OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 import unittest |
| 3 |
| 4 from extensions_paths import BROWSER_CHROME_EXTENSIONS |
| 5 from owners_data_source import _ParseOwnersFile, OwnersDataSource |
| 6 from server_instance import ServerInstance |
| 7 from servlet import Request |
| 8 from test_file_system import TestFileSystem |
| 9 |
| 10 |
| 11 _TEST_FS = { |
| 12 'chrome': { |
| 13 'browser': { |
| 14 'extensions': { |
| 15 'api': { |
| 16 'some_api': { |
| 17 'OWNERS': '\n'.join([ |
| 18 'matoi@owner.org' |
| 19 ]), |
| 20 'some_api.cc': '' |
| 21 }, |
| 22 'another_api': { |
| 23 'another_api.cc': '', |
| 24 'another_api.h': '' |
| 25 }, |
| 26 'moar_apis': { |
| 27 'OWNERS': '\n'.join([ |
| 28 '# For editing moar_apis.', |
| 29 'satsuki@revocs.org' |
| 30 ]) |
| 31 } |
| 32 } |
| 33 } |
| 34 } |
| 35 }, |
| 36 'extensions': { |
| 37 'browser': { |
| 38 'api': { |
| 39 'a_different_api': { |
| 40 'OWNERS': '\n'.join([ |
| 41 '# Hallo!', |
| 42 'nonon@owner.org', |
| 43 'matoi@owner.org' |
| 44 ]) |
| 45 } |
| 46 } |
| 47 } |
| 48 } |
| 49 } |
| 50 |
| 51 |
| 52 class OwnersDataSourceTest(unittest.TestCase): |
| 53 def setUp(self): |
| 54 server_instance = ServerInstance.ForTest( |
| 55 file_system=TestFileSystem(_TEST_FS)) |
| 56 self._owners_ds= OwnersDataSource(server_instance, Request.ForTest('/')) |
| 57 |
| 58 def testParseOwnersFile(self): |
| 59 owners_content = '\n'.join([ |
| 60 'satsuki@revocs.org', |
| 61 'mankanshoku@owner.org', |
| 62 '', |
| 63 'matoi@owner.org' |
| 64 ]) |
| 65 owners, notes = _ParseOwnersFile(owners_content) |
| 66 self.assertEqual(owners, [ |
| 67 'satsuki@revocs.org', |
| 68 'mankanshoku@owner.org', |
| 69 'matoi@owner.org' |
| 70 ]) |
| 71 self.assertEqual(notes, '') |
| 72 |
| 73 owners_content_with_comments = '\n'.join([ |
| 74 '# This is a comment concerning this file', |
| 75 '# that should not be ignored.', |
| 76 'matoi@owner.org', |
| 77 'mankanshoku@owner.org', |
| 78 '', |
| 79 '# Only bug satsuki if matoi or mankanshoku are unavailable.', |
| 80 'satsuki@revocs.org' |
| 81 ]) |
| 82 owners, notes = _ParseOwnersFile(owners_content_with_comments) |
| 83 self.assertEqual(owners, [ |
| 84 'matoi@owner.org', |
| 85 'mankanshoku@owner.org', |
| 86 'satsuki@revocs.org' |
| 87 ]) |
| 88 self.assertEqual(notes, ' '.join([ |
| 89 'This is a comment concerning this file that should not be ignored.', |
| 90 'Only bug satsuki if matoi or mankanshoku are unavailable.' |
| 91 ])) |
| 92 |
| 93 |
| 94 def testCollectOwners(self): |
| 95 self.assertEqual(self._owners_ds.get('apis'), [{ |
| 96 'api_name': 'some_api', |
| 97 'owners': 'matoi@owner.org', |
| 98 'notes': '' |
| 99 }, |
| 100 { |
| 101 'api_name': 'moar_apis', |
| 102 'owners': 'satsuki@revocs.org', |
| 103 'notes': 'For editing moar_apis.' |
| 104 }, |
| 105 { |
| 106 'api_name': 'a_different_api', |
| 107 'owners': 'nonon@owner.org, matoi@owner.org', |
| 108 'notes': 'Hallo!' |
| 109 }]) |
| 110 |
| 111 if __name__ == '__main__': |
| 112 unittest.main() |
OLD | NEW |