| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 |
| 11 import unittest | 11 import unittest |
| 12 | 12 |
| 13 ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) | 13 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
| 14 sys.path.insert(0, os.path.join(ROOT_DIR, '..')) | |
| 15 | 14 |
| 16 import patch | 15 import patch |
| 17 import rietveld | 16 import rietveld |
| 18 from tests.patches_data import GIT, RAW | 17 from tests.patches_data import GIT, RAW |
| 19 | 18 |
| 20 # Access to a protected member XX of a client class | |
| 21 # pylint: disable=W0212 | |
| 22 | |
| 23 | 19 |
| 24 def _api(files): | 20 def _api(files): |
| 25 """Mock a rietveld api request.""" | 21 """Mock a rietveld api request.""" |
| 26 return rietveld.json.dumps({'files': files}) | 22 return rietveld.json.dumps({'files': files}) |
| 27 | 23 |
| 28 | 24 |
| 29 def _file( | 25 def _file( |
| 30 status, is_binary=False, num_chunks=1, chunk_id=789, property_changes=''): | 26 status, is_binary=False, num_chunks=1, chunk_id=789, property_changes=''): |
| 31 """Mock a file in a rietveld api request.""" | 27 """Mock a file in a rietveld api request.""" |
| 32 return { | 28 return { |
| 33 'status': status, | 29 'status': status, |
| 34 'is_binary': is_binary, | 30 'is_binary': is_binary, |
| 35 'num_chunks': num_chunks, | 31 'num_chunks': num_chunks, |
| 36 'id': chunk_id, | 32 'id': chunk_id, |
| 37 'property_changes': property_changes, | 33 'property_changes': property_changes, |
| 38 } | 34 } |
| 39 | 35 |
| 40 | 36 |
| 41 class RietveldTest(unittest.TestCase): | 37 class RietveldTest(unittest.TestCase): |
| 42 def setUp(self): | 38 def setUp(self): |
| 39 super(RietveldTest, self).setUp() |
| 40 # Access to a protected member XX of a client class |
| 41 # pylint: disable=W0212 |
| 43 self.rietveld = rietveld.Rietveld('url', 'email', 'password') | 42 self.rietveld = rietveld.Rietveld('url', 'email', 'password') |
| 44 self.rietveld._send = self._rietveld_send | 43 self.rietveld._send = self._rietveld_send |
| 45 self.requests = [] | 44 self.requests = [] |
| 46 | 45 |
| 47 def tearDown(self): | 46 def tearDown(self): |
| 48 self.assertEquals([], self.requests) | 47 self.assertEquals([], self.requests) |
| 48 super(RietveldTest, self).tearDown() |
| 49 | 49 |
| 50 def _rietveld_send(self, url, *args, **kwargs): | 50 def _rietveld_send(self, url, *args, **kwargs): |
| 51 self.assertTrue(self.requests, url) | 51 self.assertTrue(self.requests, url) |
| 52 request = self.requests.pop(0) | 52 request = self.requests.pop(0) |
| 53 self.assertEquals(2, len(request)) | 53 self.assertEquals(2, len(request)) |
| 54 self.assertEquals(url, request[0]) | 54 self.assertEquals(url, request[0]) |
| 55 return request[1] | 55 return request[1] |
| 56 | 56 |
| 57 def test_get_patch_empty(self): | 57 def test_get_patch_empty(self): |
| 58 self.requests = [('/api/123/456', '{}')] | 58 self.requests = [('/api/123/456', '{}')] |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 {'foo': 'prout'}, | 342 {'foo': 'prout'}, |
| 343 ] | 343 ] |
| 344 for i in self.rietveld.search(base='base'): | 344 for i in self.rietveld.search(base='base'): |
| 345 self.assertEquals(expected.pop(0), i) | 345 self.assertEquals(expected.pop(0), i) |
| 346 self.assertEquals([], expected) | 346 self.assertEquals([], expected) |
| 347 | 347 |
| 348 | 348 |
| 349 if __name__ == '__main__': | 349 if __name__ == '__main__': |
| 350 logging.basicConfig(level=logging.ERROR) | 350 logging.basicConfig(level=logging.ERROR) |
| 351 unittest.main() | 351 unittest.main() |
| OLD | NEW |