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

Side by Side Diff: chrome/common/extensions/docs/server2/api_data_source_test.py

Issue 368973002: Docserver: Add more support for object level availability in templates (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 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 unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import json 6 import json
7 import os 7 import os
8 import sys 8 import sys
9 import unittest 9 import unittest
10 10
(...skipping 20 matching lines...) Expand all
31 from test_util import Server2Path 31 from test_util import Server2Path
32 from third_party.json_schema_compiler.memoize import memoize 32 from third_party.json_schema_compiler.memoize import memoize
33 33
34 34
35 class _FakeTemplateCache(object): 35 class _FakeTemplateCache(object):
36 36
37 def GetFromFile(self, key): 37 def GetFromFile(self, key):
38 return Future(value='handlebar %s' % key) 38 return Future(value='handlebar %s' % key)
39 39
40 40
41 class _FakeAvailabilityFinder(object):
42 def __init__(self, fake_availability):
43 self._fake_availability = fake_availability
44
45 def GetAPIAvailability(self, api_name):
46 return self._fake_availability
47
48 def GetAPINodeAvailability(self, api_name):
49 '''The tests that use this fake class don't
50 use the node availability, so just return a
51 dummy graph.
52 '''
53 return APISchemaGraph(_graph={'dummy': 'graph'})
54
55
56 class _FakeFeaturesBundle(object): 41 class _FakeFeaturesBundle(object):
57 def GetAPIFeatures(self): 42 def GetAPIFeatures(self):
58 return Future(value={ 43 return Future(value={
59 'bluetooth': {'value': True}, 44 'bluetooth': {'value': True},
60 'contextMenus': {'value': True}, 45 'contextMenus': {'value': True},
61 'jsonStableAPI': {'value': True}, 46 'jsonStableAPI': {'value': True},
62 'idle': {'value': True}, 47 'idle': {'value': True},
63 'input.ime': {'value': True}, 48 'input.ime': {'value': True},
64 'tabs': {'value': True} 49 'tabs': {'value': True}
65 }) 50 })
66 51
67 52
68 class _FakeAvailabilityFinder(object): 53 class _FakeAvailabilityFinder(object):
69 def __init__(self, fake_availability): 54 def __init__(self, fake_availability):
70 self._fake_availability = fake_availability 55 self._fake_availability = fake_availability
71 56
72 def GetAPIAvailability(self, api_name): 57 def GetAPIAvailability(self, api_name):
73 return self._fake_availability 58 return self._fake_availability
74 59
75 def GetAPINodeAvailability(self, api_name): 60 def GetAPINodeAvailability(self, api_name):
76 '''The tests that use this fake class don't 61 schema_graph = APISchemaGraph()
77 use the node availability, so just return a 62 api_graph = APISchemaGraph(json.loads(
78 dummy graph. 63 CANNED_TRUNK_FS_DATA['api'][api_name + '.json']))
79 ''' 64 # Give the graph fake ChannelInfo; it's not used in tests.
80 return APISchemaGraph(_graph={'dummy': 'graph'}) 65 schema_graph.Update(api_graph, annotation=ChannelInfo('stable', '28', 28))
66 return schema_graph
81 67
82 68
83 class APIDataSourceTest(unittest.TestCase): 69 class APIDataSourceTest(unittest.TestCase):
84 def setUp(self): 70 def setUp(self):
85 self._base_path = Server2Path('test_data', 'test_json') 71 self._base_path = Server2Path('test_data', 'test_json')
86 72
87 server_instance = ServerInstance.ForTest( 73 server_instance = ServerInstance.ForTest(
88 TestFileSystem(CANNED_TRUNK_FS_DATA, relative_to=CHROME_EXTENSIONS)) 74 TestFileSystem(CANNED_TRUNK_FS_DATA, relative_to=CHROME_EXTENSIONS))
89 file_system = server_instance.host_file_system_provider.GetTrunk() 75 file_system = server_instance.host_file_system_provider.GetTrunk()
90 self._json_cache = server_instance.compiled_fs_factory.ForJson(file_system) 76 self._json_cache = server_instance.compiled_fs_factory.ForJson(file_system)
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 self._json_cache, 141 self._json_cache,
156 _FakeTemplateCache(), 142 _FakeTemplateCache(),
157 self._features_bundle, 143 self._features_bundle,
158 None).ToDict() 144 None).ToDict()
159 self.assertEquals(expected_json, dict_) 145 self.assertEquals(expected_json, dict_)
160 146
161 def testAddRules(self): 147 def testAddRules(self):
162 fake_avail_finder = _FakeAvailabilityFinder(self._fake_availability) 148 fake_avail_finder = _FakeAvailabilityFinder(self._fake_availability)
163 dict_ = _JSCModel(self._api_models.GetModel('add_rules_tester').Get(), 149 dict_ = _JSCModel(self._api_models.GetModel('add_rules_tester').Get(),
164 fake_avail_finder, 150 fake_avail_finder,
165 #self._fake_availability,
166 self._json_cache, 151 self._json_cache,
167 _FakeTemplateCache(), 152 _FakeTemplateCache(),
168 self._features_bundle, 153 self._features_bundle,
169 self._FakeLoadAddRulesSchema()).ToDict() 154 self._FakeLoadAddRulesSchema()).ToDict()
170 155
171 # Check that the first event has the addRulesFunction defined. 156 # Check that the first event has the addRulesFunction defined.
172 self.assertEquals('add_rules_tester', dict_['name']) 157 self.assertEquals('add_rules_tester', dict_['name'])
173 self.assertEquals('rules', dict_['events'][0]['name']) 158 self.assertEquals('rules', dict_['events'][0]['name'])
174 self.assertEquals('notable_name_to_check_for', 159 self.assertEquals('notable_name_to_check_for',
175 dict_['events'][0]['byName']['addRules'][ 160 dict_['events'][0]['byName']['addRules'][
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 338
354 # Test nodes that have the same availability as their parent. 339 # Test nodes that have the same availability as their parent.
355 assertEquals('tabs.get', model_dict['functions'][1]['availability']) 340 assertEquals('tabs.get', model_dict['functions'][1]['availability'])
356 # Test nodes with varying availabilities. 341 # Test nodes with varying availabilities.
357 assertEquals('tabs.getCurrent', 342 assertEquals('tabs.getCurrent',
358 model_dict['functions'][0]['availability']['version']) 343 model_dict['functions'][0]['availability']['version'])
359 344
360 345
361 if __name__ == '__main__': 346 if __name__ == '__main__':
362 unittest.main() 347 unittest.main()
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/server2/api_data_source.py ('k') | chrome/common/extensions/docs/server2/app.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698