OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright (c) 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. | |
5 | |
6 import types | |
7 import unittest | |
8 | |
9 from manifest_data_source import ManifestDataSource | |
10 | |
11 class MockCompiledFileSystem(object): | |
12 class Factory(object): | |
not at google - send to devlin
2013/05/10 04:14:14
It doesn't look like having a Factory here achieve
jshumway
2013/05/11 02:37:08
Replaced all of this stuff with the project's test
| |
13 def Create(self, _, __): | |
14 return MockCompiledFileSystem() | |
15 | |
16 def GetFromFile(self, path): | |
17 if path == 'features_path': | |
18 # Our example _manifest_features.json. | |
19 return { | |
20 'req0': { | |
21 'channel': 'stable', | |
22 'extension_types': ['packaged_app', 'extension'] | |
23 }, | |
24 'req1': { | |
25 'channel': 'dev', | |
26 'extension_types': 'all' | |
27 }, | |
28 'opt0': { | |
29 'channel': 'trunk', | |
30 'extension_types': ['extension'] | |
31 }, | |
32 'opt1': { | |
33 'channel': 'stable', | |
34 'extension_types': ['hosted_app'] | |
35 }, | |
36 'free0': { | |
37 'channel': 'stable', | |
38 'extension_types': ['platform_app'] | |
39 }, | |
40 'free1': { | |
41 'channel': 'dev', | |
42 'extension_types': ['packaged_app', 'hosted_app', 'extension'] | |
43 } | |
44 } | |
45 | |
46 def LoadManifestData(self, _): | |
47 # Our example manifest.json. | |
48 return { | |
49 'required': [ | |
50 {'name': 'req0'}, | |
51 {'name': 'req1'} | |
52 ], | |
53 'optional': [ | |
54 {'name': 'opt0'}, | |
55 {'name': 'opt1'} | |
56 ] | |
57 } | |
58 def Nothing(self, _): | |
59 # Do nothing. We don't care what Apply{Apps,Extensions}Transformations methods | |
60 # do because they change depending on data. | |
61 pass | |
62 | |
63 class ManifestDataSourceTest(unittest.TestCase): | |
64 def testCreateManifestData(self): | |
65 expected_extensions = { | |
66 'required': [ | |
67 {'name': 'req0'}, | |
68 {'name': 'req1'} | |
69 ], | |
70 'optional': [ | |
71 {'name': 'free1'}, | |
72 ] | |
73 } | |
74 | |
75 expected_apps = { | |
76 'required': [ | |
77 {'name': 'req0'}, | |
78 {'name': 'req1'} | |
79 ], | |
80 'optional': [ | |
81 {'name': 'opt1'}, | |
82 {'name': 'free0'}, | |
83 {'name': 'free1'} | |
84 ] | |
85 } | |
86 | |
87 mds = ManifestDataSource( | |
88 MockCompiledFileSystem.Factory(), 'manifest_path', 'features_path', | |
not at google - send to devlin
2013/05/10 04:14:14
4 space
jshumway
2013/05/11 02:37:08
Done.
| |
89 'dev') | |
90 | |
91 # Prevent an actual file load by patching in our load function. | |
not at google - send to devlin
2013/05/10 04:14:14
cool test data, but the test object store / file s
jshumway
2013/05/11 02:37:08
Fixed them up. I still override the two Apply*Tran
| |
92 mds._LoadManifestData = types.MethodType(LoadManifestData, mds) | |
93 mds._ApplyAppsTransformations = types.MethodType(Nothing, mds) | |
94 mds._ApplyExtensionsTransformations = types.MethodType(Nothing, mds) | |
95 | |
96 results = mds._CreateManifestData(None, None) | |
97 | |
98 self.assertEqual(expected_extensions, dict(results['extensions'])) | |
99 self.assertEqual(expected_apps, dict(results['apps'])) | |
100 | |
101 if __name__ == '__main__': | |
102 unittest.main() | |
OLD | NEW |