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

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

Issue 16410002: Docserver manifest follow up (rewrite) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gen-manifest-try-2
Patch Set: more idiomatic/less explicit copying Created 7 years, 4 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
OLDNEW
(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 import unittest
7
8 from features_utility import Parse, Filtered, MergedWith
9
10 class FeaturesUtilityTest(unittest.TestCase):
11 def testFromJson(self):
12 raw_features_json = {
13 'doc1': {
14 'extension_types': ['extension', 'platform_app']
15 },
16 'doc2': {
17 'extension_types': ['hosted_app', 'packaged_app']
18 },
19 'doc3': {
20 'whitelist': 'hashhashashhashashhashashhash'
21 },
22 'doc4': [
23 { 'extension_types': 'all' },
24 { 'whitelist': 'hashhashashhashashhashashhash' }
25 ],
26 'doc5': {
27 'extension_types': ['extension']
28 },
29 'doc1.sub1': {
30 'extension_types': ['platform_app', 'hosted_app', 'packaged_app']
31 }
32 }
33
34 expected = {
35 'doc1': {
36 'platforms': ['app', 'extension'],
37 'name': 'doc1'
38 },
39 'doc2': {
40 'platforms': [],
41 'name': 'doc2'
42 },
43 'doc4': {
44 'platforms': ['app', 'extension'],
45 'name': 'doc4'
46 },
47 'doc5': {
48 'platforms': ['extension'],
49 'name': 'doc5'
50 },
51 'doc1.sub1': {
52 'platforms': ['app'],
53 'name': 'doc1.sub1'
54 }
55 }
56
57 self.assertEqual(expected, Parse(raw_features_json))
58
59 def testFilter(self):
60 unfiltered = {
61 'doc1': { 'platforms': ['app'] },
62 'doc2': { 'platforms': ['extension'] },
63 'doc3': { 'platforms': ['app', 'extension'] },
64 'doc4': { 'platforms': [] }
65 }
66
67 apps_names = set(('doc1', 'doc3'))
68 extension_names = set(('doc2', 'doc3'))
69
70 self.assertEqual(
71 apps_names, set(Filtered(unfiltered, 'app').keys()))
72 self.assertEqual(
73 extension_names, set(Filtered(unfiltered, 'extension').keys()))
74
75 def testMergeFeatures(self):
76 features = {
77 'doc1': {
78 'platforms': ['app']
79 },
80 'doc3': {
81 'name': 'doc3'
82 }
83 }
84
85 other = {
86 'doc1': {
87 'name': 'doc1',
88 'platforms': ['extension']
89 },
90 'doc2': {
91 'name': 'doc2'
92 },
93 'doc3': {
94 'platforms': ['extension', 'app']
95 }
96 }
97
98 expected = {
99 'doc1': {
100 'name': 'doc1',
101 'platforms': ['extension']
102 },
103 'doc2': {
104 'name': 'doc2'
105 },
106 'doc3': {
107 'name': 'doc3',
108 'platforms': ['extension', 'app']
109 }
110 }
111
112 self.assertEqual(expected, MergedWith(features, other))
113
114 if __name__ == '__main__':
115 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698