Chromium Code Reviews| Index: chrome/common/extensions/docs/server2/api_data_source_test.py |
| diff --git a/chrome/common/extensions/docs/server2/api_data_source_test.py b/chrome/common/extensions/docs/server2/api_data_source_test.py |
| index d8ce485a644f9fb22852e48fc14d9a09247ef7f6..30b200a7843b37c934adaa021b37c6c9dd0037cf 100755 |
| --- a/chrome/common/extensions/docs/server2/api_data_source_test.py |
| +++ b/chrome/common/extensions/docs/server2/api_data_source_test.py |
| @@ -3,7 +3,7 @@ |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| -import copy |
| +from copy import deepcopy |
| import json |
| import os |
| import sys |
| @@ -19,6 +19,18 @@ from file_system import FileNotFoundError |
| from local_file_system import LocalFileSystem |
| from object_store_creator import ObjectStoreCreator |
| from reference_resolver import ReferenceResolver |
| +from test_file_system import TestFileSystem |
| + |
| +_INTRO_TABLES_DATA = { |
| + 'docs': { |
| + 'templates': { |
| + 'json': { |
| + 'intro_tables.json': |
| + '{"tester": [{"Permissions": "<code>tester</code>"}]}' |
|
not at google - send to devlin
2013/04/30 18:34:19
what about Learn More? No Learn More? No Permissio
epeterson
2013/05/13 02:38:10
Done.
|
| + } |
| + } |
| + } |
| +} |
| def _MakeLink(href, text): |
| return '<a href="%s">%s</a>' % (href, text) |
| @@ -28,6 +40,13 @@ def _GetType(dict_, name): |
| if type_['name'] == name: |
| return type_ |
| +class FakeAvailabilityDataSourceFactory(object): |
| + def Create(self): |
| + return {} |
| + |
| +def _FakeGetAvailability(self): |
| + return 'Not Currently Available' |
| + |
| class FakeSamplesDataSource(object): |
| def Create(self, request): |
| return {} |
| @@ -50,6 +69,7 @@ class FakeAPIAndListDataSource(object): |
| class APIDataSourceTest(unittest.TestCase): |
| def setUp(self): |
| self._base_path = os.path.join(sys.path[0], 'test_data', 'test_json') |
| + _JSCModel._GetAvailability = _FakeGetAvailability |
|
not at google - send to devlin
2013/04/30 18:34:19
this is what passing in a fake availability data s
epeterson
2013/05/13 02:38:10
Done.
|
| def _ReadLocalFile(self, filename): |
| with open(os.path.join(self._base_path, filename), 'r') as f: |
| @@ -68,9 +88,12 @@ class APIDataSourceTest(unittest.TestCase): |
| def testCreateId(self): |
| data_source = FakeAPIAndListDataSource( |
| self._LoadJSON('test_file_data_source.json')) |
| + fake_avail_factory = FakeAvailabilityDataSourceFactory() |
|
not at google - send to devlin
2013/04/30 18:34:19
inline
epeterson
2013/05/13 02:38:10
Done.
|
| dict_ = _JSCModel(self._LoadJSON('test_file.json')[0], |
| self._CreateRefResolver('test_file_data_source.json'), |
| - False).ToDict() |
| + False, |
| + fake_avail_factory, |
| + TestFileSystem(deepcopy(_INTRO_TABLES_DATA))).ToDict() |
|
not at google - send to devlin
2013/04/30 18:34:19
save a reference in setUp?
epeterson
2013/05/13 02:38:10
Done.
|
| self.assertEquals('type-TypeA', dict_['types'][0]['id']) |
| self.assertEquals('property-TypeA-b', |
| dict_['types'][0]['properties'][0]['id']) |
| @@ -85,7 +108,9 @@ class APIDataSourceTest(unittest.TestCase): |
| self._LoadJSON('test_file_data_source.json')) |
| dict_ = _JSCModel(self._LoadJSON(filename)[0], |
| self._CreateRefResolver('test_file_data_source.json'), |
| - False).ToDict() |
| + False, |
| + fake_avail_factory, |
|
not at google - send to devlin
2013/04/30 18:34:19
the only reason this works is because the test is
epeterson
2013/05/13 02:38:10
Done.
|
| + TestFileSystem(deepcopy(_INTRO_TABLES_DATA))).ToDict() |
| self.assertEquals(expected_json, dict_) |
| def testFormatValue(self): |
| @@ -94,9 +119,12 @@ class APIDataSourceTest(unittest.TestCase): |
| self.assertEquals('234,567', _FormatValue(234567)) |
| def testFormatDescription(self): |
| + fake_avail_factory = FakeAvailabilityDataSourceFactory() |
| dict_ = _JSCModel(self._LoadJSON('ref_test.json')[0], |
| self._CreateRefResolver('ref_test_data_source.json'), |
| - False).ToDict() |
| + False, |
| + fake_avail_factory, |
| + TestFileSystem(deepcopy(_INTRO_TABLES_DATA))).ToDict() |
|
not at google - send to devlin
2013/04/30 18:34:19
ditto inline, safe reference comment
epeterson
2013/05/13 02:38:10
Done.
|
| self.assertEquals(_MakeLink('ref_test.html#type-type2', 'type2'), |
| _GetType(dict_, 'type1')['description']) |
| self.assertEquals( |
| @@ -173,7 +201,7 @@ class APIDataSourceTest(unittest.TestCase): |
| ] |
| } |
| - inlined_schema = copy.deepcopy(schema) |
| + inlined_schema = deepcopy(schema) |
| _InlineDocs(inlined_schema) |
| self.assertEqual(expected_schema, inlined_schema) |