Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5867)

Unified Diff: chrome/common/extensions/docs/server2/api_data_source_test.py

Issue 12996003: Dynamically generate a heading for Extension Docs API pages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing comments - Patch currently being broken up Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 f648ce267db442d0b4b02c9b2ae07a4d11c97919..24a11a61f4a79518d4ae3302d35eb387c6c5762e 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
@@ -14,9 +14,13 @@ from api_data_source import (_JSCModel,
_RemoveNoDocs,
_DetectInlineableTypes,
_InlineDocs)
+from compiled_file_system import CompiledFileSystem
from file_system import FileNotFoundError
from object_store_creator import ObjectStoreCreator
from reference_resolver import ReferenceResolver
+from test_data.canned_data import CANNED_TEST_FILE_SYSTEM_DATA
+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)
@@ -26,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 {}
@@ -48,6 +56,13 @@ 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(CANNED_TEST_FILE_SYSTEM_DATA),
+ ObjectStoreCreator.ForTest())
+ self._json_cache = self._compiled_fs_factory.Create(
+ lambda _, json: json_parse.Parse(json),
+ APIDataSourceTest,
+ 'test')
def _ReadLocalFile(self, filename):
with open(os.path.join(self._base_path, filename), 'r') as f:
@@ -68,7 +83,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'])
@@ -83,7 +100,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):
@@ -94,7 +113,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(
@@ -109,7 +130,31 @@ 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(),
+ [
+ { "permission": "tester" },
+ { "extra": "is an API." }
+ ])
+
+ 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(),
+ [{
+ 'href': 'https://tester.test.com/welcome.html',
+ 'content': 'Welcome!'
+ }])
def testInlineDocs(self):
schema = {
@@ -171,7 +216,7 @@ class APIDataSourceTest(unittest.TestCase):
]
}
- inlined_schema = copy.deepcopy(schema)
+ inlined_schema = deepcopy(schema)
_InlineDocs(inlined_schema)
self.assertEqual(expected_schema, inlined_schema)

Powered by Google App Engine
This is Rietveld 408576698