OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 logging | 6 import logging |
7 import optparse | 7 import optparse |
8 import os | 8 import os |
9 import sys | 9 import sys |
10 from StringIO import StringIO | 10 from StringIO import StringIO |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 self.url = 'http://localhost' + path | 42 self.url = 'http://localhost' + path |
43 | 43 |
44 class IntegrationTest(unittest.TestCase): | 44 class IntegrationTest(unittest.TestCase): |
45 def _TestSamplesLocales(self, sample_path, failures): | 45 def _TestSamplesLocales(self, sample_path, failures): |
46 # Use US English, Spanish, and Arabic. | 46 # Use US English, Spanish, and Arabic. |
47 for lang in ['en-US', 'es', 'ar']: | 47 for lang in ['en-US', 'es', 'ar']: |
48 request = _MockRequest(sample_path) | 48 request = _MockRequest(sample_path) |
49 request.headers['Accept-Language'] = lang + ';q=0.8' | 49 request.headers['Accept-Language'] = lang + ';q=0.8' |
50 response = _MockResponse() | 50 response = _MockResponse() |
51 try: | 51 try: |
52 Handler(request, response, local_path=BASE_PATH).get() | 52 Handler(request, response).get() |
53 if 200 != response.status: | 53 if 200 != response.status: |
54 failures.append( | 54 failures.append( |
55 'Samples page with language %s does not have 200 status.' | 55 'Samples page with language %s does not have 200 status.' |
56 ' Status was %d.' % (lang, response.status)) | 56 ' Status was %d.' % (lang, response.status)) |
57 if not response.out.getvalue(): | 57 if not response.out.getvalue(): |
58 failures.append( | 58 failures.append( |
59 'Rendering samples page with language %s produced no output.' % | 59 'Rendering samples page with language %s produced no output.' % |
60 lang) | 60 lang) |
61 except Exception as e: | 61 except Exception as e: |
62 failures.append('Error rendering samples page with language %s: %s' % | 62 failures.append('Error rendering samples page with language %s: %s' % |
(...skipping 12 matching lines...) Expand all Loading... |
75 continue | 75 continue |
76 test_files.append(os.path.join(path, name)[len(base_path + os.sep):]) | 76 test_files.append(os.path.join(path, name)[len(base_path + os.sep):]) |
77 else: | 77 else: |
78 test_files = EXPLICIT_TEST_FILES | 78 test_files = EXPLICIT_TEST_FILES |
79 test_files = [f.replace(os.sep, '/') for f in test_files] | 79 test_files = [f.replace(os.sep, '/') for f in test_files] |
80 failures = [] | 80 failures = [] |
81 for filename in test_files: | 81 for filename in test_files: |
82 request = _MockRequest(filename) | 82 request = _MockRequest(filename) |
83 response = _MockResponse() | 83 response = _MockResponse() |
84 try: | 84 try: |
85 Handler(request, response, local_path=BASE_PATH).get() | 85 Handler(request, response).get() |
86 if 200 != response.status: | 86 if 200 != response.status: |
87 failures.append('%s does not have 200 status. Status was %d.' % | 87 failures.append('%s does not have 200 status. Status was %d.' % |
88 (filename, response.status)) | 88 (filename, response.status)) |
89 if not response.out.getvalue(): | 89 if not response.out.getvalue(): |
90 failures.append('Rendering %s produced no output.' % filename) | 90 failures.append('Rendering %s produced no output.' % filename) |
91 if filename.endswith('samples.html'): | 91 if filename.endswith('samples.html'): |
92 self._TestSamplesLocales(filename, failures) | 92 self._TestSamplesLocales(filename, failures) |
93 except Exception as e: | 93 except Exception as e: |
94 failures.append('Error rendering %s: %s' % (filename, e)) | 94 failures.append('Error rendering %s: %s' % (filename, e)) |
95 if failures: | 95 if failures: |
96 self.fail('\n'.join(failures)) | 96 self.fail('\n'.join(failures)) |
97 | 97 |
98 def testAllPublicTemplates(self): | 98 def testAllPublicTemplates(self): |
99 logging.getLogger().setLevel(logging.ERROR) | 99 logging.getLogger().setLevel(logging.ERROR) |
100 logging_error = logging.error | 100 logging_error = logging.error |
101 try: | 101 try: |
102 logging.error = self.fail | 102 logging.error = self.fail |
103 self._RunPublicTemplatesTest() | 103 self._RunPublicTemplatesTest() |
104 finally: | 104 finally: |
105 logging.error = logging_error | 105 logging.error = logging_error |
106 | 106 |
107 def testNonexistentFile(self): | 107 def testNonexistentFile(self): |
108 logging.getLogger().setLevel(logging.CRITICAL) | 108 logging.getLogger().setLevel(logging.CRITICAL) |
109 request = _MockRequest('extensions/junk.html') | 109 request = _MockRequest('extensions/junk.html') |
110 bad_response = _MockResponse() | 110 bad_response = _MockResponse() |
111 Handler(request, bad_response, local_path=BASE_PATH).get() | 111 Handler(request, bad_response).get() |
112 self.assertEqual(404, bad_response.status) | 112 self.assertEqual(404, bad_response.status) |
113 request_404 = _MockRequest('404.html') | 113 request_404 = _MockRequest('404.html') |
114 response_404 = _MockResponse() | 114 response_404 = _MockResponse() |
115 Handler(request_404, response_404, local_path=BASE_PATH).get() | 115 Handler(request_404, response_404).get() |
116 self.assertEqual(200, response_404.status) | 116 self.assertEqual(200, response_404.status) |
117 self.assertEqual(response_404.out.getvalue(), bad_response.out.getvalue()) | 117 self.assertEqual(response_404.out.getvalue(), bad_response.out.getvalue()) |
118 | 118 |
119 def testCron(self): | 119 def testCron(self): |
120 if EXPLICIT_TEST_FILES is not None: | 120 if EXPLICIT_TEST_FILES is not None: |
121 return | 121 return |
122 logging_error = logging.error | 122 logging_error = logging.error |
123 try: | 123 try: |
124 logging.error = self.fail | 124 logging.error = self.fail |
125 request = _MockRequest('/cron/trunk') | 125 request = _MockRequest('/cron/trunk') |
126 response = _MockResponse() | 126 response = _MockResponse() |
127 Handler(request, response, local_path=BASE_PATH).get() | 127 Handler(request, response).get() |
128 self.assertEqual(200, response.status) | 128 self.assertEqual(200, response.status) |
129 self.assertEqual('Success', response.out.getvalue()) | 129 self.assertEqual('Success', response.out.getvalue()) |
130 finally: | 130 finally: |
131 logging.error = logging_error | 131 logging.error = logging_error |
132 | 132 |
133 if __name__ == '__main__': | 133 if __name__ == '__main__': |
134 parser = optparse.OptionParser() | 134 parser = optparse.OptionParser() |
135 parser.add_option('-p', | 135 parser.add_option('-p', |
136 '--path', | 136 '--path', |
137 default=os.path.join( | 137 default=os.path.join( |
(...skipping 18 matching lines...) Expand all Loading... |
156 suite.run(result) | 156 suite.run(result) |
157 if result.failures: | 157 if result.failures: |
158 print('*----------------------------------*') | 158 print('*----------------------------------*') |
159 print('| integration_test.py has failures |') | 159 print('| integration_test.py has failures |') |
160 print('*----------------------------------*') | 160 print('*----------------------------------*') |
161 for test, failure in result.failures: | 161 for test, failure in result.failures: |
162 print(test) | 162 print(test) |
163 print(failure) | 163 print(failure) |
164 exit(1) | 164 exit(1) |
165 exit(0) | 165 exit(0) |
OLD | NEW |