Chromium Code Reviews| Index: chrome/common/extensions/docs/server2/owners_data_source_test.py |
| diff --git a/chrome/common/extensions/docs/server2/owners_data_source_test.py b/chrome/common/extensions/docs/server2/owners_data_source_test.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..353c80ad8a14dd42d8f9f1abfe71e6b9c1876b3c |
| --- /dev/null |
| +++ b/chrome/common/extensions/docs/server2/owners_data_source_test.py |
| @@ -0,0 +1,184 @@ |
| +#!/usr/bin/env python |
| +# Copyright 2014 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import unittest |
| + |
| +from extensions_paths import BROWSER_CHROME_EXTENSIONS |
| +from owners_data_source import _ParseOwnersFile, OwnersDataSource |
| +from server_instance import ServerInstance |
| +from servlet import Request |
| +from test_file_system import TestFileSystem |
| + |
| + |
| +_TEST_FS = { |
| + 'chrome': { |
| + 'browser': { |
| + 'extensions': { |
| + 'OWNERS': '\n'.join([ |
| + '# Core owners.', |
| + 'satsuki@revocs.tld' |
| + ]), |
| + 'api': { |
| + 'some_api': { |
| + 'OWNERS': '\n'.join([ |
| + 'matoi@owner.tld' |
| + ]), |
| + 'some_api.cc': '' |
| + }, |
| + 'another_api': { |
| + 'another_api.cc': '', |
| + 'another_api.h': '' |
| + }, |
| + 'moar_apis': { |
| + 'OWNERS': '\n'.join([ |
| + '# For editing moar_apis.', |
| + 'satsuki@revocs.tld' |
| + ]) |
| + } |
| + } |
| + } |
| + } |
| + }, |
| + 'extensions': { |
| + 'browser': { |
| + 'api': { |
| + 'a_different_api': { |
| + 'OWNERS': '\n'.join([ |
| + '# Hallo!', |
| + 'nonon@owner.tld', |
| + 'matoi@owner.tld' |
| + ]) |
| + } |
| + } |
| + } |
| + } |
| +} |
| + |
| + |
| +class OwnersDataSourceTest(unittest.TestCase): |
| + def setUp(self): |
| + server_instance = ServerInstance.ForTest( |
| + file_system=TestFileSystem(_TEST_FS)) |
| + # Don't randomize the owners to avoid testing issues. |
| + self._owners_ds= OwnersDataSource(server_instance, |
|
not at google - send to devlin
2014/08/21 21:39:58
' ' before the '='.
|
| + Request.ForTest('/'), |
| + randomize=False) |
| + |
| + def testParseOwnersFile(self): |
| + owners_content = '\n'.join([ |
| + 'satsuki@revocs.tld', |
| + 'mankanshoku@owner.tld', |
| + '', |
| + 'matoi@owner.tld' |
| + ]) |
| + 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
|
| + # The order of the owners list should reflect the order of the owners file. |
| + self.assertEqual(owners, [ |
| + { |
| + 'email': 'satsuki@revocs.tld', |
| + 'username': 'satsuki' |
| + }, |
| + { |
| + 'email': 'mankanshoku@owner.tld', |
| + 'username': 'mankanshoku' |
| + }, |
| + { |
| + 'email': 'matoi@owner.tld', |
| + 'username': 'matoi', |
| + 'last': True |
| + } |
| + ]) |
| + self.assertEqual(notes, '') |
| + |
| + owners_content_with_comments = '\n'.join([ |
| + '# This is a comment concerning this file', |
| + '# that should not be ignored.', |
| + 'matoi@owner.tld', |
| + 'mankanshoku@owner.tld', |
| + '', |
| + '# Only bug satsuki if matoi or mankanshoku are unavailable.', |
| + 'satsuki@revocs.tld' |
| + ]) |
| + owners, notes = _ParseOwnersFile(owners_content_with_comments, False) |
| + self.assertEqual(owners, [ |
| + { |
| + 'email': 'matoi@owner.tld', |
| + 'username': 'matoi' |
| + }, |
| + { |
| + 'email': 'mankanshoku@owner.tld', |
| + 'username': 'mankanshoku' |
| + }, |
| + { |
| + 'email': 'satsuki@revocs.tld', |
| + 'username': 'satsuki', |
| + 'last': True |
| + } |
| + ]) |
| + self.assertEqual(notes, '\n'.join([ |
| + 'This is a comment concerning this file', |
| + 'that should not be ignored.', |
| + 'Only bug satsuki if matoi or mankanshoku are unavailable.' |
| + ])) |
| + |
| + |
| + def testCollectOwners(self): |
| + # NOTE: Order matters. The list should be sorted by 'apiName'. |
| + self.assertEqual(self._owners_ds.get('apis'), [{ |
| + 'apiName': 'Core Extensions/Apps Owners', |
| + 'owners': [ |
| + { |
| + 'email': 'satsuki@revocs.tld', |
| + 'username': 'satsuki', |
| + 'last': True |
| + } |
| + ], |
| + 'notes': 'Core owners.' |
| + }, |
| + { |
| + 'apiName': 'a_different_api', |
| + 'owners': [ |
| + { |
| + 'email': 'nonon@owner.tld', |
| + 'username': 'nonon' |
| + }, |
| + { |
| + 'email': 'matoi@owner.tld', |
| + 'username': 'matoi', |
| + 'last': True |
| + } |
| + ], |
| + 'notes': 'Hallo!' |
| + }, |
| + { |
| + 'apiName': 'another_api', |
| + 'owners': [], |
| + 'notes': 'Use one of the Core Extensions/Apps Owners.' |
| + }, |
| + { |
| + 'apiName': 'moar_apis', |
| + 'owners': [ |
| + { |
| + 'email': 'satsuki@revocs.tld', |
| + 'username': 'satsuki', |
| + 'last': True |
| + } |
| + ], |
| + 'notes': 'For editing moar_apis.' |
| + }, |
| + { |
| + 'apiName': 'some_api', |
| + 'owners': [ |
| + { |
| + 'email': 'matoi@owner.tld', |
| + 'username': 'matoi', |
| + 'last': True |
| + } |
| + ], |
| + 'notes': '' |
| + }]) |
| + |
| +if __name__ == '__main__': |
| + unittest.main() |