Adding the orphaned options pages to the navigation
[chromium-blink-merge.git] / chrome / common / extensions / docs / server2 / owners_data_source_test.py
blob64f695251644a27285e822f3f73eec5218e7f70f
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.
6 import unittest
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
14 _TEST_FS = {
15 'chrome': {
16 'browser': {
17 'extensions': {
18 'OWNERS': '\n'.join([
19 '# Core owners.',
20 'satsuki@revocs.tld'
21 ]),
22 'api': {
23 'some_api': {
24 'OWNERS': '\n'.join([
25 'matoi@owner.tld'
26 ]),
27 'some_api.cc': ''
29 'another_api': {
30 'another_api.cc': '',
31 'another_api.h': ''
33 'moar_apis': {
34 'OWNERS': '\n'.join([
35 '# For editing moar_apis.',
36 'satsuki@revocs.tld'
43 'extensions': {
44 'browser': {
45 'api': {
46 'a_different_api': {
47 'OWNERS': '\n'.join([
48 '# Hallo!',
49 'nonon@owner.tld',
50 'matoi@owner.tld'
59 class OwnersDataSourceTest(unittest.TestCase):
60 def setUp(self):
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,
65 Request.ForTest('/'),
66 randomize=False)
68 def testParseOwnersFile(self):
69 owners_content = '\n'.join([
70 'satsuki@revocs.tld',
71 'mankanshoku@owner.tld',
72 '',
73 'matoi@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',
80 'username': 'satsuki'
83 'email': 'mankanshoku@owner.tld',
84 'username': 'mankanshoku'
87 'email': 'matoi@owner.tld',
88 'username': 'matoi',
89 'last': True
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.',
97 'matoi@owner.tld',
98 'mankanshoku@owner.tld',
99 '',
100 '# Only bug satsuki if matoi or mankanshoku are unavailable.',
101 'satsuki@revocs.tld'
103 owners, notes = ParseOwnersFile(owners_content_with_comments,
104 randomize=False)
105 self.assertEqual(owners, [
107 'email': 'matoi@owner.tld',
108 'username': 'matoi'
111 'email': 'mankanshoku@owner.tld',
112 'username': 'mankanshoku'
115 'email': 'satsuki@revocs.tld',
116 'username': 'satsuki',
117 'last': True
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',
131 'owners': [
133 'email': 'satsuki@revocs.tld',
134 'username': 'satsuki',
135 'last': True
138 'notes': 'Core owners.',
139 'id': 'core'
142 'apiName': 'a_different_api',
143 'owners': [
145 'email': 'nonon@owner.tld',
146 'username': 'nonon'
149 'email': 'matoi@owner.tld',
150 'username': 'matoi',
151 'last': True
154 'notes': 'Hallo!',
155 'id': 'a_different_api'
158 'apiName': 'another_api',
159 'owners': [],
160 'notes': 'Use one of the Core Extensions/Apps Owners.',
161 'id': 'another_api'
164 'apiName': 'moar_apis',
165 'owners': [
167 'email': 'satsuki@revocs.tld',
168 'username': 'satsuki',
169 'last': True
172 'notes': 'For editing moar_apis.',
173 'id': 'moar_apis'
176 'apiName': 'some_api',
177 'owners': [
179 'email': 'matoi@owner.tld',
180 'username': 'matoi',
181 'last': True
184 'notes': '',
185 'id': 'some_api'
188 if __name__ == '__main__':
189 unittest.main()