OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 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. |
| 5 |
| 6 from copy import deepcopy |
| 7 import unittest |
| 8 |
| 9 from features_model import FeaturesModel |
| 10 |
| 11 raw_features_json = { |
| 12 'doc1': { |
| 13 'extension_types': ['extension', 'platform_app'] |
| 14 }, |
| 15 'doc2': { |
| 16 'extension_types': ['hosted_app', 'packaged_app'] |
| 17 }, |
| 18 'doc3': { |
| 19 'whitelist': 'hashhashashhashashhashashhash' |
| 20 }, |
| 21 'doc4': [ |
| 22 { |
| 23 'extension_types': 'all' |
| 24 }, |
| 25 { |
| 26 'whitelist': 'hashhashashhashashhashashhash' |
| 27 } |
| 28 ], |
| 29 'doc5': { |
| 30 'extension_types': ['extension'] |
| 31 }, |
| 32 'doc1.sub1': { |
| 33 'extension_types': ['platform_app', 'hosted_app', 'packaged_app'] |
| 34 } |
| 35 } |
| 36 |
| 37 class FeaturesUtilityTest(unittest.TestCase): |
| 38 def testFeatureFile(self): |
| 39 init_json = { |
| 40 'doc1': { |
| 41 'platform': ['extension', 'app'], |
| 42 'name': 'doc1' |
| 43 }, |
| 44 'doc2': { |
| 45 'platform': [], |
| 46 'name': 'doc2' |
| 47 }, |
| 48 'doc4': { |
| 49 'platform': ['extension', 'app'], |
| 50 'name': 'doc4' |
| 51 }, |
| 52 'doc5': { |
| 53 'platform': ['extension'], |
| 54 'name': 'doc5' |
| 55 }, |
| 56 'doc1.sub1': { |
| 57 'platform': ['app'], |
| 58 'name': 'doc1.sub1' |
| 59 } |
| 60 } |
| 61 |
| 62 features_model = FeaturesModel().LoadFeaturesJson(raw_features_json) |
| 63 self.assertEqual(init_json, features_model.Get()) |
| 64 |
| 65 additional_dict = { |
| 66 'doc1': { |
| 67 'documentation': 'http://documentation' |
| 68 }, |
| 69 'doc2': { |
| 70 'children': { |
| 71 'sub': { |
| 72 'name': 'sub' |
| 73 } |
| 74 } |
| 75 }, |
| 76 'doc5': { |
| 77 'example': {} |
| 78 } |
| 79 } |
| 80 |
| 81 expected_merge_result = { |
| 82 'doc1': { |
| 83 'documentation': 'http://documentation', |
| 84 'platform': ['extension', 'app'], |
| 85 'name': 'doc1' |
| 86 }, |
| 87 'doc2': { |
| 88 'platform': [], |
| 89 'name': 'doc2', |
| 90 'children': { |
| 91 'sub': { |
| 92 'name': 'sub' |
| 93 } |
| 94 } |
| 95 }, |
| 96 'doc4': { |
| 97 'platform': ['extension', 'app'], |
| 98 'name': 'doc4' |
| 99 }, |
| 100 'doc5': { |
| 101 'platform': ['extension'], |
| 102 'name': 'doc5', |
| 103 'example': {} |
| 104 }, |
| 105 'doc1.sub1': { |
| 106 'platform': ['app'], |
| 107 'name': 'doc1.sub1' |
| 108 } |
| 109 } |
| 110 |
| 111 features_model = features_model.MergeWith(additional_dict) |
| 112 self.assertEqual(expected_merge_result, features_model.Get()) |
| 113 |
| 114 expected_filter = { |
| 115 'doc1': { |
| 116 'documentation': 'http://documentation', |
| 117 'platform': ['extension', 'app'], |
| 118 'name': 'doc1' |
| 119 }, |
| 120 'doc4': { |
| 121 'platform': ['extension', 'app'], |
| 122 'name': 'doc4' |
| 123 }, |
| 124 'doc5': { |
| 125 'platform': ['extension'], |
| 126 'name': 'doc5', |
| 127 'example': {} |
| 128 } |
| 129 } |
| 130 |
| 131 self.assertEqual( |
| 132 expected_filter, features_model.Filter('extension').Get()) |
| 133 |
| 134 expecting = { |
| 135 'doc1': { |
| 136 'documentation': 'http://documentation', |
| 137 'platform': ['extension', 'app'], |
| 138 'name': 'doc1', |
| 139 'children': { |
| 140 'sub1': { |
| 141 'name': 'sub1', |
| 142 'platform': ['app'] |
| 143 } |
| 144 } |
| 145 }, |
| 146 'doc2': { |
| 147 'platform': [], |
| 148 'name': 'doc2', |
| 149 'children': { |
| 150 'sub': { |
| 151 'name': 'sub' |
| 152 } |
| 153 } |
| 154 }, |
| 155 'doc4': { |
| 156 'platform': ['extension', 'app'], |
| 157 'name': 'doc4' |
| 158 }, |
| 159 'doc5': { |
| 160 'platform': ['extension'], |
| 161 'name': 'doc5', |
| 162 'example': {} |
| 163 } |
| 164 } |
| 165 |
| 166 self.assertEqual( |
| 167 expecting, features_model.RestructureChildren()) |
| 168 |
| 169 if __name__ == '__main__': |
| 170 unittest.main() |
OLD | NEW |