| OLD | NEW |
| 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 import json | 6 import json |
| 7 import os | 7 import os |
| 8 import sys | 8 import sys |
| 9 import unittest | 9 import unittest |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 class TemplateDataSourceTest(unittest.TestCase): | 36 class TemplateDataSourceTest(unittest.TestCase): |
| 37 | 37 |
| 38 def setUp(self): | 38 def setUp(self): |
| 39 self._base_path = os.path.join(sys.path[0], | 39 self._base_path = os.path.join(sys.path[0], |
| 40 'test_data', | 40 'test_data', |
| 41 'template_data_source') | 41 'template_data_source') |
| 42 self._fake_api_list_data_source_factory = _FakeFactory() | 42 self._fake_api_list_data_source_factory = _FakeFactory() |
| 43 self._fake_intro_data_source_factory = _FakeFactory() | 43 self._fake_intro_data_source_factory = _FakeFactory() |
| 44 self._fake_samples_data_source_factory = _FakeFactory() | 44 self._fake_samples_data_source_factory = _FakeFactory() |
| 45 self._fake_sidenav_data_source_factory = _FakeFactory() | |
| 46 self._permissions_data_source = PermissionsDataSource( | 45 self._permissions_data_source = PermissionsDataSource( |
| 47 _FakeFactory(), LocalFileSystem.Create(), '', '', '') | 46 _FakeFactory(), LocalFileSystem.Create(), '', '', '') |
| 48 | 47 |
| 49 def _ReadLocalFile(self, filename): | 48 def _ReadLocalFile(self, filename): |
| 50 with open(os.path.join(self._base_path, filename), 'r') as f: | 49 with open(os.path.join(self._base_path, filename), 'r') as f: |
| 51 return f.read() | 50 return f.read() |
| 52 | 51 |
| 53 def _RenderTest(self, name, data_source): | 52 def _RenderTest(self, name, data_source): |
| 54 template_name = name + '_tmpl.html' | 53 template_name = name + '_tmpl.html' |
| 55 template = Handlebar(self._ReadLocalFile(template_name)) | 54 template = Handlebar(self._ReadLocalFile(template_name)) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 66 TestBranchUtility.CreateWithCannedData()) | 65 TestBranchUtility.CreateWithCannedData()) |
| 67 else: | 66 else: |
| 68 api_data_factory = _FakeFactory(api_data) | 67 api_data_factory = _FakeFactory(api_data) |
| 69 reference_resolver_factory = ReferenceResolver.Factory( | 68 reference_resolver_factory = ReferenceResolver.Factory( |
| 70 api_data_factory, | 69 api_data_factory, |
| 71 self._fake_api_list_data_source_factory, | 70 self._fake_api_list_data_source_factory, |
| 72 ObjectStoreCreator.ForTest()) | 71 ObjectStoreCreator.ForTest()) |
| 73 @DisableLogging('error') # "was never set" error | 72 @DisableLogging('error') # "was never set" error |
| 74 def create_from_factory(factory): | 73 def create_from_factory(factory): |
| 75 path = 'extensions/foo' | 74 path = 'extensions/foo' |
| 76 return factory.Create(Request.ForTest(path), path) | 75 return factory.Create(Request.ForTest(path), {}) |
| 77 return create_from_factory(TemplateDataSource.Factory( | 76 return create_from_factory(TemplateDataSource.Factory( |
| 78 api_data_factory, | 77 api_data_factory, |
| 79 self._fake_api_list_data_source_factory, | 78 self._fake_api_list_data_source_factory, |
| 80 self._fake_intro_data_source_factory, | 79 self._fake_intro_data_source_factory, |
| 81 self._fake_samples_data_source_factory, | 80 self._fake_samples_data_source_factory, |
| 82 self._fake_sidenav_data_source_factory, | |
| 83 compiled_fs_factory, | 81 compiled_fs_factory, |
| 84 reference_resolver_factory, | 82 reference_resolver_factory, |
| 85 self._permissions_data_source, | 83 self._permissions_data_source, |
| 86 '.', | 84 '.', |
| 87 '.', | 85 '.', |
| 88 '', | 86 '')) |
| 89 {})) | |
| 90 | 87 |
| 91 def testSimple(self): | 88 def testSimple(self): |
| 92 self._base_path = os.path.join(self._base_path, 'simple') | 89 self._base_path = os.path.join(self._base_path, 'simple') |
| 93 fetcher = LocalFileSystem(self._base_path) | 90 fetcher = LocalFileSystem(self._base_path) |
| 94 compiled_fs_factory = CompiledFileSystem.Factory( | 91 compiled_fs_factory = CompiledFileSystem.Factory( |
| 95 fetcher, | 92 fetcher, |
| 96 ObjectStoreCreator.ForTest()) | 93 ObjectStoreCreator.ForTest()) |
| 97 t_data_source = self._CreateTemplateDataSource( | 94 t_data_source = self._CreateTemplateDataSource( |
| 98 compiled_fs_factory, | 95 compiled_fs_factory, |
| 99 ObjectStoreCreator.ForTest()) | 96 ObjectStoreCreator.ForTest()) |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 compiled_fs_factory, | 139 compiled_fs_factory, |
| 143 api_data=json.loads(self._ReadLocalFile('test1.json')))) | 140 api_data=json.loads(self._ReadLocalFile('test1.json')))) |
| 144 self._RenderTest( | 141 self._RenderTest( |
| 145 'test2', | 142 'test2', |
| 146 self._CreateTemplateDataSource( | 143 self._CreateTemplateDataSource( |
| 147 compiled_fs_factory, | 144 compiled_fs_factory, |
| 148 api_data=json.loads(self._ReadLocalFile('test2.json')))) | 145 api_data=json.loads(self._ReadLocalFile('test2.json')))) |
| 149 | 146 |
| 150 if __name__ == '__main__': | 147 if __name__ == '__main__': |
| 151 unittest.main() | 148 unittest.main() |
| OLD | NEW |