OLD | NEW |
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 from itertools import groupby | 11 from itertools import groupby |
12 from operator import itemgetter | 12 from operator import itemgetter |
13 import optparse | 13 import optparse |
14 import os | 14 import os |
| 15 import posixpath |
15 import sys | 16 import sys |
16 import time | 17 import time |
17 import unittest | 18 import unittest |
18 | 19 |
| 20 from branch_utility import BranchUtility |
19 from link_error_detector import LinkErrorDetector | 21 from link_error_detector import LinkErrorDetector |
20 from local_file_system import LocalFileSystem | 22 from local_file_system import LocalFileSystem |
21 from local_renderer import LocalRenderer | 23 from local_renderer import LocalRenderer |
22 from fake_fetchers import ConfigureFakeFetchers | 24 from fake_fetchers import ConfigureFakeFetchers |
23 from handler import Handler | 25 from handler import Handler |
24 from servlet import Request | 26 from servlet import Request |
25 from test_util import EnableLogging, DisableLogging | 27 from test_util import EnableLogging, DisableLogging |
26 | 28 |
27 # Arguments set up if __main__ specifies them. | 29 # Arguments set up if __main__ specifies them. |
28 _EXPLICIT_TEST_FILES = None | 30 _EXPLICIT_TEST_FILES = None |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 for path, content in public_files.iteritems(): | 119 for path, content in public_files.iteritems(): |
118 if path.endswith('redirects.json'): | 120 if path.endswith('redirects.json'): |
119 continue | 121 continue |
120 def check_result(response): | 122 def check_result(response): |
121 self.assertEqual(200, response.status, | 123 self.assertEqual(200, response.status, |
122 'Got %s when rendering %s' % (response.status, path)) | 124 'Got %s when rendering %s' % (response.status, path)) |
123 # This is reaaaaally rough since usually these will be tiny templates | 125 # This is reaaaaally rough since usually these will be tiny templates |
124 # that render large files. At least it'll catch zero-length responses. | 126 # that render large files. At least it'll catch zero-length responses. |
125 self.assertTrue(len(response.content) >= len(content), | 127 self.assertTrue(len(response.content) >= len(content), |
126 'Content was "%s" when rendering %s' % (response.content, path)) | 128 'Content was "%s" when rendering %s' % (response.content, path)) |
| 129 |
127 check_result(Handler(Request.ForTest(path)).Get()) | 130 check_result(Handler(Request.ForTest(path)).Get()) |
| 131 |
| 132 # Make sure that leaving out the .html will temporarily redirect to the |
| 133 # path with the .html. |
| 134 if path != '/404.html': |
| 135 redirect_result = Handler( |
| 136 Request.ForTest(posixpath.splitext(path)[0])).Get() |
| 137 self.assertEqual((path, False), redirect_result.GetRedirect()) |
| 138 |
| 139 # Make sure including a channel will permanently redirect to the same |
| 140 # path without a channel. |
| 141 for channel in BranchUtility.GetAllChannelNames(): |
| 142 redirect_result = Handler( |
| 143 Request.ForTest('%s/%s' % (channel, path))).Get() |
| 144 self.assertEqual((path, True), redirect_result.GetRedirect()) |
| 145 |
128 # Samples are internationalized, test some locales. | 146 # Samples are internationalized, test some locales. |
129 if path.endswith('/samples.html'): | 147 if path.endswith('/samples.html'): |
130 for lang in ['en-US', 'es', 'ar']: | 148 for lang in ['en-US', 'es', 'ar']: |
131 check_result(Handler(Request.ForTest( | 149 check_result(Handler(Request.ForTest( |
132 path, | 150 path, |
133 headers={'Accept-Language': '%s;q=0.8' % lang})).Get()) | 151 headers={'Accept-Language': '%s;q=0.8' % lang})).Get()) |
134 finally: | 152 finally: |
135 print('Took %s seconds' % (time.time() - start_time)) | 153 print('Took %s seconds' % (time.time() - start_time)) |
136 | 154 |
137 # TODO(kalman): Move this test elsewhere, it's not an integration test. | 155 # TODO(kalman): Move this test elsewhere, it's not an integration test. |
(...skipping 23 matching lines...) Expand all Loading... |
161 | 179 |
162 if __name__ == '__main__': | 180 if __name__ == '__main__': |
163 parser = optparse.OptionParser() | 181 parser = optparse.OptionParser() |
164 parser.add_option('-a', '--all', action='store_true', default=False) | 182 parser.add_option('-a', '--all', action='store_true', default=False) |
165 (opts, args) = parser.parse_args() | 183 (opts, args) = parser.parse_args() |
166 if not opts.all: | 184 if not opts.all: |
167 _EXPLICIT_TEST_FILES = args | 185 _EXPLICIT_TEST_FILES = args |
168 # Kill sys.argv because we have our own flags. | 186 # Kill sys.argv because we have our own flags. |
169 sys.argv = [sys.argv[0]] | 187 sys.argv = [sys.argv[0]] |
170 unittest.main() | 188 unittest.main() |
OLD | NEW |