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 self._owners_ds= OwnersDataSource(server_instance, Request.ForTest('/')) |
| 65 |
| 66 def testParseOwnersFile(self): |
| 67 owners_content = '\n'.join([ |
| 68 'satsuki@revocs.tld', |
| 69 'mankanshoku@owner.tld', |
| 70 '', |
| 71 'matoi@owner.tld' |
| 72 ]) |
| 73 owners, notes = _ParseOwnersFile(owners_content) |
| 74 # The order of the owners list should reflect the order of the owners file. |
| 75 self.assertEqual(owners, [ |
| 76 { |
| 77 'email': 'satsuki@revocs.tld', |
| 78 'username': 'satsuki' |
| 79 }, |
| 80 { |
| 81 'email': 'mankanshoku@owner.tld', |
| 82 'username': 'mankanshoku' |
| 83 }, |
| 84 { |
| 85 'email': 'matoi@owner.tld', |
| 86 'username': 'matoi', |
| 87 'last': True |
| 88 } |
| 89 ]) |
| 90 self.assertEqual(notes, '') |
| 91 |
| 92 owners_content_with_comments = '\n'.join([ |
| 93 '# This is a comment concerning this file', |
| 94 '# that should not be ignored.', |
| 95 'matoi@owner.tld', |
| 96 'mankanshoku@owner.tld', |
| 97 '', |
| 98 '# Only bug satsuki if matoi or mankanshoku are unavailable.', |
| 99 'satsuki@revocs.tld' |
| 100 ]) |
| 101 owners, notes = _ParseOwnersFile(owners_content_with_comments) |
| 102 self.assertEqual(owners, [ |
| 103 { |
| 104 'email': 'matoi@owner.tld', |
| 105 'username': 'matoi' |
| 106 }, |
| 107 { |
| 108 'email': 'mankanshoku@owner.tld', |
| 109 'username': 'mankanshoku' |
| 110 }, |
| 111 { |
| 112 'email': 'satsuki@revocs.tld', |
| 113 'username': 'satsuki', |
| 114 'last': True |
| 115 } |
| 116 ]) |
| 117 self.assertEqual(notes, ' '.join([ |
| 118 'This is a comment concerning this file that should not be ignored.', |
| 119 'Only bug satsuki if matoi or mankanshoku are unavailable.' |
| 120 ])) |
| 121 |
| 122 |
| 123 def testCollectOwners(self): |
| 124 # NOTE: Order matters. The list should be sorted by 'apiName'. |
| 125 self.assertEqual(self._owners_ds.get('apis'), [{ |
| 126 'apiName': 'Core Extensions/Apps Owners', |
| 127 'owners': [ |
| 128 { |
| 129 'email': 'satsuki@revocs.tld', |
| 130 'username': 'satsuki', |
| 131 'last': True |
| 132 } |
| 133 ], |
| 134 'notes': 'Core owners.' |
| 135 }, |
| 136 { |
| 137 'apiName': 'a_different_api', |
| 138 'owners': [ |
| 139 { |
| 140 'email': 'nonon@owner.tld', |
| 141 'username': 'nonon' |
| 142 }, |
| 143 { |
| 144 'email': 'matoi@owner.tld', |
| 145 'username': 'matoi', |
| 146 'last': True |
| 147 } |
| 148 ], |
| 149 'notes': 'Hallo!' |
| 150 }, |
| 151 { |
| 152 'apiName': 'another_api', |
| 153 'owners': [], |
| 154 'notes': 'See core extensions owners.' |
| 155 }, |
| 156 { |
| 157 'apiName': 'moar_apis', |
| 158 'owners': [ |
| 159 { |
| 160 'email': 'satsuki@revocs.tld', |
| 161 'username': 'satsuki', |
| 162 'last': True |
| 163 } |
| 164 ], |
| 165 'notes': 'For editing moar_apis.' |
| 166 }, |
| 167 { |
| 168 'apiName': 'some_api', |
| 169 'owners': [ |
| 170 { |
| 171 'email': 'matoi@owner.tld', |
| 172 'username': 'matoi', |
| 173 'last': True |
| 174 } |
| 175 ], |
| 176 'notes': '' |
| 177 }]) |
| 178 |
| 179 if __name__ == '__main__': |
| 180 unittest.main() |
OLD | NEW |