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.
8 from owners_data_source import ParseOwnersFile, OwnersDataSource
9 from server_instance import ServerInstance
10 from servlet import Request
11 from test_file_system import TestFileSystem
35 '# For editing moar_apis.',
59 class OwnersDataSourceTest(unittest.TestCase):
61 server_instance = ServerInstance.ForTest(
62 file_system=TestFileSystem(_TEST_FS))
63 # Don't randomize the owners to avoid testing issues.
64 self._owners_ds = OwnersDataSource(server_instance,
68 def testParseOwnersFile(self):
69 owners_content = '\n'.join([
71 'mankanshoku@owner.tld',
75 owners, notes = ParseOwnersFile(owners_content, randomize=False)
76 # The order of the owners list should reflect the order of the owners file.
77 self.assertEqual(owners, [
79 'email': 'satsuki@revocs.tld',
83 'email': 'mankanshoku@owner.tld',
84 'username': 'mankanshoku'
87 'email': 'matoi@owner.tld',
92 self.assertEqual(notes, '')
94 owners_content_with_comments = '\n'.join([
95 '# This is a comment concerning this file',
96 '# that should not be ignored.',
98 'mankanshoku@owner.tld',
100 '# Only bug satsuki if matoi or mankanshoku are unavailable.',
103 owners, notes = ParseOwnersFile(owners_content_with_comments,
105 self.assertEqual(owners, [
107 'email': 'matoi@owner.tld',
111 'email': 'mankanshoku@owner.tld',
112 'username': 'mankanshoku'
115 'email': 'satsuki@revocs.tld',
116 'username': 'satsuki',
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.'
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',
133 'email': 'satsuki@revocs.tld',
134 'username': 'satsuki',
138 'notes': 'Core owners.',
142 'apiName': 'a_different_api',
145 'email': 'nonon@owner.tld',
149 'email': 'matoi@owner.tld',
155 'id': 'a_different_api'
158 'apiName': 'another_api',
160 'notes': 'Use one of the Core Extensions/Apps Owners.',
164 'apiName': 'moar_apis',
167 'email': 'satsuki@revocs.tld',
168 'username': 'satsuki',
172 'notes': 'For editing moar_apis.',
176 'apiName': 'some_api',
179 'email': 'matoi@owner.tld',
188 if __name__ == '__main__':