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 os | 6 import os |
7 from StringIO import StringIO | 7 from StringIO import StringIO |
8 import unittest | 8 import unittest |
9 | 9 |
10 import appengine_memcache as memcache | 10 import appengine_memcache as memcache |
(...skipping 12 matching lines...) Expand all Loading... |
23 def set_status(self, status): | 23 def set_status(self, status): |
24 self.status = status | 24 self.status = status |
25 | 25 |
26 class _MockRequest(object): | 26 class _MockRequest(object): |
27 def __init__(self, path): | 27 def __init__(self, path): |
28 self.headers = {} | 28 self.headers = {} |
29 self.path = path | 29 self.path = path |
30 | 30 |
31 class IntegrationTest(unittest.TestCase): | 31 class IntegrationTest(unittest.TestCase): |
32 def testAll(self): | 32 def testAll(self): |
33 for filename in os.listdir(os.path.join('templates', 'public')): | 33 base_path = os.path.join('templates', 'public') |
34 if filename in KNOWN_FAILURES or filename.startswith('.'): | 34 for path, dirs, files in os.walk(base_path): |
35 continue | 35 for name in files: |
36 request = _MockRequest(filename) | 36 filename = os.path.join(path, name) |
37 response = _MockResponse() | 37 if filename in KNOWN_FAILURES or filename.startswith('.'): |
38 Handler(request, response, local_path='../..').get() | 38 continue |
39 self.assertEqual(200, response.status) | 39 request = _MockRequest(filename.split('/', 2)[-1]) |
40 self.assertTrue(response.out.getvalue()) | 40 response = _MockResponse() |
| 41 Handler(request, response, local_path='../..').get() |
| 42 self.assertEqual(200, response.status) |
| 43 self.assertTrue(response.out.getvalue()) |
41 | 44 |
42 def test404(self): | 45 def test404(self): |
43 request = _MockRequest('junk.html') | 46 request = _MockRequest('junk.html') |
44 bad_response = _MockResponse() | 47 bad_response = _MockResponse() |
45 Handler(request, bad_response, local_path='../..').get() | 48 Handler(request, bad_response, local_path='../..').get() |
46 self.assertEqual(404, bad_response.status) | 49 self.assertEqual(404, bad_response.status) |
47 self.assertTrue(bad_response.out.getvalue()) | 50 self.assertTrue(bad_response.out.getvalue()) |
48 | 51 |
49 def testLocales(self): | 52 def testLocales(self): |
50 # Use US English, Spanish, and Arabic. | 53 # Use US English, Spanish, and Arabic. |
51 for lang in ['en-US', 'es', 'ar']: | 54 for lang in ['en-US', 'es', 'ar']: |
52 request = _MockRequest('samples.html') | 55 request = _MockRequest('extensions/samples.html') |
53 request.headers['Accept-Language'] = lang + ';q=0.8' | 56 request.headers['Accept-Language'] = lang + ';q=0.8' |
54 response = _MockResponse() | 57 response = _MockResponse() |
55 Handler(request, response, local_path='../..').get() | 58 Handler(request, response, local_path='../..').get() |
56 self.assertEqual(200, response.status) | 59 self.assertEqual(200, response.status) |
57 self.assertTrue(response.out.getvalue()) | 60 self.assertTrue(response.out.getvalue()) |
58 | 61 |
59 def testWarmupRequest(self): | 62 def testWarmupRequest(self): |
60 for branch in ['dev', 'trunk', 'beta', 'stable']: | 63 for branch in ['dev', 'trunk', 'beta', 'stable']: |
61 handler.BRANCH_UTILITY_MEMCACHE.Set( | 64 handler.BRANCH_UTILITY_MEMCACHE.Set( |
62 branch + '.' + handler.OMAHA_PROXY_URL, | 65 branch + '.' + handler.OMAHA_PROXY_URL, |
63 'local', | 66 'local', |
64 memcache.MEMCACHE_BRANCH_UTILITY) | 67 memcache.MEMCACHE_BRANCH_UTILITY) |
65 request = _MockRequest('_ah/warmup') | 68 request = _MockRequest('_ah/warmup') |
66 response = _MockResponse() | 69 response = _MockResponse() |
67 Handler(request, response, local_path='../..').get() | 70 Handler(request, response, local_path='../..').get() |
68 self.assertEqual(200, response.status) | 71 self.assertEqual(200, response.status) |
69 # Test that the pages were rendered by checking the size of the output. | 72 # Test that the pages were rendered by checking the size of the output. |
70 # In python 2.6 there is no 'assertGreater' method. | 73 # In python 2.6 there is no 'assertGreater' method. |
71 self.assertTrue(len(response.out.getvalue()) > 500000) | 74 self.assertTrue(len(response.out.getvalue()) > 500000) |
72 | 75 |
73 if __name__ == '__main__': | 76 if __name__ == '__main__': |
74 unittest.main() | 77 unittest.main() |
OLD | NEW |