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 os | 7 import os |
7 from StringIO import StringIO | 8 from StringIO import StringIO |
8 import unittest | 9 import unittest |
9 | 10 |
10 import appengine_memcache as memcache | 11 import appengine_memcache as memcache |
11 import handler | 12 import handler |
12 from handler import Handler | 13 from handler import Handler |
| 14 import url_constants |
13 | 15 |
14 KNOWN_FAILURES = [ | 16 KNOWN_FAILURES = [ |
| 17 # Apps samples fails because it requires fetching data from github.com. |
| 18 'apps/samples.html', |
15 # Exception in schema compiler (model.py). See http://crbug.com/141279. | 19 # Exception in schema compiler (model.py). See http://crbug.com/141279. |
16 'app.html', | 20 'apps/app.html' |
17 ] | 21 ] |
18 | 22 |
19 class _MockResponse(object): | 23 class _MockResponse(object): |
20 def __init__(self): | 24 def __init__(self): |
21 self.status = 200 | 25 self.status = 200 |
22 self.out = StringIO() | 26 self.out = StringIO() |
23 | 27 |
24 def set_status(self, status): | 28 def set_status(self, status): |
25 self.status = status | 29 self.status = status |
26 | 30 |
27 class _MockRequest(object): | 31 class _MockRequest(object): |
28 def __init__(self, path): | 32 def __init__(self, path): |
29 self.headers = {} | 33 self.headers = {} |
30 self.path = path | 34 self.path = path |
31 | 35 |
32 class IntegrationTest(unittest.TestCase): | 36 class IntegrationTest(unittest.TestCase): |
33 def testAll(self): | 37 def testAll(self): |
| 38 logging.getLogger().setLevel(logging.ERROR) |
34 base_path = os.path.join('templates', 'public') | 39 base_path = os.path.join('templates', 'public') |
35 for path, dirs, files in os.walk(base_path): | 40 for path, dirs, files in os.walk(base_path): |
36 for name in files: | 41 for name in files: |
37 filename = os.path.join(path, name) | 42 filename = os.path.join(path, name) |
38 if name in KNOWN_FAILURES or '.' in path or name.startswith('.'): | 43 if (filename.split('/', 2)[-1] in KNOWN_FAILURES or |
| 44 '.' in path or |
| 45 name.startswith('.')): |
39 continue | 46 continue |
40 request = _MockRequest(filename.split('/', 2)[-1]) | 47 request = _MockRequest(filename.split('/', 2)[-1]) |
41 response = _MockResponse() | 48 response = _MockResponse() |
42 Handler(request, response, local_path='../..').get() | 49 Handler(request, response, local_path='../..').get() |
43 self.assertEqual(200, response.status) | 50 self.assertEqual(200, response.status) |
44 self.assertTrue(response.out.getvalue()) | 51 self.assertTrue(response.out.getvalue()) |
45 | 52 |
46 def test404(self): | 53 def test404(self): |
47 request = _MockRequest('junk.html') | 54 request = _MockRequest('junk.html') |
48 bad_response = _MockResponse() | 55 bad_response = _MockResponse() |
49 Handler(request, bad_response, local_path='../..').get() | 56 Handler(request, bad_response, local_path='../..').get() |
50 self.assertEqual(404, bad_response.status) | 57 self.assertEqual(404, bad_response.status) |
51 self.assertTrue(bad_response.out.getvalue()) | 58 self.assertTrue(bad_response.out.getvalue()) |
52 | 59 |
53 def testLocales(self): | 60 def testLocales(self): |
54 # Use US English, Spanish, and Arabic. | 61 # Use US English, Spanish, and Arabic. |
55 for lang in ['en-US', 'es', 'ar']: | 62 for lang in ['en-US', 'es', 'ar']: |
56 request = _MockRequest('extensions/samples.html') | 63 request = _MockRequest('extensions/samples.html') |
57 request.headers['Accept-Language'] = lang + ';q=0.8' | 64 request.headers['Accept-Language'] = lang + ';q=0.8' |
58 response = _MockResponse() | 65 response = _MockResponse() |
59 Handler(request, response, local_path='../..').get() | 66 Handler(request, response, local_path='../..').get() |
60 self.assertEqual(200, response.status) | 67 self.assertEqual(200, response.status) |
61 self.assertTrue(response.out.getvalue()) | 68 self.assertTrue(response.out.getvalue()) |
62 | 69 |
63 def testWarmupRequest(self): | 70 def testWarmupRequest(self): |
64 for branch in ['dev', 'trunk', 'beta', 'stable']: | 71 for branch in ['dev', 'trunk', 'beta', 'stable']: |
65 handler.BRANCH_UTILITY_MEMCACHE.Set( | 72 handler.BRANCH_UTILITY_MEMCACHE.Set( |
66 branch + '.' + handler.OMAHA_PROXY_URL, | 73 branch + '.' + url_constants.OMAHA_PROXY_URL, |
67 'local', | 74 'local', |
68 memcache.MEMCACHE_BRANCH_UTILITY) | 75 memcache.MEMCACHE_BRANCH_UTILITY) |
69 request = _MockRequest('_ah/warmup') | 76 request = _MockRequest('_ah/warmup') |
70 response = _MockResponse() | 77 response = _MockResponse() |
71 Handler(request, response, local_path='../..').get() | 78 Handler(request, response, local_path='../..').get() |
72 self.assertEqual(200, response.status) | 79 self.assertEqual(200, response.status) |
73 # Test that the pages were rendered by checking the size of the output. | 80 # Test that the pages were rendered by checking the size of the output. |
74 # In python 2.6 there is no 'assertGreater' method. | 81 # In python 2.6 there is no 'assertGreater' method. |
75 self.assertTrue(len(response.out.getvalue()) > 500000) | 82 self.assertTrue(len(response.out.getvalue()) > 500000) |
76 | 83 |
77 if __name__ == '__main__': | 84 if __name__ == '__main__': |
78 unittest.main() | 85 unittest.main() |
OLD | NEW |