| OLD | NEW |
| (Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright 2013 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 import os |
| 7 import sys |
| 8 import unittest |
| 9 from appengine_url_fetcher import AppEngineUrlFetcher |
| 10 from fake_fetchers import ConfigureFakeFetchers |
| 11 from file_system import FileNotFoundError |
| 12 from object_store_creator import ObjectStoreCreator |
| 13 from rietveld_patcher import RietveldPatcher |
| 14 from svn_constants import EXTENSIONS_PATH |
| 15 import url_constants |
| 16 |
| 17 class RietveldPatcherTest(unittest.TestCase): |
| 18 def setUp(self): |
| 19 ConfigureFakeFetchers(os.path.join(sys.path[0], os.pardir)) |
| 20 self._patcher = RietveldPatcher( |
| 21 EXTENSIONS_PATH, |
| 22 '14096030', |
| 23 AppEngineUrlFetcher(url_constants.CODEREVIEW_SERVER), |
| 24 ObjectStoreCreator.Factory('1-0', 'test')) |
| 25 |
| 26 def _ReadLocalFile(self, filename): |
| 27 with open(os.path.join(sys.path[0], |
| 28 'test_data', |
| 29 'rietveld_patcher', |
| 30 'expected', |
| 31 filename), 'r') as f: |
| 32 return f.read() |
| 33 |
| 34 def _ApplySingle(self, path, binary=False): |
| 35 return self._patcher.Apply([path], None, binary).Get()[path] |
| 36 |
| 37 def testGetVersion(self): |
| 38 self.assertEqual(self._patcher.GetVersion(), '22002') |
| 39 |
| 40 def testGetPatchedFiles(self): |
| 41 added, deleted, modified = self._patcher.GetPatchedFiles() |
| 42 self.assertEqual(sorted(added), |
| 43 sorted([ |
| 44 u'docs/templates/articles/test_foo.html', |
| 45 u'docs/templates/public/extensions/test_foo.html'])) |
| 46 self.assertEqual(sorted(deleted), |
| 47 sorted([ |
| 48 u'docs/templates/public/extensions/runtime.html'])) |
| 49 self.assertEqual(sorted(modified), |
| 50 sorted([ |
| 51 u'api/test.json', |
| 52 u'docs/templates/json/extensions_sidenav.json'])) |
| 53 |
| 54 def testApply(self): |
| 55 article_path = 'docs/templates/articles/test_foo.html' |
| 56 |
| 57 # Make sure RietveldPatcher handles |binary| correctly. |
| 58 self.assertTrue(isinstance(self._ApplySingle(article_path, True), str), |
| 59 'Expected result is binary. It was text.') |
| 60 self.assertTrue(isinstance(self._ApplySingle(article_path), unicode), |
| 61 'Expected result is text. It was binary.') |
| 62 |
| 63 # Apply to an added file. |
| 64 self.assertEqual( |
| 65 self._ReadLocalFile('test_foo.html'), |
| 66 self._ApplySingle( |
| 67 'docs/templates/public/extensions/test_foo.html')) |
| 68 |
| 69 # Apply to a modified file. |
| 70 self.assertEqual( |
| 71 self._ReadLocalFile('extensions_sidenav.json'), |
| 72 self._ApplySingle( |
| 73 'docs/templates/json/extensions_sidenav.json')) |
| 74 |
| 75 # Apply to a deleted file. |
| 76 self.assertRaises(FileNotFoundError, self._ApplySingle, |
| 77 'docs/templates/public/extensions/runtime.html') |
| 78 |
| 79 if __name__ == '__main__': |
| 80 unittest.main() |
| OLD | NEW |