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

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

Issue 56083005: Docserver: Cleanup to remove the APIListDataSource dependency from (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 1 month 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
« no previous file with comments | « no previous file | chrome/common/extensions/docs/server2/api_list_data_source.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 611ef49717737fbbad896f0ff6bf99e8428bee0c..5aac1d666896cc4595a52718f6f63830c80dfbdf 100755
--- a/chrome/common/extensions/docs/server2/api_data_source_test.py
+++ b/chrome/common/extensions/docs/server2/api_data_source_test.py
@@ -35,19 +35,20 @@ def _GetType(dict_, name):
return type_
-class FakeAvailabilityFinder(object):
+class _FakeAvailabilityFinder(object):
def GetApiAvailability(self, version):
return ChannelInfo('stable', '396', 5)
-class FakeSamplesDataSource(object):
+class _FakeSamplesDataSource(object):
def Create(self, request):
return {}
-class FakeAPIAndListDataSource(object):
+# Sad irony :(
+class _FakeAPIDataSource(object):
def __init__(self, json_data):
self._json = json_data
@@ -60,11 +61,17 @@ class FakeAPIAndListDataSource(object):
raise FileNotFoundError(key)
return self._json[key]
- def GetAllNames(self):
- return self._json.keys()
+class _FakeAPIModels(object):
-class FakeTemplateCache(object):
+ def __init__(self, names):
+ self._names = names
+
+ def GetNames(self):
+ return self._names
+
+
+class _FakeTemplateCache(object):
def GetFromFile(self, key):
return Future(value='handlebar %s' % key)
@@ -84,25 +91,22 @@ class APIDataSourceTest(unittest.TestCase):
return f.read()
def _CreateRefResolver(self, filename):
- data_source = FakeAPIAndListDataSource(
- self._LoadJSON(filename))
- return ReferenceResolver.Factory(data_source,
- data_source,
+ test_data = self._LoadJSON(filename)
+ return ReferenceResolver.Factory(_FakeAPIDataSource(test_data),
+ _FakeAPIModels(test_data),
ObjectStoreCreator.ForTest()).Create()
def _LoadJSON(self, filename):
return json.loads(self._ReadLocalFile(filename))
def testCreateId(self):
- data_source = FakeAPIAndListDataSource(
- self._LoadJSON('test_file_data_source.json'))
dict_ = _JSCModel(self._LoadJSON('test_file.json')[0],
self._CreateRefResolver('test_file_data_source.json'),
False,
- FakeAvailabilityFinder(),
+ _FakeAvailabilityFinder(),
TestBranchUtility.CreateWithCannedData(),
self._json_cache,
- FakeTemplateCache(),
+ _FakeTemplateCache(),
None).ToDict()
self.assertEquals('type-TypeA', dict_['types'][0]['id'])
self.assertEquals('property-TypeA-b',
@@ -114,15 +118,13 @@ class APIDataSourceTest(unittest.TestCase):
def DISABLED_testToDict(self):
filename = 'test_file.json'
expected_json = self._LoadJSON('expected_' + filename)
- data_source = FakeAPIAndListDataSource(
- self._LoadJSON('test_file_data_source.json'))
dict_ = _JSCModel(self._LoadJSON(filename)[0],
self._CreateRefResolver('test_file_data_source.json'),
False,
- FakeAvailabilityFinder(),
+ _FakeAvailabilityFinder(),
TestBranchUtility.CreateWithCannedData(),
self._json_cache,
- FakeTemplateCache(),
+ _FakeTemplateCache(),
None).ToDict()
self.assertEquals(expected_json, dict_)
@@ -135,10 +137,10 @@ class APIDataSourceTest(unittest.TestCase):
dict_ = _JSCModel(self._LoadJSON('ref_test.json')[0],
self._CreateRefResolver('ref_test_data_source.json'),
False,
- FakeAvailabilityFinder(),
+ _FakeAvailabilityFinder(),
TestBranchUtility.CreateWithCannedData(),
self._json_cache,
- FakeTemplateCache(),
+ _FakeTemplateCache(),
None).ToDict()
self.assertEquals(_MakeLink('ref_test.html#type-type2', 'type2'),
_GetType(dict_, 'type1')['description'])
@@ -156,13 +158,13 @@ class APIDataSourceTest(unittest.TestCase):
model = _JSCModel(self._LoadJSON('test_file.json')[0],
self._CreateRefResolver('test_file_data_source.json'),
False,
- FakeAvailabilityFinder(),
+ _FakeAvailabilityFinder(),
TestBranchUtility.CreateWithCannedData(),
self._json_cache,
- FakeTemplateCache(),
+ _FakeTemplateCache(),
None)
# The model namespace is "tester". No predetermined availability is found,
- # so the FakeAvailabilityFinder instance is used to find availability.
+ # so the _FakeAvailabilityFinder instance is used to find availability.
self.assertEqual(ChannelInfo('stable', '396', 5),
model._GetApiAvailability())
@@ -188,10 +190,10 @@ class APIDataSourceTest(unittest.TestCase):
model = _JSCModel(self._LoadJSON('test_file.json')[0],
self._CreateRefResolver('test_file_data_source.json'),
False,
- FakeAvailabilityFinder(),
+ _FakeAvailabilityFinder(),
TestBranchUtility.CreateWithCannedData(),
self._json_cache,
- FakeTemplateCache(),
+ _FakeTemplateCache(),
None)
expected_list = [
{ 'title': 'Description',
@@ -257,15 +259,13 @@ class APIDataSourceTest(unittest.TestCase):
return _GetEventByNameFromEvents(events)
def testAddRules(self):
- data_source = FakeAPIAndListDataSource(
- self._LoadJSON('test_file_data_source.json'))
dict_ = _JSCModel(self._LoadJSON('add_rules_test.json')[0],
self._CreateRefResolver('test_file_data_source.json'),
False,
- FakeAvailabilityFinder(),
+ _FakeAvailabilityFinder(),
TestBranchUtility.CreateWithCannedData(),
self._json_cache,
- FakeTemplateCache(),
+ _FakeTemplateCache(),
self._FakeLoadAddRulesSchema).ToDict()
# Check that the first event has the addRulesFunction defined.
self.assertEquals('tester', dict_['name'])
« no previous file with comments | « no previous file | chrome/common/extensions/docs/server2/api_list_data_source.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698