OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 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 from copy import deepcopy | 6 from copy import deepcopy |
7 import json | 7 import json |
8 import unittest | 8 import unittest |
9 | 9 |
10 from compiled_file_system import CompiledFileSystem | 10 from compiled_file_system import CompiledFileSystem |
| 11 from features_bundle import FeaturesBundle |
11 import manifest_data_source | 12 import manifest_data_source |
12 from object_store_creator import ObjectStoreCreator | 13 from object_store_creator import ObjectStoreCreator |
13 from test_file_system import TestFileSystem | |
14 | 14 |
15 | 15 |
16 convert_and_annotate_docs = { | 16 convert_and_annotate_docs = { |
17 'name': { | 17 'name': { |
18 'example': "My {{title}}", | 18 'example': "My {{title}}", |
19 'name': 'name', | 19 'name': 'name', |
20 'level': 'required' | 20 'level': 'required' |
21 }, | 21 }, |
22 'doc2': { | 22 'doc2': { |
23 'level': 'required', | 23 'level': 'required', |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 } | 192 } |
193 ] | 193 ] |
194 } | 194 } |
195 ] | 195 ] |
196 } | 196 } |
197 ] | 197 ] |
198 } | 198 } |
199 ] | 199 ] |
200 | 200 |
201 self.assertEqual( | 201 self.assertEqual( |
202 expected_docs, manifest_data_source._ListifyAndSortDocs(docs, 'app')) | 202 expected_docs, manifest_data_source._ListifyAndSortDocs(docs, 'apps')) |
203 | 203 |
204 def testManifestDataSource(self): | 204 def testManifestDataSource(self): |
205 file_system = TestFileSystem({ | 205 manifest_features = { |
206 '_manifest_features.json': json.dumps({ | 206 'doc1': { |
207 'doc1': { | 207 'name': 'doc1', |
208 'extension_types': 'all' | 208 'platforms': ['apps', 'extensions'], |
209 }, | 209 'example': {}, |
210 'doc1.sub1': { | 210 'level': 'required' |
211 'extension_types': ['platform_app'] | 211 }, |
212 }, | 212 'doc1.sub1': { |
213 'doc2': { | 213 'name': 'doc1.sub1', |
214 'extension_types': ['extension'] | 214 'platforms': ['apps'], |
215 } | 215 'annotations': ['important!'], |
216 }), | 216 'level': 'recommended' |
217 'manifest.json': json.dumps({ | 217 }, |
218 'doc1': { | 218 'doc2': { |
219 'example': {}, | 219 'name': 'doc2', |
220 'level': 'required' | 220 'platforms': ['extensions'] |
221 }, | 221 } |
222 'doc1.sub1': { | 222 } |
223 'annotations': ['important!'], | |
224 'level': 'recommended' | |
225 } | |
226 }) | |
227 }) | |
228 | 223 |
229 expected_app = [ | 224 expected_app = [ |
230 { | 225 { |
231 'example': '{...}', | 226 'example': '{...}', |
232 'has_example': True, | 227 'has_example': True, |
233 'level': 'required', | 228 'level': 'required', |
234 'name': 'doc1', | 229 'name': 'doc1', |
235 'platforms': ['app', 'extension'], | 230 'platforms': ['apps', 'extensions'], |
236 'children': [ | 231 'children': [ |
237 { | 232 { |
238 'annotations': [ | 233 'annotations': [ |
239 'Recommended', | 234 'Recommended', |
240 'important!' | 235 'important!' |
241 ], | 236 ], |
242 'level': 'recommended', | 237 'level': 'recommended', |
243 'name': 'sub1', | 238 'name': 'sub1', |
244 'platforms': ['app'], | 239 'platforms': ['apps'], |
245 'is_last': True | 240 'is_last': True |
246 } | 241 } |
247 ], | 242 ], |
248 'is_last': True | 243 'is_last': True |
249 } | 244 } |
250 ] | 245 ] |
251 | 246 |
| 247 class FakeFeaturesBundle(object): |
| 248 def GetManifestFeatures(self): |
| 249 return manifest_features |
| 250 |
252 class FakeServerInstance(object): | 251 class FakeServerInstance(object): |
253 def __init__(self): | 252 def __init__(self): |
254 self.host_file_system = file_system | 253 self.features_bundle = FakeFeaturesBundle() |
255 self.compiled_host_fs_factory = CompiledFileSystem.Factory( | 254 self.object_store_creator = ObjectStoreCreator.ForTest() |
256 file_system, ObjectStoreCreator.ForTest()) | |
257 self.manifest_json_path = 'manifest.json' | |
258 self.manifest_features_path = '_manifest_features.json' | |
259 | 255 |
260 mds = manifest_data_source.ManifestDataSource(FakeServerInstance(), None) | 256 mds = manifest_data_source.ManifestDataSource(FakeServerInstance(), None) |
261 self.assertEqual(expected_app, mds.get('apps')) | 257 self.assertEqual(expected_app, mds.get('apps')) |
262 | 258 |
263 if __name__ == '__main__': | 259 if __name__ == '__main__': |
264 unittest.main() | 260 unittest.main() |
OLD | NEW |