Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: tests/rietveld_test.py

Issue 6792028: Move patch.py and rietveld.py from commit-queue. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: fixed remaining issues Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« tests/local_rietveld.py ('K') | « tests/patch_test.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 """Unit tests for rietveld.py."""
7
8 import logging
9 import os
10 import sys
11 import unittest
12
13 ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
14 sys.path.insert(0, os.path.join(ROOT_DIR, '..'))
15
16 import patch
17 import rietveld
18
19 # Access to a protected member XX of a client class
20 # pylint: disable=W0212
21
22
23 class RietveldTest(unittest.TestCase):
24 def setUp(self):
25 super(RietveldTest, self).setUp()
26 self._rietveld_send = rietveld.Rietveld._send
27 rietveld.Rietveld._send = None
28
29 def tearDown(self):
30 super(RietveldTest, self).setUp()
31 rietveld.Rietveld._send = self._rietveld_send
32
33 def test_get_patch_empty(self):
34 rietveld.Rietveld._send = lambda x, y, payload: '{}'
35 r = rietveld.Rietveld('url', 'email', 'password')
36 patches = r.get_patch(123, 456)
37 self.assertTrue(isinstance(patches, patch.PatchSet))
38 self.assertEquals([], patches.patches)
39
40 def test_get_patch_no_status(self):
41 rietveld.Rietveld._send = lambda x, y, payload: (
42 '{'
43 ' "files":'
44 ' {'
45 ' "file_a":'
46 ' {'
47 ' }'
48 ' }'
49 '}')
50 r = rietveld.Rietveld('url', 'email', 'password')
51 try:
52 r.get_patch(123, 456)
53 self.fail()
54 except patch.UnsupportedPatchFormat, e:
55 self.assertEquals('file_a', e.filename)
56
57 def test_get_patch_two_files(self):
58 output = (
59 '{'
60 ' "files":'
61 ' {'
62 ' "file_a":'
63 ' {'
64 ' "status": "A",'
65 ' "is_binary": false,'
66 ' "num_chunks": 1,'
67 ' "id": 789'
68 ' }'
69 ' }'
70 '}')
71 rietveld.Rietveld._send = lambda x, y, payload: output
72 r = rietveld.Rietveld('url', 'email', 'password')
73 patches = r.get_patch(123, 456)
74 self.assertTrue(isinstance(patches, patch.PatchSet))
75 self.assertEquals(1, len(patches.patches))
76 obj = patches.patches[0]
77 self.assertEquals(patch.FilePatchDiff, obj.__class__)
78 self.assertEquals('file_a', obj.filename)
79 self.assertEquals([], obj.svn_properties)
80 self.assertEquals(False, obj.is_git_diff)
81 self.assertEquals(0, obj.patchlevel)
82 # This is because Rietveld._send() always returns the same buffer.
83 self.assertEquals(output, obj.get())
84
85
86
87 if __name__ == '__main__':
88 logging.basicConfig(level=logging.ERROR)
89 unittest.main()
OLDNEW
« tests/local_rietveld.py ('K') | « tests/patch_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698