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

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

Issue 14218004: Devserver: only populate data during cron jobs, meaning all data from instances (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: PTAL Created 7 years, 8 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 | Annotate | Revision Log
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
11 from api_data_source import (APIDataSource, 11 from api_data_source import (APIDataSource,
12 _JSCModel, 12 _JSCModel,
13 _FormatValue, 13 _FormatValue,
14 _RemoveNoDocs) 14 _RemoveNoDocs)
15 from compiled_file_system import CompiledFileSystem 15 from compiled_file_system import CompiledFileSystem
16 from file_system import FileNotFoundError 16 from file_system import FileNotFoundError
17 from in_memory_object_store import InMemoryObjectStore
18 from local_file_system import LocalFileSystem 17 from local_file_system import LocalFileSystem
19 from object_store_creator import ObjectStoreCreator 18 from object_store_creator import ObjectStoreCreator
20 from reference_resolver import ReferenceResolver 19 from reference_resolver import ReferenceResolver
21 import third_party.json_schema_compiler.model as model 20 import third_party.json_schema_compiler.model as model
22 21
23 def _MakeLink(href, text): 22 def _MakeLink(href, text):
24 return '<a href="%s">%s</a>' % (href, text) 23 return '<a href="%s">%s</a>' % (href, text)
25 24
26 def _GetType(dict_, name): 25 def _GetType(dict_, name):
27 for type_ in dict_['types']: 26 for type_ in dict_['types']:
(...skipping 27 matching lines...) Expand all
55 with open(os.path.join(self._base_path, filename), 'r') as f: 54 with open(os.path.join(self._base_path, filename), 'r') as f:
56 return f.read() 55 return f.read()
57 56
58 def _CreateRefResolver(self, filename): 57 def _CreateRefResolver(self, filename):
59 data_source = FakeAPIAndListDataSource( 58 data_source = FakeAPIAndListDataSource(
60 self._LoadJSON(filename)) 59 self._LoadJSON(filename))
61 return ReferenceResolver.Factory(data_source, 60 return ReferenceResolver.Factory(data_source,
62 data_source, 61 data_source,
63 ObjectStoreCreator.Factory()).Create() 62 ObjectStoreCreator.Factory()).Create()
64 63
65 def DISABLED_testSimple(self):
66 compiled_fs_factory = CompiledFileSystem.Factory(
67 LocalFileSystem(self._base_path),
68 InMemoryObjectStore('fake_branch'))
69 data_source_factory = APIDataSource.Factory(compiled_fs_factory,
70 '.')
71 data_source_factory.SetSamplesDataSourceFactory(FakeSamplesDataSource())
72 data_source = data_source_factory.Create({}, disable_refs=True)
73
74 # Take the dict out of the list.
75 expected = json.loads(self._ReadLocalFile('expected_test_file.json'))
76 expected['permissions'] = None
77 test1 = data_source.get('test_file')
78 test1.pop('samples')
79 self.assertEqual(expected, test1)
80 test2 = data_source.get('testFile')
81 test2.pop('samples')
82 self.assertEqual(expected, test2)
83 test3 = data_source.get('testFile.html')
84 test3.pop('samples')
85 self.assertEqual(expected, test3)
86 self.assertRaises(FileNotFoundError, data_source.get, 'junk')
87
88 def _LoadJSON(self, filename): 64 def _LoadJSON(self, filename):
89 return json.loads(self._ReadLocalFile(filename)) 65 return json.loads(self._ReadLocalFile(filename))
90 66
91 def testCreateId(self): 67 def testCreateId(self):
92 data_source = FakeAPIAndListDataSource( 68 data_source = FakeAPIAndListDataSource(
93 self._LoadJSON('test_file_data_source.json')) 69 self._LoadJSON('test_file_data_source.json'))
94 dict_ = _JSCModel(self._LoadJSON('test_file.json')[0], 70 dict_ = _JSCModel(self._LoadJSON('test_file.json')[0],
95 self._CreateRefResolver('test_file_data_source.json'), 71 self._CreateRefResolver('test_file_data_source.json'),
96 False).ToDict() 72 False).ToDict()
97 self.assertEquals('type-TypeA', dict_['types'][0]['id']) 73 self.assertEquals('type-TypeA', dict_['types'][0]['id'])
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 _MakeLink('ref_test.html#type-type2', 'type2')), 107 _MakeLink('ref_test.html#type-type2', 'type2')),
132 _GetType(dict_, 'type3')['description']) 108 _GetType(dict_, 'type3')['description'])
133 109
134 def testRemoveNoDocs(self): 110 def testRemoveNoDocs(self):
135 d = self._LoadJSON('nodoc_test.json') 111 d = self._LoadJSON('nodoc_test.json')
136 _RemoveNoDocs(d) 112 _RemoveNoDocs(d)
137 self.assertEqual(self._LoadJSON('expected_nodoc.json'), d) 113 self.assertEqual(self._LoadJSON('expected_nodoc.json'), d)
138 114
139 if __name__ == '__main__': 115 if __name__ == '__main__':
140 unittest.main() 116 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698