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 os | 7 import os |
8 import re | 8 import re |
9 from StringIO import StringIO | 9 from StringIO import StringIO |
10 import unittest | 10 import unittest |
11 | 11 |
12 import appengine_memcache as memcache | 12 import appengine_memcache as memcache |
13 import appengine_wrappers | 13 import appengine_wrappers |
14 import url_constants | 14 import url_constants |
15 | 15 |
16 KNOWN_FAILURES = [ | 16 KNOWN_FAILURES = [ |
17 # Apps samples fails because it requires fetching data from github.com. | 17 # Apps samples fails because it requires fetching data from github.com. |
18 # This should be tested though: http://crbug.com/141910. | 18 # This should be tested though: http://crbug.com/141910. |
19 'apps/samples.html', | 19 'apps/samples.html', |
20 ] | 20 ] |
21 | 21 |
22 def _ReadFile(path): | 22 def _ReadFile(path): |
23 with open(path, 'r') as f: | 23 with open(path, 'r') as f: |
24 return f.read() | 24 return f.read() |
25 | 25 |
26 class FakeOmahaProxy(object): | 26 class FakeOmahaProxy(object): |
27 def fetch(self, url): | 27 def fetch(self, url): |
28 return _ReadFile(os.path.join('test_data', 'branch_utility', 'first.json')) | 28 return _ReadFile(os.path.join('test_data', 'branch_utility', 'first.json')) |
29 | 29 |
| 30 class FakeViewvcServer(object): |
| 31 def __init__(self): |
| 32 self._base_pattern = re.compile(r'.*chrome/common/extensions/(.*)') |
| 33 |
| 34 def fetch(self, url): |
| 35 path = os.path.join( |
| 36 os.pardir, os.pardir, self._base_pattern.match(url).group(1)) |
| 37 if os.path.isdir(path): |
| 38 html = ['<html><td>Directory revision:</td><td><a>000000</a></td>'] |
| 39 for f in os.listdir(path): |
| 40 if f.startswith('.'): |
| 41 continue |
| 42 html.append('<td><a name="%s"></a></td>' % f) |
| 43 if os.path.isdir(os.path.join(path, f)): |
| 44 html.append('<td><a title="dir"><strong>000000</strong></a></td>') |
| 45 else: |
| 46 html.append('<td><a title="file"><strong>000000</strong></a></td>') |
| 47 html.append('</html>') |
| 48 return '\n'.join(html) |
| 49 return _ReadFile(path) |
| 50 |
30 class FakeSubversionServer(object): | 51 class FakeSubversionServer(object): |
31 def __init__(self): | 52 def __init__(self): |
32 self._base_pattern = re.compile(r'.*chrome/common/extensions/(.*)') | 53 self._base_pattern = re.compile(r'.*chrome/common/extensions/(.*)') |
33 | 54 |
34 def fetch(self, url): | 55 def fetch(self, url): |
35 path = os.path.join( | 56 path = os.path.join( |
36 os.pardir, os.pardir, self._base_pattern.match(url).group(1)) | 57 os.pardir, os.pardir, self._base_pattern.match(url).group(1)) |
37 if os.path.isdir(path): | 58 if os.path.isdir(path): |
38 html = ['<html>Revision 000000'] | 59 html = ['<html>Revision 000000'] |
39 for f in os.listdir(path): | 60 for f in os.listdir(path): |
40 if f.startswith('.'): | 61 if f.startswith('.'): |
41 continue | 62 continue |
42 if os.path.isdir(os.path.join(path, f)): | 63 if os.path.isdir(os.path.join(path, f)): |
43 html.append('<a>' + f + '/</a>') | 64 html.append('<a>' + f + '/</a>') |
44 else: | 65 else: |
45 html.append('<a>' + f + '</a>') | 66 html.append('<a>' + f + '</a>') |
46 html.append('</html>') | 67 html.append('</html>') |
47 return '\n'.join(html) | 68 return '\n'.join(html) |
48 return _ReadFile(path) | 69 return _ReadFile(path) |
49 | 70 |
50 class FakeGithub(object): | 71 class FakeGithub(object): |
51 def fetch(self, url): | 72 def fetch(self, url): |
52 return '{ "commit": { "tree": { "sha": 0} } }' | 73 return '{ "commit": { "tree": { "sha": 0} } }' |
53 | 74 |
54 appengine_wrappers.ConfigureFakeUrlFetch({ | 75 appengine_wrappers.ConfigureFakeUrlFetch({ |
55 url_constants.OMAHA_PROXY_URL: FakeOmahaProxy(), | 76 url_constants.OMAHA_PROXY_URL: FakeOmahaProxy(), |
56 '%s/.*' % url_constants.SVN_URL: FakeSubversionServer(), | 77 '%s/.*' % url_constants.SVN_URL: FakeSubversionServer(), |
| 78 '%s/.*' % url_constants.VIEWVC_URL: FakeViewvcServer(), |
57 '%s/.*' % url_constants.GITHUB_URL: FakeGithub() | 79 '%s/.*' % url_constants.GITHUB_URL: FakeGithub() |
58 }) | 80 }) |
59 | 81 |
60 # Import Handler later because it immediately makes a request to github. We need | 82 # Import Handler later because it immediately makes a request to github. We need |
61 # the fake urlfetch to be in place first. | 83 # the fake urlfetch to be in place first. |
62 from handler import Handler | 84 from handler import Handler |
63 | 85 |
64 class _MockResponse(object): | 86 class _MockResponse(object): |
65 def __init__(self): | 87 def __init__(self): |
66 self.status = 200 | 88 self.status = 200 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 Handler(request, response, local_path='../..').get() | 136 Handler(request, response, local_path='../..').get() |
115 self.assertEqual(200, response.status) | 137 self.assertEqual(200, response.status) |
116 # Test that the pages were rendered by checking the size of the output. | 138 # Test that the pages were rendered by checking the size of the output. |
117 # In python 2.6 there is no 'assertGreater' method. | 139 # In python 2.6 there is no 'assertGreater' method. |
118 value = response.out.getvalue() | 140 value = response.out.getvalue() |
119 self.assertTrue(len(value) > 100000, | 141 self.assertTrue(len(value) > 100000, |
120 msg='Response is too small, probably empty: %s' % value) | 142 msg='Response is too small, probably empty: %s' % value) |
121 | 143 |
122 if __name__ == '__main__': | 144 if __name__ == '__main__': |
123 unittest.main() | 145 unittest.main() |
OLD | NEW |