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
4 # found in the LICENSE file.
6 from copy
import deepcopy
10 from future
import Future
11 import manifest_data_source
12 from object_store_creator
import ObjectStoreCreator
15 convert_and_annotate_docs
= {
17 'example': "My {{platform}}",
30 'annotations': ['not so important'],
45 'level': 'recommended',
59 class ManifestDataSourceTest(unittest
.TestCase
):
60 def testListifyAndSortDocs(self
):
71 'annotations': ['not so important'],
83 'example': '"My App"',
88 'level': 'recommended',
105 self
.assertEqual(expected_docs
, manifest_data_source
._ListifyAndSortDocs
(
106 deepcopy(convert_and_annotate_docs
), 'App'))
108 def testAnnotate(self
):
119 'annotations': ['Optional', 'not so important'],
133 'example': '"My App"',
137 'annotations': ['Recommended'],
138 'level': 'recommended',
142 'annotations': ['Pick one (or none)'],
151 'annotations': ['Optional'],
158 annotated
= manifest_data_source
._ListifyAndSortDocs
(
159 deepcopy(convert_and_annotate_docs
), 'App')
160 manifest_data_source
._AddLevelAnnotations
(annotated
)
161 self
.assertEqual(expected_docs
, annotated
)
163 def testExpandedExamples(self
):
170 'json_example': ['with', 'more', 'json']
188 'name': 'json_example',
189 'example': json
.dumps(['with', 'more', 'json']),
201 expected_docs
, manifest_data_source
._ListifyAndSortDocs
(docs
, 'apps'))
203 def testNonExpandedExamples(self
):
237 expected_docs
, manifest_data_source
._ListifyAndSortDocs
(docs
, 'apps'))
239 def testManifestDataSource(self
):
240 manifest_features
= {
243 'platforms': ['apps', 'extensions'],
249 'platforms': ['apps'],
250 'annotations': ['important!'],
251 'level': 'recommended'
261 'platforms': ['apps', 'extensions'],
268 'level': 'recommended',
270 'platforms': ['apps'],
278 class FakePlatformBundle(object):
279 def GetFeaturesBundle(self
, platform
):
280 return FakeFeaturesBundle()
282 class FakeFeaturesBundle(object):
283 def GetManifestFeatures(self
):
284 return Future(value
=manifest_features
)
286 class FakeServerInstance(object):
288 self
.platform_bundle
= FakePlatformBundle()
289 self
.object_store_creator
= ObjectStoreCreator
.ForTest()
291 mds
= manifest_data_source
.ManifestDataSource(FakeServerInstance(), None)
292 self
.assertEqual(expected_app
, mds
.get('apps'))
294 if __name__
== '__main__':