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

Side by Side Diff: tests/rietveld_test.py

Issue 11280143: Create CachingRietveld to automatically cache results for presubmit checks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: add tests Created 8 years 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
« no previous file with comments | « tests/git_cl_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
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Unit tests for rietveld.py.""" 6 """Unit tests for rietveld.py."""
7 7
8 import logging 8 import logging
9 import os 9 import os
10 import sys 10 import sys
(...skipping 17 matching lines...) Expand all
28 """Mock a file in a rietveld api request.""" 28 """Mock a file in a rietveld api request."""
29 return { 29 return {
30 'status': status, 30 'status': status,
31 'is_binary': is_binary, 31 'is_binary': is_binary,
32 'num_chunks': num_chunks, 32 'num_chunks': num_chunks,
33 'id': chunk_id, 33 'id': chunk_id,
34 'property_changes': property_changes, 34 'property_changes': property_changes,
35 } 35 }
36 36
37 37
38 class RietveldTest(unittest.TestCase): 38 class BaseFixture(unittest.TestCase):
39 # Override.
40 TESTED_CLASS = Exception
41
39 def setUp(self): 42 def setUp(self):
40 super(RietveldTest, self).setUp() 43 super(BaseFixture, self).setUp()
41 # Access to a protected member XX of a client class 44 # Access to a protected member XX of a client class
42 # pylint: disable=W0212 45 # pylint: disable=W0212
43 self.rietveld = rietveld.Rietveld('url', 'email', 'password') 46 self.rietveld = self.TESTED_CLASS('url', 'email', 'password')
44 self.rietveld._send = self._rietveld_send 47 self.rietveld._send = self._rietveld_send
45 self.requests = [] 48 self.requests = []
46 49
47 def tearDown(self): 50 def tearDown(self):
48 self.assertEquals([], self.requests) 51 self.assertEqual([], self.requests)
49 super(RietveldTest, self).tearDown() 52 super(BaseFixture, self).tearDown()
50 53
51 def _rietveld_send(self, url, *args, **kwargs): 54 def _rietveld_send(self, url, *args, **kwargs):
52 self.assertTrue(self.requests, url) 55 self.assertTrue(self.requests, url)
53 request = self.requests.pop(0) 56 request = self.requests.pop(0)
54 self.assertEquals(2, len(request)) 57 self.assertEqual(2, len(request))
55 self.assertEquals(url, request[0]) 58 self.assertEqual(url, request[0])
56 return request[1] 59 return request[1]
57 60
58 def test_get_patch_empty(self):
59 self.requests = [('/api/123/456', '{}')]
60 patches = self.rietveld.get_patch(123, 456)
61 self.assertTrue(isinstance(patches, patch.PatchSet))
62 self.assertEquals([], patches.patches)
63
64 def _check_patch(self, 61 def _check_patch(self,
65 p, 62 p,
66 filename, 63 filename,
67 diff, 64 diff,
68 source_filename=None, 65 source_filename=None,
69 is_binary=False, 66 is_binary=False,
70 is_delete=False, 67 is_delete=False,
71 is_git_diff=False, 68 is_git_diff=False,
72 is_new=False, 69 is_new=False,
73 patchlevel=0, 70 patchlevel=0,
74 svn_properties=None): 71 svn_properties=None):
75 svn_properties = svn_properties or [] 72 svn_properties = svn_properties or []
76 self.assertEquals(p.filename, filename) 73 self.assertEqual(p.filename, filename)
77 self.assertEquals(p.source_filename, source_filename) 74 self.assertEqual(p.source_filename, source_filename)
78 self.assertEquals(p.is_binary, is_binary) 75 self.assertEqual(p.is_binary, is_binary)
79 self.assertEquals(p.is_delete, is_delete) 76 self.assertEqual(p.is_delete, is_delete)
80 if hasattr(p, 'is_git_diff'): 77 if hasattr(p, 'is_git_diff'):
81 self.assertEquals(p.is_git_diff, is_git_diff) 78 self.assertEqual(p.is_git_diff, is_git_diff)
82 self.assertEquals(p.is_new, is_new) 79 self.assertEqual(p.is_new, is_new)
83 if hasattr(p, 'patchlevel'): 80 if hasattr(p, 'patchlevel'):
84 self.assertEquals(p.patchlevel, patchlevel) 81 self.assertEqual(p.patchlevel, patchlevel)
85 if diff: 82 if diff:
86 self.assertEquals(p.get(True), diff) 83 self.assertEqual(p.get(True), diff)
87 if hasattr(p, 'svn_properties'): 84 if hasattr(p, 'svn_properties'):
88 self.assertEquals(p.svn_properties, svn_properties) 85 self.assertEqual(p.svn_properties, svn_properties)
86
87
88 class RietveldTest(BaseFixture):
89 TESTED_CLASS = rietveld.Rietveld
90
91 def test_get_patch_empty(self):
92 self.requests = [('/api/123/456', '{}')]
93 patches = self.rietveld.get_patch(123, 456)
94 self.assertTrue(isinstance(patches, patch.PatchSet))
95 self.assertEqual([], patches.patches)
89 96
90 def test_get_patch_no_status(self): 97 def test_get_patch_no_status(self):
91 self.requests = [ 98 self.requests = [
92 ( '/api/123/456', 99 ( '/api/123/456',
93 _api( 100 _api(
94 { 101 {
95 'tools/clang_check/README.chromium': { 102 'tools/clang_check/README.chromium': {
96 'status': None, 103 'status': None,
97 'id': 789, 104 'id': 789,
98 }})), 105 }})),
99 ('/download/issue123_456_789.diff', RAW.DELETE), 106 ('/download/issue123_456_789.diff', RAW.DELETE),
100 ] 107 ]
101 patches = self.rietveld.get_patch(123, 456) 108 patches = self.rietveld.get_patch(123, 456)
102 self.assertEquals(1, len(patches.patches)) 109 self.assertEqual(1, len(patches.patches))
103 self._check_patch( 110 self._check_patch(
104 patches.patches[0], 111 patches.patches[0],
105 'tools/clang_check/README.chromium', 112 'tools/clang_check/README.chromium',
106 RAW.DELETE, 113 RAW.DELETE,
107 is_delete=True) 114 is_delete=True)
108 115
109 def test_get_patch_2_files(self): 116 def test_get_patch_2_files(self):
110 self.requests = [ 117 self.requests = [
111 ('/api/123/456', 118 ('/api/123/456',
112 _api({'foo': _file('A'), 'file_a': _file('M', chunk_id=790)})), 119 _api({'foo': _file('A'), 'file_a': _file('M', chunk_id=790)})),
113 ('/download/issue123_456_789.diff', RAW.NEW), 120 ('/download/issue123_456_789.diff', RAW.NEW),
114 ('/download/issue123_456_790.diff', RAW.NEW_NOT_NULL), 121 ('/download/issue123_456_790.diff', RAW.NEW_NOT_NULL),
115 ] 122 ]
116 patches = self.rietveld.get_patch(123, 456) 123 patches = self.rietveld.get_patch(123, 456)
117 self.assertEquals(2, len(patches.patches)) 124 self.assertEqual(2, len(patches.patches))
118 self._check_patch( 125 self._check_patch(
119 patches.patches[0], 'file_a', RAW.NEW_NOT_NULL, is_new=True) 126 patches.patches[0], 'file_a', RAW.NEW_NOT_NULL, is_new=True)
120 self._check_patch(patches.patches[1], 'foo', RAW.NEW, is_new=True) 127 self._check_patch(patches.patches[1], 'foo', RAW.NEW, is_new=True)
121 128
122 def test_get_patch_add(self): 129 def test_get_patch_add(self):
123 self.requests = [ 130 self.requests = [
124 ('/api/123/456', _api({'foo': _file('A')})), 131 ('/api/123/456', _api({'foo': _file('A')})),
125 ('/download/issue123_456_789.diff', RAW.NEW), 132 ('/download/issue123_456_789.diff', RAW.NEW),
126 ] 133 ]
127 patches = self.rietveld.get_patch(123, 456) 134 patches = self.rietveld.get_patch(123, 456)
128 self.assertEquals(1, len(patches.patches)) 135 self.assertEqual(1, len(patches.patches))
129 self._check_patch(patches.patches[0], 'foo', RAW.NEW, is_new=True) 136 self._check_patch(patches.patches[0], 'foo', RAW.NEW, is_new=True)
130 137
131 def test_invalid_status(self): 138 def test_invalid_status(self):
132 self.requests = [ 139 self.requests = [
133 ('/api/123/456', _api({'file_a': _file('B')})), 140 ('/api/123/456', _api({'file_a': _file('B')})),
134 ] 141 ]
135 try: 142 try:
136 self.rietveld.get_patch(123, 456) 143 self.rietveld.get_patch(123, 456)
137 self.fail() 144 self.fail()
138 except patch.UnsupportedPatchFormat, e: 145 except patch.UnsupportedPatchFormat, e:
139 self.assertEquals('file_a', e.filename) 146 self.assertEqual('file_a', e.filename)
140 147
141 def test_add_plus_merge(self): 148 def test_add_plus_merge(self):
142 # svn:mergeinfo is dropped. 149 # svn:mergeinfo is dropped.
143 properties = ( 150 properties = (
144 '\nAdded: svn:mergeinfo\n' 151 '\nAdded: svn:mergeinfo\n'
145 ' Merged /branches/funky/file_b:r69-2775\n') 152 ' Merged /branches/funky/file_b:r69-2775\n')
146 self.requests = [ 153 self.requests = [
147 ('/api/123/456', 154 ('/api/123/456',
148 _api({'pp': _file('A+', property_changes=properties)})), 155 _api({'pp': _file('A+', property_changes=properties)})),
149 ('/download/issue123_456_789.diff', GIT.COPY), 156 ('/download/issue123_456_789.diff', GIT.COPY),
150 ] 157 ]
151 patches = self.rietveld.get_patch(123, 456) 158 patches = self.rietveld.get_patch(123, 456)
152 self.assertEquals(1, len(patches.patches)) 159 self.assertEqual(1, len(patches.patches))
153 self._check_patch( 160 self._check_patch(
154 patches.patches[0], 161 patches.patches[0],
155 'pp', 162 'pp',
156 GIT.COPY, 163 GIT.COPY,
157 is_git_diff=True, 164 is_git_diff=True,
158 is_new=True, 165 is_new=True,
159 patchlevel=1, 166 patchlevel=1,
160 source_filename='PRESUBMIT.py') 167 source_filename='PRESUBMIT.py')
161 168
162 def test_add_plus_eol_style(self): 169 def test_add_plus_eol_style(self):
163 properties = '\nAdded: svn:eol-style\n + LF\n' 170 properties = '\nAdded: svn:eol-style\n + LF\n'
164 self.requests = [ 171 self.requests = [
165 ('/api/123/456', 172 ('/api/123/456',
166 _api({'pp': _file('A+', property_changes=properties)})), 173 _api({'pp': _file('A+', property_changes=properties)})),
167 ('/download/issue123_456_789.diff', GIT.COPY), 174 ('/download/issue123_456_789.diff', GIT.COPY),
168 ] 175 ]
169 patches = self.rietveld.get_patch(123, 456) 176 patches = self.rietveld.get_patch(123, 456)
170 self.assertEquals(1, len(patches.patches)) 177 self.assertEqual(1, len(patches.patches))
171 self._check_patch( 178 self._check_patch(
172 patches.patches[0], 179 patches.patches[0],
173 'pp', 180 'pp',
174 GIT.COPY, 181 GIT.COPY,
175 is_git_diff=True, 182 is_git_diff=True,
176 is_new=True, 183 is_new=True,
177 patchlevel=1, 184 patchlevel=1,
178 source_filename='PRESUBMIT.py', 185 source_filename='PRESUBMIT.py',
179 svn_properties=[('svn:eol-style', 'LF')]) 186 svn_properties=[('svn:eol-style', 'LF')])
180 187
181 def test_add_empty(self): 188 def test_add_empty(self):
182 self.requests = [ 189 self.requests = [
183 ('/api/123/456', _api({'__init__.py': _file('A ', num_chunks=0)})), 190 ('/api/123/456', _api({'__init__.py': _file('A ', num_chunks=0)})),
184 ('/download/issue123_456_789.diff', RAW.CRAP_ONLY), 191 ('/download/issue123_456_789.diff', RAW.CRAP_ONLY),
185 ] 192 ]
186 patches = self.rietveld.get_patch(123, 456) 193 patches = self.rietveld.get_patch(123, 456)
187 self.assertEquals(1, len(patches.patches)) 194 self.assertEqual(1, len(patches.patches))
188 self._check_patch( 195 self._check_patch(
189 patches.patches[0], 196 patches.patches[0],
190 '__init__.py', 197 '__init__.py',
191 RAW.CRAP_ONLY, 198 RAW.CRAP_ONLY,
192 is_new=True) 199 is_new=True)
193 200
194 def test_delete(self): 201 def test_delete(self):
195 name = 'tools/clang_check/README.chromium' 202 name = 'tools/clang_check/README.chromium'
196 self.requests = [ 203 self.requests = [
197 ('/api/123/456', _api({name: _file('D')})), 204 ('/api/123/456', _api({name: _file('D')})),
198 ('/download/issue123_456_789.diff', RAW.DELETE), 205 ('/download/issue123_456_789.diff', RAW.DELETE),
199 ] 206 ]
200 patches = self.rietveld.get_patch(123, 456) 207 patches = self.rietveld.get_patch(123, 456)
201 self.assertEquals(1, len(patches.patches)) 208 self.assertEqual(1, len(patches.patches))
202 self._check_patch(patches.patches[0], name, RAW.DELETE, is_delete=True) 209 self._check_patch(patches.patches[0], name, RAW.DELETE, is_delete=True)
203 210
204 def test_delete_empty(self): 211 def test_delete_empty(self):
205 name = 'tests/__init__.py' 212 name = 'tests/__init__.py'
206 self.requests = [ 213 self.requests = [
207 ('/api/123/456', _api({name: _file('D')})), 214 ('/api/123/456', _api({name: _file('D')})),
208 ('/download/issue123_456_789.diff', GIT.DELETE_EMPTY), 215 ('/download/issue123_456_789.diff', GIT.DELETE_EMPTY),
209 ] 216 ]
210 patches = self.rietveld.get_patch(123, 456) 217 patches = self.rietveld.get_patch(123, 456)
211 self.assertEquals(1, len(patches.patches)) 218 self.assertEqual(1, len(patches.patches))
212 self._check_patch( 219 self._check_patch(
213 patches.patches[0], 220 patches.patches[0],
214 name, 221 name,
215 GIT.DELETE_EMPTY, 222 GIT.DELETE_EMPTY,
216 is_delete=True, 223 is_delete=True,
217 is_git_diff=True, 224 is_git_diff=True,
218 patchlevel=1) 225 patchlevel=1)
219 226
220 def test_m_plus(self): 227 def test_m_plus(self):
221 properties = '\nAdded: svn:eol-style\n + LF\n' 228 properties = '\nAdded: svn:eol-style\n + LF\n'
222 self.requests = [ 229 self.requests = [
223 ('/api/123/456', 230 ('/api/123/456',
224 _api({'chrome/file.cc': _file('M+', property_changes=properties)})), 231 _api({'chrome/file.cc': _file('M+', property_changes=properties)})),
225 ('/download/issue123_456_789.diff', RAW.PATCH), 232 ('/download/issue123_456_789.diff', RAW.PATCH),
226 ] 233 ]
227 patches = self.rietveld.get_patch(123, 456) 234 patches = self.rietveld.get_patch(123, 456)
228 self.assertEquals(1, len(patches.patches)) 235 self.assertEqual(1, len(patches.patches))
229 self._check_patch( 236 self._check_patch(
230 patches.patches[0], 237 patches.patches[0],
231 'chrome/file.cc', 238 'chrome/file.cc',
232 RAW.PATCH, 239 RAW.PATCH,
233 svn_properties=[('svn:eol-style', 'LF')]) 240 svn_properties=[('svn:eol-style', 'LF')])
234 241
235 def test_m_plus_unknown_prop(self): 242 def test_m_plus_unknown_prop(self):
236 properties = '\nAdded: svn:foobar\n + stuff\n' 243 properties = '\nAdded: svn:foobar\n + stuff\n'
237 self.requests = [ 244 self.requests = [
238 ('/api/123/456', 245 ('/api/123/456',
239 _api({'file_a': _file('M+', property_changes=properties)})), 246 _api({'file_a': _file('M+', property_changes=properties)})),
240 ] 247 ]
241 try: 248 try:
242 self.rietveld.get_patch(123, 456) 249 self.rietveld.get_patch(123, 456)
243 self.fail() 250 self.fail()
244 except patch.UnsupportedPatchFormat, e: 251 except patch.UnsupportedPatchFormat, e:
245 self.assertEquals('file_a', e.filename) 252 self.assertEqual('file_a', e.filename)
246 253
247 def test_get_patch_moved(self): 254 def test_get_patch_moved(self):
248 self.requests = [ 255 self.requests = [
249 ('/api/123/456', _api({'file_b': _file('A+')})), 256 ('/api/123/456', _api({'file_b': _file('A+')})),
250 ('/download/issue123_456_789.diff', RAW.MINIMAL_RENAME), 257 ('/download/issue123_456_789.diff', RAW.MINIMAL_RENAME),
251 ] 258 ]
252 patches = self.rietveld.get_patch(123, 456) 259 patches = self.rietveld.get_patch(123, 456)
253 self.assertEquals(1, len(patches.patches)) 260 self.assertEqual(1, len(patches.patches))
254 self._check_patch( 261 self._check_patch(
255 patches.patches[0], 262 patches.patches[0],
256 'file_b', 263 'file_b',
257 RAW.MINIMAL_RENAME, 264 RAW.MINIMAL_RENAME,
258 source_filename='file_a', 265 source_filename='file_a',
259 is_new=True) 266 is_new=True)
260 267
261 def test_svn_properties(self): 268 def test_svn_properties(self):
262 # Line too long (N/80) 269 # Line too long (N/80)
263 # pylint: disable=C0301 270 # pylint: disable=C0301
264 271
265 # To test one of these, run something like 272 # To test one of these, run something like
266 # import json, pprint, urllib 273 # import json, pprint, urllib
267 # url = 'http://codereview.chromium.org/api/202046/1' 274 # url = 'http://codereview.chromium.org/api/202046/1'
268 # pprint.pprint(json.load(urllib.urlopen(url))['files']) 275 # pprint.pprint(json.load(urllib.urlopen(url))['files'])
269 276
270 # svn:mergeinfo across branches: 277 # svn:mergeinfo across branches:
271 # http://codereview.chromium.org/202046/diff/1/third_party/libxml/xmlcatalog _dummy.cc 278 # http://codereview.chromium.org/202046/diff/1/third_party/libxml/xmlcatalog _dummy.cc
272 self.assertEquals( 279 self.assertEqual(
273 [('svn:eol-style', 'LF')], 280 [('svn:eol-style', 'LF')],
274 rietveld.Rietveld.parse_svn_properties( 281 rietveld.Rietveld.parse_svn_properties(
275 u'\nAdded: svn:eol-style\n + LF\n', 'foo')) 282 u'\nAdded: svn:eol-style\n + LF\n', 'foo'))
276 283
277 # svn:eol-style property that is lost in the diff 284 # svn:eol-style property that is lost in the diff
278 # http://codereview.chromium.org/202046/diff/1/third_party/libxml/xmllint_du mmy.cc 285 # http://codereview.chromium.org/202046/diff/1/third_party/libxml/xmllint_du mmy.cc
279 self.assertEquals( 286 self.assertEqual(
280 [], 287 [],
281 rietveld.Rietveld.parse_svn_properties( 288 rietveld.Rietveld.parse_svn_properties(
282 u'\nAdded: svn:mergeinfo\n' 289 u'\nAdded: svn:mergeinfo\n'
283 ' Merged /branches/chrome_webkit_merge_branch/third_party/' 290 ' Merged /branches/chrome_webkit_merge_branch/third_party/'
284 'libxml/xmldummy_mac.cc:r69-2775\n', 291 'libxml/xmldummy_mac.cc:r69-2775\n',
285 'foo')) 292 'foo'))
286 293
287 self.assertEquals( 294 self.assertEqual(
288 [], 295 [],
289 rietveld.Rietveld.parse_svn_properties(u'', 'foo')) 296 rietveld.Rietveld.parse_svn_properties(u'', 'foo'))
290 297
291 298
292 # http://codereview.chromium.org/api/7834045/15001 299 # http://codereview.chromium.org/api/7834045/15001
293 self.assertEquals( 300 self.assertEqual(
294 [('svn:executable', '*'), ('svn:eol-style', 'LF')], 301 [('svn:executable', '*'), ('svn:eol-style', 'LF')],
295 rietveld.Rietveld.parse_svn_properties( 302 rietveld.Rietveld.parse_svn_properties(
296 '\n' 303 '\n'
297 'Added: svn:executable\n' 304 'Added: svn:executable\n'
298 ' + *\n' 305 ' + *\n'
299 'Added: svn:eol-style\n' 306 'Added: svn:eol-style\n'
300 ' + LF\n', 307 ' + LF\n',
301 'foo')) 308 'foo'))
302 309
303 # http://codereview.chromium.org/api/9139006/7001 310 # http://codereview.chromium.org/api/9139006/7001
304 self.assertEquals( 311 self.assertEqual(
305 [('svn:mime-type', 'image/png')], 312 [('svn:mime-type', 'image/png')],
306 rietveld.Rietveld.parse_svn_properties( 313 rietveld.Rietveld.parse_svn_properties(
307 '\n' 314 '\n'
308 'Added: svn:mime-type\n' 315 'Added: svn:mime-type\n'
309 ' + image/png\n', 316 ' + image/png\n',
310 'foo')) 317 'foo'))
311 318
312 def test_bad_svn_properties(self): 319 def test_bad_svn_properties(self):
313 try: 320 try:
314 rietveld.Rietveld.parse_svn_properties(u'\n', 'foo') 321 rietveld.Rietveld.parse_svn_properties(u'\n', 'foo')
315 self.fail() 322 self.fail()
316 except rietveld.patch.UnsupportedPatchFormat, e: 323 except rietveld.patch.UnsupportedPatchFormat, e:
317 self.assertEquals('foo', e.filename) 324 self.assertEqual('foo', e.filename)
318 # TODO(maruel): Change with no diff, only svn property change: 325 # TODO(maruel): Change with no diff, only svn property change:
319 # http://codereview.chromium.org/6462019/ 326 # http://codereview.chromium.org/6462019/
320 327
321 def test_search_all_empty(self): 328 def test_search_all_empty(self):
322 url = ( 329 url = (
323 '/search?format=json' 330 '/search?format=json'
324 '&base=base' 331 '&base=base'
325 '&created_after=2010-01-02' 332 '&created_after=2010-01-02'
326 '&created_before=2010-01-01' 333 '&created_before=2010-01-01'
327 '&modified_after=2010-02-02' 334 '&modified_after=2010-02-02'
(...skipping 17 matching lines...) Expand all
345 True, 352 True,
346 True, 353 True,
347 '2010-01-01', 354 '2010-01-01',
348 '2010-01-02', 355 '2010-01-02',
349 '2010-02-01', 356 '2010-02-01',
350 '2010-02-02', 357 '2010-02-02',
351 23, 358 23,
352 True, 359 True,
353 True, 360 True,
354 )) 361 ))
355 self.assertEquals([], results) 362 self.assertEqual([], results)
356 363
357 def test_results_cursor(self): 364 def test_results_cursor(self):
358 # Verify cursor iteration is transparent. 365 # Verify cursor iteration is transparent.
359 self.requests = [ 366 self.requests = [
360 ('/search?format=json&base=base', 367 ('/search?format=json&base=base',
361 rietveld.json.dumps({ 368 rietveld.json.dumps({
362 'cursor': 'MY_CURSOR', 369 'cursor': 'MY_CURSOR',
363 'results': [{'foo': 'bar'}, {'foo': 'baz'}], 370 'results': [{'foo': 'bar'}, {'foo': 'baz'}],
364 })), 371 })),
365 ('/search?format=json&base=base&cursor=MY_CURSOR', 372 ('/search?format=json&base=base&cursor=MY_CURSOR',
366 rietveld.json.dumps({ 373 rietveld.json.dumps({
367 'cursor': 'NEXT', 374 'cursor': 'NEXT',
368 'results': [{'foo': 'prout'}], 375 'results': [{'foo': 'prout'}],
369 })), 376 })),
370 ('/search?format=json&base=base&cursor=NEXT', 377 ('/search?format=json&base=base&cursor=NEXT',
371 rietveld.json.dumps({ 378 rietveld.json.dumps({
372 'cursor': 'VOID', 379 'cursor': 'VOID',
373 'results': [], 380 'results': [],
374 })), 381 })),
375 ] 382 ]
376 expected = [ 383 expected = [
377 {'foo': 'bar'}, 384 {'foo': 'bar'},
378 {'foo': 'baz'}, 385 {'foo': 'baz'},
379 {'foo': 'prout'}, 386 {'foo': 'prout'},
380 ] 387 ]
381 for i in self.rietveld.search(base='base'): 388 for i in self.rietveld.search(base='base'):
382 self.assertEquals(expected.pop(0), i) 389 self.assertEqual(expected.pop(0), i)
383 self.assertEquals([], expected) 390 self.assertEqual([], expected)
391
392
393 class CachingRietveldTest(BaseFixture):
394 # Tests only one request is done.
395 TESTED_CLASS = rietveld.CachingRietveld
396
397 def test_get_description(self):
398 self.requests = [
399 ('/1/description', 'Blah blah blah'),
400 ]
401 expected = 'Blah blah blah'
402 self.assertEqual(expected, self.rietveld.get_description(1))
403 self.assertEqual(expected, self.rietveld.get_description(1))
404
405 def test_get_issue_properties(self):
406 self.requests = [
407 ('/api/1?messages=true', rietveld.json.dumps({'messages': 'foo'})),
408 ]
409 expected = {}
410 expected_msg = {'messages': 'foo'}
411 self.assertEqual(expected, self.rietveld.get_issue_properties(1, False))
412 self.assertEqual(expected_msg, self.rietveld.get_issue_properties(1, True))
413
414 def test_get_patchset_properties(self):
415 self.requests = [
416 ('/api/1/2', '{}'),
417 ]
418 expected = {}
419 self.assertEqual(expected, self.rietveld.get_patchset_properties(1, 2))
420 self.assertEqual(expected, self.rietveld.get_patchset_properties(1, 2))
421
384 422
385 423
386 if __name__ == '__main__': 424 if __name__ == '__main__':
387 logging.basicConfig(level=[ 425 logging.basicConfig(level=[
388 logging.ERROR, logging.INFO, logging.DEBUG][min(2, sys.argv.count('-v'))]) 426 logging.ERROR, logging.INFO, logging.DEBUG][min(2, sys.argv.count('-v'))])
389 unittest.main() 427 unittest.main()
OLDNEW
« no previous file with comments | « tests/git_cl_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698