| 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 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 class TemplateDataSourceTest(unittest.TestCase): | 33 class TemplateDataSourceTest(unittest.TestCase): |
| 34 def setUp(self): | 34 def setUp(self): |
| 35 self._base_path = os.path.join(sys.path[0], | 35 self._base_path = os.path.join(sys.path[0], |
| 36 'test_data', | 36 'test_data', |
| 37 'template_data_source') | 37 'template_data_source') |
| 38 self._fake_api_list_data_source_factory = _FakeFactory() | 38 self._fake_api_list_data_source_factory = _FakeFactory() |
| 39 self._fake_intro_data_source_factory = _FakeFactory() | 39 self._fake_intro_data_source_factory = _FakeFactory() |
| 40 self._fake_samples_data_source_factory = _FakeFactory() | 40 self._fake_samples_data_source_factory = _FakeFactory() |
| 41 self._fake_sidenav_data_source_factory = _FakeFactory() | 41 self._fake_sidenav_data_source_factory = _FakeFactory() |
| 42 self._fake_channel_data = [ |
| 43 { 'name': 'a', 'branch': '11', 'version': '1' }, |
| 44 { 'name': 'b', 'branch': '22', 'version': '2' }, |
| 45 { 'name': 'c', 'branch': '33', 'version': '3' }, |
| 46 { 'name': 'd', 'branch': '44', 'version': '4' } |
| 47 ] |
| 42 | 48 |
| 43 def _ReadLocalFile(self, filename): | 49 def _ReadLocalFile(self, filename): |
| 44 with open(os.path.join(self._base_path, filename), 'r') as f: | 50 with open(os.path.join(self._base_path, filename), 'r') as f: |
| 45 return f.read() | 51 return f.read() |
| 46 | 52 |
| 47 def _RenderTest(self, name, data_source): | 53 def _RenderTest(self, name, data_source): |
| 48 template_name = name + '_tmpl.html' | 54 template_name = name + '_tmpl.html' |
| 49 template = Handlebar(self._ReadLocalFile(template_name)) | 55 template = Handlebar(self._ReadLocalFile(template_name)) |
| 50 self.assertEquals( | 56 self.assertEquals( |
| 51 self._ReadLocalFile(name + '_expected.html'), | 57 self._ReadLocalFile(name + '_expected.html'), |
| 52 data_source.Render(template_name)) | 58 data_source.Render(template_name)) |
| 53 | 59 |
| 54 def _CreateTemplateDataSource(self, compiled_fs_factory, api_data=None): | 60 def _CreateTemplateDataSource(self, compiled_fs_factory, api_data=None): |
| 61 fake_avail_factory = _FakeFactory() |
| 55 if api_data is None: | 62 if api_data is None: |
| 56 api_data_factory = APIDataSource.Factory(compiled_fs_factory, 'fake_path') | 63 api_data_factory = APIDataSource.Factory(compiled_fs_factory, |
| 64 'fake_path', |
| 65 fake_avail_factory, |
| 66 {}) # Unnecessary file system |
| 57 else: | 67 else: |
| 58 api_data_factory = _FakeFactory(api_data) | 68 api_data_factory = _FakeFactory(api_data) |
| 59 reference_resolver_factory = ReferenceResolver.Factory( | 69 reference_resolver_factory = ReferenceResolver.Factory( |
| 60 api_data_factory, | 70 api_data_factory, |
| 61 self._fake_api_list_data_source_factory, | 71 self._fake_api_list_data_source_factory, |
| 62 ObjectStoreCreator.TestFactory()) | 72 ObjectStoreCreator.TestFactory()) |
| 63 @DisableLogging('error') # "was never set" error | 73 @DisableLogging('error') # "was never set" error |
| 64 def create_from_factory(factory): | 74 def create_from_factory(factory): |
| 65 return factory.Create(_FakeRequest(), 'extensions/foo') | 75 return factory.Create(_FakeRequest(), 'extensions/foo') |
| 66 return create_from_factory(TemplateDataSource.Factory( | 76 return create_from_factory(TemplateDataSource.Factory( |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 compiled_fs_factory, | 139 compiled_fs_factory, |
| 130 api_data=json.loads(self._ReadLocalFile('test1.json')))) | 140 api_data=json.loads(self._ReadLocalFile('test1.json')))) |
| 131 self._RenderTest( | 141 self._RenderTest( |
| 132 'test2', | 142 'test2', |
| 133 self._CreateTemplateDataSource( | 143 self._CreateTemplateDataSource( |
| 134 compiled_fs_factory, | 144 compiled_fs_factory, |
| 135 api_data=json.loads(self._ReadLocalFile('test2.json')))) | 145 api_data=json.loads(self._ReadLocalFile('test2.json')))) |
| 136 | 146 |
| 137 if __name__ == '__main__': | 147 if __name__ == '__main__': |
| 138 unittest.main() | 148 unittest.main() |
| OLD | NEW |