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..ad0a3c3f84a20e1583b760952e85b840aff93500 |
--- /dev/null |
+++ b/chrome/common/extensions/docs/server2/owners_data_source_test.py |
@@ -0,0 +1,112 @@ |
+#!/usr/bin/env python |
+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': { |
+ 'api': { |
+ 'some_api': { |
+ 'OWNERS': '\n'.join([ |
+ 'matoi@owner.org' |
+ ]), |
+ 'some_api.cc': '' |
+ }, |
+ 'another_api': { |
+ 'another_api.cc': '', |
+ 'another_api.h': '' |
+ }, |
+ 'moar_apis': { |
+ 'OWNERS': '\n'.join([ |
+ '# For editing moar_apis.', |
+ 'satsuki@revocs.org' |
+ ]) |
+ } |
+ } |
+ } |
+ } |
+ }, |
+ 'extensions': { |
+ 'browser': { |
+ 'api': { |
+ 'a_different_api': { |
+ 'OWNERS': '\n'.join([ |
+ '# Hallo!', |
+ 'nonon@owner.org', |
+ 'matoi@owner.org' |
+ ]) |
+ } |
+ } |
+ } |
+ } |
+} |
+ |
+ |
+class OwnersDataSourceTest(unittest.TestCase): |
+ def setUp(self): |
+ server_instance = ServerInstance.ForTest( |
+ file_system=TestFileSystem(_TEST_FS)) |
+ self._owners_ds= OwnersDataSource(server_instance, Request.ForTest('/')) |
+ |
+ def testParseOwnersFile(self): |
+ owners_content = '\n'.join([ |
+ 'satsuki@revocs.org', |
+ 'mankanshoku@owner.org', |
+ '', |
+ 'matoi@owner.org' |
+ ]) |
+ owners, notes = _ParseOwnersFile(owners_content) |
+ self.assertEqual(owners, [ |
+ 'satsuki@revocs.org', |
+ 'mankanshoku@owner.org', |
+ 'matoi@owner.org' |
+ ]) |
+ self.assertEqual(notes, '') |
+ |
+ owners_content_with_comments = '\n'.join([ |
+ '# This is a comment concerning this file', |
+ '# that should not be ignored.', |
+ 'matoi@owner.org', |
+ 'mankanshoku@owner.org', |
+ '', |
+ '# Only bug satsuki if matoi or mankanshoku are unavailable.', |
+ 'satsuki@revocs.org' |
+ ]) |
+ owners, notes = _ParseOwnersFile(owners_content_with_comments) |
+ self.assertEqual(owners, [ |
+ 'matoi@owner.org', |
+ 'mankanshoku@owner.org', |
+ 'satsuki@revocs.org' |
+ ]) |
+ self.assertEqual(notes, ' '.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): |
+ self.assertEqual(self._owners_ds.get('apis'), [{ |
+ 'api_name': 'some_api', |
+ 'owners': 'matoi@owner.org', |
+ 'notes': '' |
+ }, |
+ { |
+ 'api_name': 'moar_apis', |
+ 'owners': 'satsuki@revocs.org', |
+ 'notes': 'For editing moar_apis.' |
+ }, |
+ { |
+ 'api_name': 'a_different_api', |
+ 'owners': 'nonon@owner.org, matoi@owner.org', |
+ 'notes': 'Hallo!' |
+ }]) |
+ |
+if __name__ == '__main__': |
+ unittest.main() |