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

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

Issue 17816005: Doc server broken link detection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: patch rewrite Created 7 years, 5 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 # Run build_server so that files needed by tests are copied to the local 6 # Run build_server so that files needed by tests are copied to the local
7 # third_party directory. 7 # third_party directory.
8 import build_server 8 import build_server
9 build_server.main() 9 build_server.main()
10 10
11 import logging
12 import optparse 11 import optparse
13 import os 12 import os
14 import sys 13 import sys
15 import time 14 import time
16 import unittest 15 import unittest
17 16
17 from link_error_detector import LinkErrorDetector, pprint_broken_links
18 from local_file_system import LocalFileSystem
18 from local_renderer import LocalRenderer 19 from local_renderer import LocalRenderer
19 from fake_fetchers import ConfigureFakeFetchers 20 from fake_fetchers import ConfigureFakeFetchers
20 from handler import Handler 21 from handler import Handler
21 from servlet import Request 22 from servlet import Request
22 from test_util import EnableLogging, DisableLogging 23 from test_util import EnableLogging, DisableLogging
23 24
24 # Arguments set up if __main__ specifies them. 25 # Arguments set up if __main__ specifies them.
25 _EXPLICIT_TEST_FILES = None 26 _EXPLICIT_TEST_FILES = None
26 27
27 def _ToPosixPath(os_path): 28 def _ToPosixPath(os_path):
(...skipping 26 matching lines...) Expand all
54 55
55 print('Running cron...') 56 print('Running cron...')
56 start_time = time.time() 57 start_time = time.time()
57 try: 58 try:
58 response = Handler(Request.ForTest('/_cron/stable')).Get() 59 response = Handler(Request.ForTest('/_cron/stable')).Get()
59 self.assertEqual(200, response.status) 60 self.assertEqual(200, response.status)
60 self.assertEqual('Success', response.content.ToString()) 61 self.assertEqual('Success', response.content.ToString())
61 finally: 62 finally:
62 print('Took %s seconds' % (time.time() - start_time)) 63 print('Took %s seconds' % (time.time() - start_time))
63 64
65 print "checking for broken links..."
not at google - send to devlin 2013/07/09 00:17:32 print(..) not print ..., print without () is depre
jshumway 2013/07/17 00:49:55 Done.
66 def renderer(path):
67 return Handler(Request.ForTest(path)).Get()
68
69 start_time = time.time()
70 link_error_detector = LinkErrorDetector(
71 LocalFileSystem(os.path.join(sys.path[0], os.pardir, os.pardir)),
72 renderer,
not at google - send to devlin 2013/07/09 00:17:32 maybe make this a lambda?
jshumway 2013/07/17 00:49:55 Done.
73 'templates/public',
74 ('extensions/index.html', 'apps/about_apps.html'))
75
76 broken_links = link_error_detector.GetBrokenLinks()
77 if broken_links:
78 pprint_broken_links(broken_links)
79
80 print 'finding %d broken links took %s seconds' % (
not at google - send to devlin 2013/07/09 00:17:32 likewise, and here Took %s seconds.
jshumway 2013/07/17 00:49:55 Done.
81 len(broken_links), time.time() - start_time)
82
83 print 'searching for orphan pages...'
not at google - send to devlin 2013/07/09 00:17:32 likewise here and below.
jshumway 2013/07/17 00:49:55 Done.
84 start_time = time.time()
85 orphans = link_error_detector.GetOrphanPages()
86 for page in orphans:
87 print page
not at google - send to devlin 2013/07/09 00:17:32 I think we can do a better job of being informativ
jshumway 2013/07/17 00:49:55 Done.
88 print 'finding %d orphan pages took %s seconds' % (
89 len(orphans), time.time() - start_time)
90
64 public_files = _GetPublicFiles() 91 public_files = _GetPublicFiles()
65 92
66 print('Rendering %s public files...' % len(public_files.keys())) 93 print('Rendering %s public files...' % len(public_files.keys()))
67 start_time = time.time() 94 start_time = time.time()
68 try: 95 try:
69 for path, content in public_files.iteritems(): 96 for path, content in public_files.iteritems():
70 if path.endswith('redirects.json'): 97 if path.endswith('redirects.json'):
71 continue 98 continue
72 def check_result(response): 99 def check_result(response):
73 self.assertEqual(200, response.status, 100 self.assertEqual(200, response.status,
(...skipping 20 matching lines...) Expand all
94 if _EXPLICIT_TEST_FILES is None: 121 if _EXPLICIT_TEST_FILES is None:
95 return 122 return
96 for filename in _EXPLICIT_TEST_FILES: 123 for filename in _EXPLICIT_TEST_FILES:
97 print('Rendering %s...' % filename) 124 print('Rendering %s...' % filename)
98 start_time = time.time() 125 start_time = time.time()
99 try: 126 try:
100 response = LocalRenderer.Render(_ToPosixPath(filename)) 127 response = LocalRenderer.Render(_ToPosixPath(filename))
101 self.assertEqual(200, response.status) 128 self.assertEqual(200, response.status)
102 self.assertTrue(response.content != '') 129 self.assertTrue(response.content != '')
103 finally: 130 finally:
104 print('Took %s seconds' % (time.time() - start_time)) 131 print('Took %s seconds' % (time.time() - start_time))
not at google - send to devlin 2013/07/09 00:17:32 like I mentioned - can we make the test run here t
jshumway 2013/07/17 00:49:55 I built out this functionality then discovered tha
105 132
106 @DisableLogging('warning') 133 @DisableLogging('warning')
107 def testFileNotFound(self): 134 def testFileNotFound(self):
108 response = Handler(Request.ForTest('/extensions/notfound.html')).Get() 135 response = Handler(Request.ForTest('/extensions/notfound.html')).Get()
109 self.assertEqual(404, response.status) 136 self.assertEqual(404, response.status)
110 137
111 if __name__ == '__main__': 138 if __name__ == '__main__':
112 parser = optparse.OptionParser() 139 parser = optparse.OptionParser()
113 parser.add_option('-a', '--all', action='store_true', default=False) 140 parser.add_option('-a', '--all', action='store_true', default=False)
114 (opts, args) = parser.parse_args() 141 (opts, args) = parser.parse_args()
115 if not opts.all: 142 if not opts.all:
116 _EXPLICIT_TEST_FILES = args 143 _EXPLICIT_TEST_FILES = args
117 # Kill sys.argv because we have our own flags. 144 # Kill sys.argv because we have our own flags.
118 sys.argv = [sys.argv[0]] 145 sys.argv = [sys.argv[0]]
119 unittest.main() 146 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698