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 f3c472f74a0700482da78ebfb4bc30efba9ca8b7..e3f7151be433374ef491a5dd97d94e73b7293f6f 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,8 @@ 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 |
| +import third_party.json_schema_compiler.json_parse as json_parse |
| def _MakeLink(href, text): |
| return '<a href="%s">%s</a>' % (href, text) |
| @@ -28,6 +30,10 @@ def _GetType(dict_, name): |
| if type_['name'] == name: |
| return type_ |
| +class FakeAvailabilityFinder(object): |
| + def GetApiAvailability(self, version): |
| + return None |
| + |
| class FakeSamplesDataSource(object): |
| def Create(self, request): |
| return {} |
| @@ -50,6 +56,16 @@ class FakeAPIAndListDataSource(object): |
| class APIDataSourceTest(unittest.TestCase): |
| def setUp(self): |
| self._base_path = os.path.join(sys.path[0], 'test_data', 'test_json') |
| + self._compiled_fs_factory = CompiledFileSystem.Factory( |
| + TestFileSystem(self._LoadJSON(os.path.join( |
| + self._base_path, |
| + 'basic_docs_filesystem.json'))), |
|
not at google - send to devlin
2013/06/05 00:24:09
define this in python somewhere, not a JSON file,
epeterson
2013/06/17 20:05:49
Done.
|
| + ObjectStoreCreator.ForTest()) |
| + def compiled_fs_parse(path, json): |
| + return json_parse.Parse(json) |
| + self._json_cache = self._compiled_fs_factory.Create(compiled_fs_parse, |
| + APIDataSourceTest, |
| + 'test') |
| def _ReadLocalFile(self, filename): |
| with open(os.path.join(self._base_path, filename), 'r') as f: |
| @@ -70,7 +86,9 @@ class APIDataSourceTest(unittest.TestCase): |
| self._LoadJSON('test_file_data_source.json')) |
| dict_ = _JSCModel(self._LoadJSON('test_file.json')[0], |
| self._CreateRefResolver('test_file_data_source.json'), |
| - False).ToDict() |
| + False, |
| + FakeAvailabilityFinder(), |
| + self._json_cache).ToDict() |
| self.assertEquals('type-TypeA', dict_['types'][0]['id']) |
| self.assertEquals('property-TypeA-b', |
| dict_['types'][0]['properties'][0]['id']) |
| @@ -85,7 +103,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, |
| + FakeAvailabilityFinder(), |
| + self._json_cache).ToDict() |
| self.assertEquals(expected_json, dict_) |
| def testFormatValue(self): |
| @@ -96,7 +116,9 @@ class APIDataSourceTest(unittest.TestCase): |
| def testFormatDescription(self): |
| dict_ = _JSCModel(self._LoadJSON('ref_test.json')[0], |
| self._CreateRefResolver('ref_test_data_source.json'), |
| - False).ToDict() |
| + False, |
| + FakeAvailabilityFinder(), |
| + self._json_cache).ToDict() |
| self.assertEquals(_MakeLink('ref_test.html#type-type2', 'type2'), |
| _GetType(dict_, 'type1')['description']) |
| self.assertEquals( |
| @@ -111,7 +133,25 @@ class APIDataSourceTest(unittest.TestCase): |
| def testRemoveNoDocs(self): |
| d = self._LoadJSON('nodoc_test.json') |
| _RemoveNoDocs(d) |
| - self.assertEqual(self._LoadJSON('expected_nodoc.json'), d) |
| + self.assertEquals(self._LoadJSON('expected_nodoc.json'), d) |
| + |
| + def testGetPermissions(self): |
| + model = _JSCModel(self._LoadJSON('test_file.json')[0], |
| + self._CreateRefResolver('test_file_data_source.json'), |
| + False, |
| + FakeAvailabilityFinder(), |
| + self._json_cache) |
| + self.assertEquals(model._GetPermissions(), |
| + self._LoadJSON('api_permissions_expected.json')) |
| + |
| + def testGetMoreLearning(self): |
| + model = _JSCModel(self._LoadJSON('test_file.json')[0], |
| + self._CreateRefResolver('test_file_data_source.json'), |
| + False, |
| + FakeAvailabilityFinder(), |
| + self._json_cache) |
| + self.assertEquals(model._GetMoreLearning(), |
| + self._LoadJSON('api_learn_more_expected.json')) |
|
not at google - send to devlin
2013/06/05 00:24:09
please just get this data from the canned file sys
epeterson
2013/06/17 20:05:49
Done, for the tests I added, at least. Should I go
not at google - send to devlin
2013/06/19 15:57:37
Same reply to the other comment.
|
| def testInlineDocs(self): |
| schema = { |
| @@ -173,7 +213,7 @@ class APIDataSourceTest(unittest.TestCase): |
| ] |
| } |
| - inlined_schema = copy.deepcopy(schema) |
| + inlined_schema = deepcopy(schema) |
| _InlineDocs(inlined_schema) |
| self.assertEqual(expected_schema, inlined_schema) |