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 import re |
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 |
| 12 import appengine_wrappers |
11 import handler | 13 import handler |
12 from handler import Handler | 14 from handler import Handler |
13 | 15 |
14 KNOWN_FAILURES = [ | 16 KNOWN_FAILURES = [ |
15 ] | 17 ] |
16 | 18 |
| 19 def _ReadFile(path): |
| 20 with open(path, 'r') as f: |
| 21 return f.read() |
| 22 |
| 23 class FakeOmahaProxy(object): |
| 24 def fetch(self, url): |
| 25 return _ReadFile(os.path.join('test_data', 'branch_utility', 'first.json')) |
| 26 |
| 27 class FakeSubversionServer(object): |
| 28 def __init__(self): |
| 29 self._base_pattern = re.compile(r'.*chrome/common/extensions/(.*)') |
| 30 |
| 31 def fetch(self, url): |
| 32 path = os.path.join( |
| 33 os.pardir, os.pardir, self._base_pattern.match(url).group(1)) |
| 34 if os.path.isdir(path): |
| 35 html = ['<html>Revision 000000'] |
| 36 for f in os.listdir(path): |
| 37 if os.path.isdir(os.path.join(path, f)): |
| 38 html.append('<a>' + f + '/</a>') |
| 39 else: |
| 40 html.append('<a>' + f + '</a>') |
| 41 html.append('</html>') |
| 42 return '\n'.join(html) |
| 43 return _ReadFile(path) |
| 44 |
| 45 appengine_wrappers.ConfigureFakeUrlFetch({ |
| 46 handler.OMAHA_PROXY_URL: FakeOmahaProxy(), |
| 47 '%s/.*' % handler.SVN_URL: FakeSubversionServer() |
| 48 }) |
| 49 |
17 class _MockResponse(object): | 50 class _MockResponse(object): |
18 def __init__(self): | 51 def __init__(self): |
19 self.status = 200 | 52 self.status = 200 |
20 self.out = StringIO() | 53 self.out = StringIO() |
21 | 54 |
22 def set_status(self, status): | 55 def set_status(self, status): |
23 self.status = status | 56 self.status = status |
24 | 57 |
25 class _MockRequest(object): | 58 class _MockRequest(object): |
26 def __init__(self, path): | 59 def __init__(self, path): |
(...skipping 25 matching lines...) Expand all Loading... |
52 # Use US English, Spanish, and Arabic. | 85 # Use US English, Spanish, and Arabic. |
53 for lang in ['en-US', 'es', 'ar']: | 86 for lang in ['en-US', 'es', 'ar']: |
54 request = _MockRequest('extensions/samples.html') | 87 request = _MockRequest('extensions/samples.html') |
55 request.headers['Accept-Language'] = lang + ';q=0.8' | 88 request.headers['Accept-Language'] = lang + ';q=0.8' |
56 response = _MockResponse() | 89 response = _MockResponse() |
57 Handler(request, response, local_path='../..').get() | 90 Handler(request, response, local_path='../..').get() |
58 self.assertEqual(200, response.status) | 91 self.assertEqual(200, response.status) |
59 self.assertTrue(response.out.getvalue()) | 92 self.assertTrue(response.out.getvalue()) |
60 | 93 |
61 def testWarmupRequest(self): | 94 def testWarmupRequest(self): |
62 for branch in ['dev', 'trunk', 'beta', 'stable']: | |
63 handler.BRANCH_UTILITY_MEMCACHE.Set( | |
64 branch + '.' + handler.OMAHA_PROXY_URL, | |
65 'local', | |
66 memcache.MEMCACHE_BRANCH_UTILITY) | |
67 request = _MockRequest('_ah/warmup') | 95 request = _MockRequest('_ah/warmup') |
68 response = _MockResponse() | 96 response = _MockResponse() |
69 Handler(request, response, local_path='../..').get() | 97 Handler(request, response, local_path='../..').get() |
70 self.assertEqual(200, response.status) | 98 self.assertEqual(200, response.status) |
71 # Test that the pages were rendered by checking the size of the output. | 99 # Test that the pages were rendered by checking the size of the output. |
72 # In python 2.6 there is no 'assertGreater' method. | 100 # In python 2.6 there is no 'assertGreater' method. |
73 self.assertTrue(len(response.out.getvalue()) > 500000) | 101 self.assertTrue(len(response.out.getvalue()) > 500000) |
74 | 102 |
75 if __name__ == '__main__': | 103 if __name__ == '__main__': |
76 unittest.main() | 104 unittest.main() |
OLD | NEW |