| 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 5e935880a600ab9b85baee322912324ae8337c6a..958707a58b8852d2050cc4ec2fd08d88f8b073e3 100755
|
| --- a/chrome/common/extensions/docs/server2/api_data_source_test.py
|
| +++ b/chrome/common/extensions/docs/server2/api_data_source_test.py
|
| @@ -3,6 +3,7 @@
|
| # Use of this source code is governed by a BSD-style license that can be
|
| # found in the LICENSE file.
|
|
|
| +from copy import deepcopy
|
| import json
|
| import os
|
| import sys
|
| @@ -17,8 +18,20 @@ 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.model as model
|
|
|
| +_INTRO_TABLES_DATA = {
|
| + 'docs': {
|
| + 'templates': {
|
| + 'json': {
|
| + 'intro_tables.json':
|
| + '{"tester": [{"Permissions": "<code>tester</code>"}]}'
|
| + }
|
| + }
|
| + }
|
| +}
|
| +
|
| def _MakeLink(href, text):
|
| return '<a href="%s">%s</a>' % (href, text)
|
|
|
| @@ -27,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 {}
|
| @@ -49,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
|
|
|
| def _ReadLocalFile(self, filename):
|
| with open(os.path.join(self._base_path, filename), 'r') as f:
|
| @@ -67,9 +88,12 @@ class APIDataSourceTest(unittest.TestCase):
|
| def testCreateId(self):
|
| data_source = FakeAPIAndListDataSource(
|
| self._LoadJSON('test_file_data_source.json'))
|
| + fake_avail_factory = FakeAvailabilityDataSourceFactory()
|
| 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()
|
| self.assertEquals('type-TypeA', dict_['types'][0]['id'])
|
| self.assertEquals('property-TypeA-b',
|
| dict_['types'][0]['properties'][0]['id'])
|
| @@ -84,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,
|
| + TestFileSystem(deepcopy(_INTRO_TABLES_DATA))).ToDict()
|
| self.assertEquals(expected_json, dict_)
|
|
|
| def testFormatValue(self):
|
| @@ -93,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()
|
| self.assertEquals(_MakeLink('ref_test.html#type-type2', 'type2'),
|
| _GetType(dict_, 'type1')['description'])
|
| self.assertEquals(
|
|
|