Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(711)

Side by Side Diff: chrome/common/extensions/docs/server2/sidenav_data_source_test.py

Issue 575613003: Docserver: Gitiles auth and cron refactoring. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2013 The Chromium Authors. All rights reserved. 2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import json 6 import json
7 import unittest 7 import unittest
8 import copy 8 import copy
9 9
10 from extensions_paths import JSON_TEMPLATES 10 from extensions_paths import JSON_TEMPLATES
(...skipping 26 matching lines...) Expand all
37 }] 37 }]
38 38
39 _AddLevels(sidenav_json, 1) 39 _AddLevels(sidenav_json, 1)
40 self.assertEqual(expected, sidenav_json) 40 self.assertEqual(expected, sidenav_json)
41 41
42 def testAddAnnotations(self): 42 def testAddAnnotations(self):
43 item1 = { 'href': '/H1.html' } 43 item1 = { 'href': '/H1.html' }
44 item2_1 = { 'href': '/H2_1.html' } 44 item2_1 = { 'href': '/H2_1.html' }
45 item2_2 = { 'href': '/H2_2.html' } 45 item2_2 = { 'href': '/H2_2.html' }
46 item2 = { 'href': '/H2.html', 'items': [item2_1, item2_2] } 46 item2 = { 'href': '/H2.html', 'items': [item2_1, item2_2] }
47 47
48 expected = [ item1, item2 ] 48 expected = [ item1, item2 ]
49 49
50 sidenav_json = copy.deepcopy(expected) 50 sidenav_json = copy.deepcopy(expected)
51 51
52 item2['child_selected'] = True 52 item2['child_selected'] = True
53 item2_1['selected'] = True 53 item2_1['selected'] = True
54 item2_1['related'] = True 54 item2_1['related'] = True
55 item2_1['parent'] = { 'title': item2.get('title', None), 55 item2_1['parent'] = { 'title': item2.get('title', None),
56 'href': item2.get('href', None) } 56 'href': item2.get('href', None) }
57 57
58 item2_2['related'] = True 58 item2_2['related'] = True
59 59
60 self.assertTrue(_AddAnnotations(sidenav_json, item2_1['href'])) 60 self.assertTrue(_AddAnnotations(sidenav_json, item2_1['href']))
61 self.assertEqual(expected, sidenav_json) 61 self.assertEqual(expected, sidenav_json)
62 62
63 def testWithDifferentBasePath(self): 63 def testWithDifferentBasePath(self):
64 file_system = TestFileSystem({ 64 file_system = TestFileSystem({
65 'chrome_sidenav.json': json.dumps([ 65 'chrome_sidenav.json': json.dumps([
66 { 'href': '/H1.html' }, 66 { 'href': '/H1.html' },
67 { 'href': '/H2.html' }, 67 { 'href': '/H2.html' },
68 { 'href': '/base/path/H2.html' }, 68 { 'href': '/base/path/H2.html' },
69 { 'href': 'https://qualified/X1.html' }, 69 { 'href': 'https://qualified/X1.html' },
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 132
133 self.assertEqual(1, len(log_output)) 133 self.assertEqual(1, len(log_output))
134 self.assertTrue( 134 self.assertTrue(
135 log_output[0].msg.startswith('Paths in sidenav must be qualified.')) 135 log_output[0].msg.startswith('Paths in sidenav must be qualified.'))
136 136
137 # Test that only a single file is read when creating the sidenav, so that 137 # Test that only a single file is read when creating the sidenav, so that
138 # we can be confident in the compiled_file_system.SingleFile annotation. 138 # we can be confident in the compiled_file_system.SingleFile annotation.
139 self.assertTrue(*file_system.CheckAndReset( 139 self.assertTrue(*file_system.CheckAndReset(
140 read_count=1, stat_count=1, read_resolve_count=1)) 140 read_count=1, stat_count=1, read_resolve_count=1))
141 141
142 def testCron(self): 142 def testRefresh(self):
143 file_system = TestFileSystem({ 143 file_system = TestFileSystem({
144 'chrome_sidenav.json': '[{ "title": "H1" }]' 144 'chrome_sidenav.json': '[{ "title": "H1" }]'
145 }, relative_to=JSON_TEMPLATES) 145 }, relative_to=JSON_TEMPLATES)
146 146
147 # Ensure Cron doesn't rely on request. 147 # Ensure Refresh doesn't rely on request.
148 sidenav_data_source = SidenavDataSource( 148 sidenav_data_source = SidenavDataSource(
149 ServerInstance.ForTest(file_system), request=None) 149 ServerInstance.ForTest(file_system), request=None)
150 sidenav_data_source.Cron().Get() 150 sidenav_data_source.Refresh().Get()
151 151
152 # If Cron fails, chrome_sidenav.json will not be cached, and the cache_data 152 # If Refresh fails, chrome_sidenav.json will not be cached, and the
153 # access will fail. 153 # cache_data access will fail.
154 # TODO(jshumway): Make a non hack version of this check. 154 # TODO(jshumway): Make a non hack version of this check.
155 sidenav_data_source._cache._file_object_store.Get( 155 sidenav_data_source._cache._file_object_store.Get(
156 '%schrome_sidenav.json' % JSON_TEMPLATES).Get().cache_data 156 '%schrome_sidenav.json' % JSON_TEMPLATES).Get().cache_data
157 157
158 158
159 if __name__ == '__main__': 159 if __name__ == '__main__':
160 unittest.main() 160 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698