| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 from copy import deepcopy | 6 from copy import deepcopy |
| 7 import unittest | 7 import unittest |
| 8 | 8 |
| 9 from caching_file_system import CachingFileSystem | 9 from caching_file_system import CachingFileSystem |
| 10 from extensions_paths import API |
| 10 from file_system import FileNotFoundError | 11 from file_system import FileNotFoundError |
| 11 from host_file_system_provider import HostFileSystemProvider | 12 from host_file_system_provider import HostFileSystemProvider |
| 12 from object_store_creator import ObjectStoreCreator | 13 from object_store_creator import ObjectStoreCreator |
| 13 from offline_file_system import OfflineFileSystem | 14 from offline_file_system import OfflineFileSystem |
| 14 from test_data.canned_data import CANNED_API_FILE_SYSTEM_DATA | 15 from test_data.canned_data import CANNED_API_FILE_SYSTEM_DATA |
| 15 from test_file_system import TestFileSystem | 16 from test_file_system import TestFileSystem |
| 16 | 17 |
| 17 class HostFileSystemProviderTest(unittest.TestCase): | 18 class HostFileSystemProviderTest(unittest.TestCase): |
| 18 def setUp(self): | 19 def setUp(self): |
| 19 self._idle_path = 'api/idle.json' | 20 self._idle_path = '%s/idle.json' % API |
| 20 self._canned_data = deepcopy(CANNED_API_FILE_SYSTEM_DATA) | 21 self._canned_data = deepcopy(CANNED_API_FILE_SYSTEM_DATA) |
| 21 | 22 |
| 22 def _constructor_for_test(self, branch, **optargs): | 23 def _constructor_for_test(self, branch, **optargs): |
| 23 return TestFileSystem(self._canned_data[branch]) | 24 return TestFileSystem(self._canned_data[branch]) |
| 24 | 25 |
| 25 def testWithCaching(self): | 26 def testWithCaching(self): |
| 26 creator = HostFileSystemProvider( | 27 creator = HostFileSystemProvider( |
| 27 ObjectStoreCreator.ForTest(), | 28 ObjectStoreCreator.ForTest(), |
| 28 constructor_for_test=self._constructor_for_test) | 29 constructor_for_test=self._constructor_for_test) |
| 29 | 30 |
| 30 fs = creator.GetBranch('1500') | 31 fs = creator.GetBranch('1500') |
| 31 first_read = fs.ReadSingle(self._idle_path).Get() | 32 first_read = fs.ReadSingle(self._idle_path).Get() |
| 32 self._canned_data['1500']['api']['idle.json'] = 'blah blah blah' | 33 self._canned_data['1500']['chrome']['common']['extensions'].get('api' |
| 34 )['idle.json'] = 'blah blah blah' |
| 33 second_read = fs.ReadSingle(self._idle_path).Get() | 35 second_read = fs.ReadSingle(self._idle_path).Get() |
| 34 | 36 |
| 35 self.assertEqual(first_read, second_read) | 37 self.assertEqual(first_read, second_read) |
| 36 | 38 |
| 37 def testWithOffline(self): | 39 def testWithOffline(self): |
| 38 creator = HostFileSystemProvider( | 40 creator = HostFileSystemProvider( |
| 39 ObjectStoreCreator.ForTest(), | 41 ObjectStoreCreator.ForTest(), |
| 40 offline=True, | 42 offline=True, |
| 41 constructor_for_test=self._constructor_for_test) | 43 constructor_for_test=self._constructor_for_test) |
| 42 | 44 |
| 43 fs = creator.GetBranch('1500') | 45 fs = creator.GetBranch('1500') |
| 44 # Offline file system should raise a FileNotFoundError if read is attempted. | 46 # Offline file system should raise a FileNotFoundError if read is attempted. |
| 45 self.assertRaises(FileNotFoundError, fs.ReadSingle(self._idle_path).Get) | 47 self.assertRaises(FileNotFoundError, fs.ReadSingle(self._idle_path).Get) |
| 46 | 48 |
| 47 if __name__ == '__main__': | 49 if __name__ == '__main__': |
| 48 unittest.main() | 50 unittest.main() |
| OLD | NEW |