OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright 2014 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 extensions_paths import BROWSER_CHROME_EXTENSIONS | |
9 from owners_data_source import _ParseOwnersFile, OwnersDataSource | |
10 from server_instance import ServerInstance | |
11 from servlet import Request | |
12 from test_file_system import TestFileSystem | |
13 | |
14 | |
15 _TEST_FS = { | |
16 'chrome': { | |
17 'browser': { | |
18 'extensions': { | |
19 'OWNERS': '\n'.join([ | |
20 '# Core owners.', | |
21 'satsuki@revocs.tld' | |
22 ]), | |
23 'api': { | |
24 'some_api': { | |
25 'OWNERS': '\n'.join([ | |
26 'matoi@owner.tld' | |
27 ]), | |
28 'some_api.cc': '' | |
29 }, | |
30 'another_api': { | |
31 'another_api.cc': '', | |
32 'another_api.h': '' | |
33 }, | |
34 'moar_apis': { | |
35 'OWNERS': '\n'.join([ | |
36 '# For editing moar_apis.', | |
37 'satsuki@revocs.tld' | |
38 ]) | |
39 } | |
40 } | |
41 } | |
42 } | |
43 }, | |
44 'extensions': { | |
45 'browser': { | |
46 'api': { | |
47 'a_different_api': { | |
48 'OWNERS': '\n'.join([ | |
49 '# Hallo!', | |
50 'nonon@owner.tld', | |
51 'matoi@owner.tld' | |
52 ]) | |
53 } | |
54 } | |
55 } | |
56 } | |
57 } | |
58 | |
59 | |
60 class OwnersDataSourceTest(unittest.TestCase): | |
61 def setUp(self): | |
62 server_instance = ServerInstance.ForTest( | |
63 file_system=TestFileSystem(_TEST_FS)) | |
64 # Don't randomize the owners to avoid testing issues. | |
65 self._owners_ds= OwnersDataSource(server_instance, | |
not at google - send to devlin
2014/08/21 21:39:58
' ' before the '='.
| |
66 Request.ForTest('/'), | |
67 randomize=False) | |
68 | |
69 def testParseOwnersFile(self): | |
70 owners_content = '\n'.join([ | |
71 'satsuki@revocs.tld', | |
72 'mankanshoku@owner.tld', | |
73 '', | |
74 'matoi@owner.tld' | |
75 ]) | |
76 owners, notes = _ParseOwnersFile(owners_content, False) | |
not at google - send to devlin
2014/08/21 21:39:58
Can you use a named parameter for False here (rand
| |
77 # The order of the owners list should reflect the order of the owners file. | |
78 self.assertEqual(owners, [ | |
79 { | |
80 'email': 'satsuki@revocs.tld', | |
81 'username': 'satsuki' | |
82 }, | |
83 { | |
84 'email': 'mankanshoku@owner.tld', | |
85 'username': 'mankanshoku' | |
86 }, | |
87 { | |
88 'email': 'matoi@owner.tld', | |
89 'username': 'matoi', | |
90 'last': True | |
91 } | |
92 ]) | |
93 self.assertEqual(notes, '') | |
94 | |
95 owners_content_with_comments = '\n'.join([ | |
96 '# This is a comment concerning this file', | |
97 '# that should not be ignored.', | |
98 'matoi@owner.tld', | |
99 'mankanshoku@owner.tld', | |
100 '', | |
101 '# Only bug satsuki if matoi or mankanshoku are unavailable.', | |
102 'satsuki@revocs.tld' | |
103 ]) | |
104 owners, notes = _ParseOwnersFile(owners_content_with_comments, False) | |
105 self.assertEqual(owners, [ | |
106 { | |
107 'email': 'matoi@owner.tld', | |
108 'username': 'matoi' | |
109 }, | |
110 { | |
111 'email': 'mankanshoku@owner.tld', | |
112 'username': 'mankanshoku' | |
113 }, | |
114 { | |
115 'email': 'satsuki@revocs.tld', | |
116 'username': 'satsuki', | |
117 'last': True | |
118 } | |
119 ]) | |
120 self.assertEqual(notes, '\n'.join([ | |
121 'This is a comment concerning this file', | |
122 'that should not be ignored.', | |
123 'Only bug satsuki if matoi or mankanshoku are unavailable.' | |
124 ])) | |
125 | |
126 | |
127 def testCollectOwners(self): | |
128 # NOTE: Order matters. The list should be sorted by 'apiName'. | |
129 self.assertEqual(self._owners_ds.get('apis'), [{ | |
130 'apiName': 'Core Extensions/Apps Owners', | |
131 'owners': [ | |
132 { | |
133 'email': 'satsuki@revocs.tld', | |
134 'username': 'satsuki', | |
135 'last': True | |
136 } | |
137 ], | |
138 'notes': 'Core owners.' | |
139 }, | |
140 { | |
141 'apiName': 'a_different_api', | |
142 'owners': [ | |
143 { | |
144 'email': 'nonon@owner.tld', | |
145 'username': 'nonon' | |
146 }, | |
147 { | |
148 'email': 'matoi@owner.tld', | |
149 'username': 'matoi', | |
150 'last': True | |
151 } | |
152 ], | |
153 'notes': 'Hallo!' | |
154 }, | |
155 { | |
156 'apiName': 'another_api', | |
157 'owners': [], | |
158 'notes': 'Use one of the Core Extensions/Apps Owners.' | |
159 }, | |
160 { | |
161 'apiName': 'moar_apis', | |
162 'owners': [ | |
163 { | |
164 'email': 'satsuki@revocs.tld', | |
165 'username': 'satsuki', | |
166 'last': True | |
167 } | |
168 ], | |
169 'notes': 'For editing moar_apis.' | |
170 }, | |
171 { | |
172 'apiName': 'some_api', | |
173 'owners': [ | |
174 { | |
175 'email': 'matoi@owner.tld', | |
176 'username': 'matoi', | |
177 'last': True | |
178 } | |
179 ], | |
180 'notes': '' | |
181 }]) | |
182 | |
183 if __name__ == '__main__': | |
184 unittest.main() | |
OLD | NEW |