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 datetime | 6 import datetime |
7 import os | 7 import os |
8 import unittest | 8 import unittest |
9 | 9 |
10 import app | 10 import app |
11 | 11 |
12 | 12 |
| 13 TEST_DIR = os.path.join(os.path.dirname(__file__), 'tests') |
| 14 |
| 15 |
13 class GaeTestCase(unittest.TestCase): | 16 class GaeTestCase(unittest.TestCase): |
14 def setUp(self, *args, **kwargs): | 17 def setUp(self, *args, **kwargs): |
15 self.clear_datastore() | 18 self.clear_datastore() |
16 super(GaeTestCase, self).setUp(*args, **kwargs) | 19 super(GaeTestCase, self).setUp(*args, **kwargs) |
17 | 20 |
| 21 # R0201: 21,2:GaeTestCase._load_content: Method could be a function |
| 22 # pylint: disable=R0201 |
| 23 def _load_content(self, test_dir, path): |
| 24 with open(os.path.join(test_dir, path)) as fh: |
| 25 return fh.read() |
| 26 return None |
| 27 |
18 @staticmethod | 28 @staticmethod |
19 def save_page(localpath, content): | 29 def save_page(localpath, content): |
| 30 page_data = {} |
| 31 page_data['content'] = content |
20 fetch_timestamp = datetime.datetime.now() | 32 fetch_timestamp = datetime.datetime.now() |
21 model = app.Page(localpath=localpath, content=None, | 33 model = app.Page(localpath=localpath, content=None, |
22 fetch_timestamp=fetch_timestamp) | 34 fetch_timestamp=fetch_timestamp) |
23 model.put() | 35 model.put() |
24 app.save_page(model, localpath=localpath, content=content, | 36 app.save_page(model, localpath=localpath, fetch_timestamp=fetch_timestamp, |
25 fetch_timestamp=fetch_timestamp) | 37 page_data=page_data) |
26 return model | 38 return model |
27 | 39 |
28 @staticmethod | 40 @staticmethod |
29 def clear_datastore(): | 41 def clear_datastore(): |
30 from google.appengine.api import apiproxy_stub_map, datastore_file_stub | 42 from google.appengine.api import apiproxy_stub_map, datastore_file_stub |
31 from google.appengine.api import memcache | 43 from google.appengine.api import memcache |
32 | 44 |
33 # See http://code.google.com/p/gaeunit/issues/detail?id=15 for clue. | 45 # See http://code.google.com/p/gaeunit/issues/detail?id=15 for clue. |
34 for key in ['datastore', 'datastore_v3']: | 46 for key in ['datastore', 'datastore_v3']: |
35 # W0212: 23,16:GaeTestCase.clear_datastore: Access to a protected member | 47 # W0212: 23,16:GaeTestCase.clear_datastore: Access to a protected member |
36 # _APIProxyStubMap__stub_map of a client class | 48 # _APIProxyStubMap__stub_map of a client class |
37 # E1101: 26,16:GaeTestCase.clear_datastore: Instance of 'APIProxyStubMap' | 49 # pylint: disable=W0212 |
38 # has no '_APIProxyStubMap__stub_map' member | |
39 # pylint: disable=W0212,E1101 | |
40 if key in apiproxy_stub_map.apiproxy._APIProxyStubMap__stub_map: | 50 if key in apiproxy_stub_map.apiproxy._APIProxyStubMap__stub_map: |
41 # W0212: 24,12:GaeTestCase.clear_datastore: Access to a protected | 51 # W0212: 24,12:GaeTestCase.clear_datastore: Access to a protected |
42 # member _APIProxyStubMap__stub_map of a client class | 52 # member _APIProxyStubMap__stub_map of a client class |
43 # E1101: 30,12:GaeTestCase.clear_datastore: Instance of | 53 # pylint: disable=W0212 |
44 # 'APIProxyStubMap' has no '_APIProxyStubMap__stub_map' member | |
45 # pylint: disable=W0212,E1101 | |
46 del apiproxy_stub_map.apiproxy._APIProxyStubMap__stub_map[key] | 54 del apiproxy_stub_map.apiproxy._APIProxyStubMap__stub_map[key] |
47 | 55 |
48 # Use a fresh stub datastore. | 56 # Use a fresh stub datastore. |
49 stub = datastore_file_stub.DatastoreFileStub( | 57 stub = datastore_file_stub.DatastoreFileStub( |
50 app.APP_NAME, '/dev/null', '/dev/null') | 58 app.APP_NAME, '/dev/null', '/dev/null') |
51 apiproxy_stub_map.apiproxy.RegisterStub('datastore', stub) | 59 apiproxy_stub_map.apiproxy.RegisterStub('datastore', stub) |
52 | 60 |
53 # Flush memcache. | 61 # Flush memcache. |
54 # E1101: 42,4:GaeTestCase.clear_datastore: Module | |
55 # 'google.appengine.api.memcache' has no 'flush_all' member | |
56 # pylint: disable=E1101 | |
57 memcache.flush_all() | 62 memcache.flush_all() |
58 | 63 |
59 class MainTestCase(GaeTestCase): | 64 class MainTestCase(GaeTestCase): |
60 def test_main_page_redirect(self): | 65 def test_main_page_redirect(self): |
61 from webtest import TestApp | 66 from webtest import TestApp |
62 import handler | 67 import handler |
63 testapp = TestApp(handler.application) | 68 testapp = TestApp(handler.application) |
64 response = testapp.get('/') | 69 response = testapp.get('/') |
65 self.assertEquals('302 Moved Temporarily', response.status) | 70 self.assertEquals('302 Moved Temporarily', response.status) |
66 self.assertEquals('', response.body) | 71 self.assertEquals('', response.body) |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 'Bad response: 404 Not Found (not 200 OK or 3xx redirect for ' | 172 'Bad response: 404 Not Found (not 200 OK or 3xx redirect for ' |
168 'http://localhost/p/test)\n') | 173 'http://localhost/p/test)\n') |
169 | 174 |
170 # Verify that the path with the query string works. | 175 # Verify that the path with the query string works. |
171 response = testapp.get('/p/test?query') | 176 response = testapp.get('/p/test?query') |
172 self.assertEquals('200 OK', response.status) | 177 self.assertEquals('200 OK', response.status) |
173 self.assertEquals('Test Query.', response.body) | 178 self.assertEquals('Test Query.', response.body) |
174 | 179 |
175 class ConsoleTestCase(GaeTestCase): | 180 class ConsoleTestCase(GaeTestCase): |
176 def test_console_handler(self): | 181 def test_console_handler(self): |
177 test_dir = os.path.join(os.path.dirname(__file__), | 182 test_dir = os.path.join(TEST_DIR, 'test_console_handler') |
178 'tests', | |
179 'test_console_handler') | |
180 self.save_page(localpath='chromium/sheriff.js', | 183 self.save_page(localpath='chromium/sheriff.js', |
181 content='document.write(\'sheriff1\')') | 184 content='document.write(\'sheriff1\')') |
182 self.save_page(localpath='chromium/sheriff_webkit.js', | 185 self.save_page(localpath='chromium/sheriff_webkit.js', |
183 content='document.write(\'sheriff2\')') | 186 content='document.write(\'sheriff2\')') |
184 self.save_page(localpath='chromium/sheriff_memory.js', | 187 self.save_page(localpath='chromium/sheriff_memory.js', |
185 content='document.write(\'sheriff3\')') | 188 content='document.write(\'sheriff3\')') |
186 self.save_page(localpath='chromium/sheriff_nacl.js', | 189 self.save_page(localpath='chromium/sheriff_nacl.js', |
187 content='document.write(\'sheriff4\')') | 190 content='document.write(\'sheriff4\')') |
188 self.save_page(localpath='chromium/sheriff_perf.js', | 191 self.save_page(localpath='chromium/sheriff_perf.js', |
189 content='document.write(\'sheriff5\')') | 192 content='document.write(\'sheriff5\')') |
190 self.save_page(localpath='chromium/sheriff_cros_mtv.js', | 193 self.save_page(localpath='chromium/sheriff_cros_mtv.js', |
191 content='document.write(\'sheriff6, sheriff7\')') | 194 content='document.write(\'sheriff6, sheriff7\')') |
192 self.save_page(localpath='chromium/sheriff_cros_nonmtv.js', | 195 self.save_page(localpath='chromium/sheriff_cros_nonmtv.js', |
193 content='document.write(\'sheriff8\')') | 196 content='document.write(\'sheriff8\')') |
194 with open(os.path.join(test_dir, 'console-input.html')) as input_fh: | 197 input_console = self._load_content(test_dir, 'console-input.html') |
195 input_console = input_fh.read() | 198 expected_console = self._load_content(test_dir, 'console-expected.html') |
196 with open(os.path.join(test_dir, 'console-expected.html')) as expected_fh: | 199 page_data = {'content': input_console} |
197 expected_console = expected_fh.read() | |
198 actual_console = app.console_handler( | 200 actual_console = app.console_handler( |
199 unquoted_localpath='chromium/console', | 201 _unquoted_localpath='chromium/console', |
200 remoteurl='http://build.chromium.org/p/chromium/console', | 202 remoteurl='http://build.chromium.org/p/chromium/console', |
201 content=input_console) | 203 page_data=page_data) |
202 # Uncomment if deeper inspection is needed of the returned console. | 204 # Uncomment if deeper inspection is needed of the returned console. |
203 # with open(os.path.join(test_dir, 'console-expected.html'), 'w') as fh: | 205 # with open(os.path.join(test_dir, 'console-expected.html'), 'w') as fh: |
204 # fh.write(actual_console) | 206 # fh.write(actual_console['content']) |
205 self.assertEquals(expected_console, actual_console, | 207 self.assertEquals(expected_console, actual_console['content'], |
206 'Unexpected console output found') | 208 'Unexpected console output found') |
207 | 209 |
208 def test_console_handler_utf8(self): | 210 def test_console_handler_utf8(self): |
209 test_dir = os.path.join(os.path.dirname(__file__), | 211 test_dir = os.path.join(TEST_DIR, 'test_console_handler_utf8') |
210 'tests', | |
211 'test_console_handler_utf8') | |
212 self.save_page(localpath='chromium/sheriff.js', | 212 self.save_page(localpath='chromium/sheriff.js', |
213 content='document.write(\'sheriff1\')') | 213 content='document.write(\'sheriff1\')') |
214 self.save_page(localpath='chromium/sheriff_webkit.js', | 214 self.save_page(localpath='chromium/sheriff_webkit.js', |
215 content='document.write(\'sheriff2\')') | 215 content='document.write(\'sheriff2\')') |
216 self.save_page(localpath='chromium/sheriff_memory.js', | 216 self.save_page(localpath='chromium/sheriff_memory.js', |
217 content='document.write(\'sheriff3\')') | 217 content='document.write(\'sheriff3\')') |
218 self.save_page(localpath='chromium/sheriff_nacl.js', | 218 self.save_page(localpath='chromium/sheriff_nacl.js', |
219 content='document.write(\'sheriff4\')') | 219 content='document.write(\'sheriff4\')') |
220 self.save_page(localpath='chromium/sheriff_perf.js', | 220 self.save_page(localpath='chromium/sheriff_perf.js', |
221 content='document.write(\'sheriff5\')') | 221 content='document.write(\'sheriff5\')') |
222 self.save_page(localpath='chromium/sheriff_cros_mtv.js', | 222 self.save_page(localpath='chromium/sheriff_cros_mtv.js', |
223 content='document.write(\'sheriff6, sheriff7\')') | 223 content='document.write(\'sheriff6, sheriff7\')') |
224 self.save_page(localpath='chromium/sheriff_cros_nonmtv.js', | 224 self.save_page(localpath='chromium/sheriff_cros_nonmtv.js', |
225 content='document.write(\'sheriff8\')') | 225 content='document.write(\'sheriff8\')') |
226 with open(os.path.join(test_dir, 'console-input.html')) as input_fh: | 226 input_console = self._load_content(test_dir, 'console-input.html') |
227 input_console = input_fh.read() | 227 expected_console = self._load_content(test_dir, 'console-expected.html') |
228 with open(os.path.join(test_dir, 'console-expected.html')) as expected_fh: | 228 page_data = {'content': input_console} |
229 expected_console = expected_fh.read() | |
230 actual_console = app.console_handler( | 229 actual_console = app.console_handler( |
231 unquoted_localpath='chromium/console', | 230 _unquoted_localpath='chromium/console', |
232 remoteurl='http://build.chromium.org/p/chromium/console', | 231 remoteurl='http://build.chromium.org/p/chromium/console', |
233 content=input_console) | 232 page_data=page_data) |
234 # Uncomment if deeper inspection is needed of the returned console. | 233 # Uncomment if deeper inspection is needed of the returned console. |
235 # with open(os.path.join(test_dir, 'console-expected.html'), 'w') as fh: | 234 # with open(os.path.join(test_dir, 'console-expected.html'), 'w') as fh: |
236 # fh.write(actual_console) | 235 # fh.write(actual_console['content']) |
237 self.assertEquals(expected_console, actual_console, | 236 self.assertEquals(expected_console, actual_console['content'], |
238 'Unexpected console output found') | 237 'Unexpected console output found') |
239 | 238 |
240 def test_console_merger(self): | 239 def test_console_merger(self): |
241 test_dir = os.path.join(os.path.dirname(__file__), | 240 test_dir = os.path.join(TEST_DIR, 'test_console_merger') |
242 'tests', | |
243 'test_console_merger') | |
244 filedata = {} | 241 filedata = {} |
245 for filename in [ | 242 for filename in [ |
246 'chromium_chrome_console_input.html', | 243 'chromium_chrome_console_input.html', |
247 'chromium_chromiumos_console_input.html', | 244 'chromium_chromiumos_console_input.html', |
248 'chromium_main_console_input.html', | 245 'chromium_main_console_input.html', |
249 'chromium_memory_console_input.html', | 246 'chromium_memory_console_input.html', |
250 'chromium_merged_console.html', | 247 'chromium_merged_console.html', |
251 ]: | 248 ]: |
252 with open(os.path.join(test_dir, filename)) as fh: | 249 filedata[filename] = self._load_content(test_dir, filename) |
253 filedata[filename] = fh.read() | |
254 self.save_page(localpath='chromium.chrome/console', | 250 self.save_page(localpath='chromium.chrome/console', |
255 content=filedata['chromium_chrome_console_input.html']) | 251 content=filedata['chromium_chrome_console_input.html']) |
256 self.save_page(localpath='chromium.chromiumos/console', | 252 self.save_page(localpath='chromium.chromiumos/console', |
257 content=filedata['chromium_chromiumos_console_input.html']) | 253 content=filedata['chromium_chromiumos_console_input.html']) |
258 self.save_page(localpath='chromium.main/console', | 254 self.save_page(localpath='chromium.main/console', |
259 content=filedata['chromium_main_console_input.html']) | 255 content=filedata['chromium_main_console_input.html']) |
260 self.save_page(localpath='chromium.memory/console', | 256 self.save_page(localpath='chromium.memory/console', |
261 content=filedata['chromium_memory_console_input.html']) | 257 content=filedata['chromium_memory_console_input.html']) |
262 actual_mergedconsole = app.console_merger( | 258 page_data = {'content': filedata['chromium_merged_console.html']} |
| 259 app.console_merger( |
263 'chromium.main/console', | 260 'chromium.main/console', |
264 'http://build.chromium.org/p/chromium/console', | 261 'http://build.chromium.org/p/chromium/console', |
265 content=filedata['chromium_merged_console.html']) | 262 page_data=page_data) |
| 263 actual_mergedconsole = app.get_and_cache_pagedata('chromium/console') |
266 # Uncomment if deeper inspection is needed of the returned console. | 264 # Uncomment if deeper inspection is needed of the returned console. |
267 # import logging | 265 # import logging |
268 # logging.debug('foo') | 266 # logging.debug('foo') |
269 # with open(os.path.join(test_dir, 'chromium_merged_console.html'), | 267 # with open(os.path.join(test_dir, 'chromium_merged_console.html'), |
270 # 'w') as fh: | 268 # 'w') as fh: |
271 # fh.write(actual_mergedconsole) | 269 # fh.write(actual_mergedconsole['content']) |
272 # import code | 270 # import code |
273 # code.interact(local=locals()) | 271 # code.interact(local=locals()) |
274 self.assertEquals(filedata['chromium_merged_console.html'], | 272 self.assertEquals(filedata['chromium_merged_console.html'], |
275 actual_mergedconsole, | 273 actual_mergedconsole['content'], |
276 'Unexpected console output found') | 274 'Unexpected console output found') |
277 | 275 |
278 def test_console_merger_utf8(self): | 276 def test_console_merger_utf8(self): |
279 test_dir = os.path.join(os.path.dirname(__file__), | 277 test_dir = os.path.join(TEST_DIR, 'test_console_merger_utf8') |
280 'tests', | |
281 'test_console_merger_utf8') | |
282 filedata = {} | 278 filedata = {} |
283 for filename in [ | 279 for filename in [ |
284 'chromium_chrome_console_input.html', | 280 'chromium_chrome_console_input.html', |
285 'chromium_chromiumos_console_input.html', | 281 'chromium_chromiumos_console_input.html', |
286 'chromium_main_console_input.html', | 282 'chromium_main_console_input.html', |
287 'chromium_memory_console_input.html', | 283 'chromium_memory_console_input.html', |
288 'chromium_merged_console.html', | 284 'chromium_merged_console.html', |
289 ]: | 285 ]: |
290 with open(os.path.join(test_dir, filename)) as fh: | 286 filedata[filename] = self._load_content(test_dir, filename) |
291 filedata[filename] = fh.read() | |
292 self.save_page(localpath='chromium.chrome/console', | 287 self.save_page(localpath='chromium.chrome/console', |
293 content=filedata['chromium_chrome_console_input.html']) | 288 content=filedata['chromium_chrome_console_input.html']) |
294 self.save_page(localpath='chromium.chromiumos/console', | 289 self.save_page(localpath='chromium.chromiumos/console', |
295 content=filedata['chromium_chromiumos_console_input.html']) | 290 content=filedata['chromium_chromiumos_console_input.html']) |
296 self.save_page(localpath='chromium.main/console', | 291 self.save_page(localpath='chromium.main/console', |
297 content=filedata['chromium_main_console_input.html']) | 292 content=filedata['chromium_main_console_input.html']) |
298 self.save_page(localpath='chromium.memory/console', | 293 self.save_page(localpath='chromium.memory/console', |
299 content=filedata['chromium_memory_console_input.html']) | 294 content=filedata['chromium_memory_console_input.html']) |
300 actual_mergedconsole = app.console_merger( | 295 page_data = {'content': filedata['chromium_merged_console.html']} |
| 296 app.console_merger( |
301 'chromium.main/console', | 297 'chromium.main/console', |
302 'http://build.chromium.org/p/chromium/console', | 298 'http://build.chromium.org/p/chromium/console', |
303 content=filedata['chromium_merged_console.html']) | 299 page_data=page_data) |
| 300 actual_mergedconsole = app.get_and_cache_pagedata('chromium/console') |
304 # Uncomment if deeper inspection is needed of the returned console. | 301 # Uncomment if deeper inspection is needed of the returned console. |
305 # import logging | 302 # import logging |
306 # logging.debug('foo') | 303 # logging.debug('foo') |
307 # merged_path = os.path.join(test_dir, 'chromium_merged_console.html') | 304 # merged_path = os.path.join(test_dir, 'chromium_merged_console.html') |
308 # with open(merged_path, 'w') as fh: | 305 # with open(merged_path, 'w') as fh: |
309 # fh.write(actual_mergedconsole) | 306 # fh.write(actual_mergedconsole['content']) |
310 # import code | 307 # import code |
311 # code.interact(local=locals()) | 308 # code.interact(local=locals()) |
312 self.assertEquals(filedata['chromium_merged_console.html'], | 309 self.assertEquals(filedata['chromium_merged_console.html'], |
313 actual_mergedconsole, | 310 actual_mergedconsole['content'], |
314 'Unexpected console output found') | 311 'Unexpected console output found') |
315 | 312 |
316 def test_console_merger_splitrevs(self): | 313 def test_console_merger_splitrevs(self): |
317 test_dir = os.path.join(os.path.dirname(__file__), | 314 test_dir = os.path.join(TEST_DIR, 'test_console_merger_splitrevs') |
318 'tests', | |
319 'test_console_merger_splitrevs') | |
320 filedata = {} | 315 filedata = {} |
321 for filename in [ | 316 for filename in [ |
322 'chromium_chrome_console.html', | 317 'chromium_chrome_console.html', |
323 'chromium_chromiumos_console.html', | 318 'chromium_chromiumos_console.html', |
324 'chromium_console.html', | 319 'chromium_console.html', |
325 'chromium_memory_console.html', | 320 'chromium_memory_console.html', |
326 'chromium_merged_console.html', | 321 'chromium_merged_console.html', |
327 ]: | 322 ]: |
328 with open(os.path.join(test_dir, filename)) as fh: | 323 filedata[filename] = self._load_content(test_dir, filename) |
329 filedata[filename] = fh.read() | |
330 self.save_page(localpath='chromium.chrome/console', | 324 self.save_page(localpath='chromium.chrome/console', |
331 content=filedata['chromium_chrome_console.html']) | 325 content=filedata['chromium_chrome_console.html']) |
332 self.save_page(localpath='chromium.chromiumos/console', | 326 self.save_page(localpath='chromium.chromiumos/console', |
333 content=filedata['chromium_chromiumos_console.html']) | 327 content=filedata['chromium_chromiumos_console.html']) |
334 self.save_page(localpath='chromium.main/console', | 328 self.save_page(localpath='chromium.main/console', |
335 content=filedata['chromium_console.html']) | 329 content=filedata['chromium_console.html']) |
336 self.save_page(localpath='chromium.memory/console', | 330 self.save_page(localpath='chromium.memory/console', |
337 content=filedata['chromium_memory_console.html']) | 331 content=filedata['chromium_memory_console.html']) |
338 actual_mergedconsole = app.console_merger( | 332 page_data = {'content': filedata['chromium_merged_console.html']} |
| 333 app.console_merger( |
339 'chromium.main/console', | 334 'chromium.main/console', |
340 'http://build.chromium.org/p/chromium/console', | 335 'http://build.chromium.org/p/chromium/console', |
341 content=filedata['chromium_merged_console.html']) | 336 page_data=page_data) |
| 337 actual_mergedconsole = app.get_and_cache_pagedata('chromium/console') |
342 # Uncomment if deeper inspection is needed of the returned console. | 338 # Uncomment if deeper inspection is needed of the returned console. |
343 # import logging | 339 # import logging |
344 # logging.debug('foo') | 340 # logging.debug('foo') |
345 # with open(os.path.join(test_dir, 'chromium_merged_console.html'), | 341 # with open(os.path.join(test_dir, 'chromium_merged_console.html'), |
346 # 'w') as fh: | 342 # 'w') as fh: |
347 # fh.write(actual_mergedconsole) | 343 # fh.write(actual_mergedconsole['content']) |
348 # import code | 344 # import code |
349 # code.interact(local=locals()) | 345 # code.interact(local=locals()) |
350 self.assertEquals(filedata['chromium_merged_console.html'], | 346 self.assertEquals(filedata['chromium_merged_console.html'], |
351 actual_mergedconsole, | 347 actual_mergedconsole['content'], |
352 'Unexpected console output found') | 348 'Unexpected console output found') |
| 349 |
| 350 |
| 351 class FetchTestCase(GaeTestCase): |
| 352 class FakeResponse(object): |
| 353 status_code = 200 |
| 354 content = None |
| 355 |
| 356 def test_fetch_direct(self): |
| 357 test_dir = os.path.join(TEST_DIR, 'test_fetch_direct') |
| 358 |
| 359 def fetch_url(url): |
| 360 fr = FetchTestCase.FakeResponse() |
| 361 if url == 'http://build.chromium.org/p/chromium/console': |
| 362 fr.content = self._load_content(test_dir, 'input.html') |
| 363 return fr |
| 364 |
| 365 expected_content = self._load_content(test_dir, 'expected.html') |
| 366 app.fetch_page( |
| 367 localpath='chromium/console', |
| 368 remoteurl='http://build.chromium.org/p/chromium/console', |
| 369 maxage=60, |
| 370 fetch_url=fetch_url) |
| 371 page = app.get_and_cache_pagedata('chromium/console') |
| 372 # Uncomment if deeper inspection is needed of the returned console. |
| 373 # with open(os.path.join(test_dir, 'expected.html'), 'w') as fh: |
| 374 # fh.write(page['content']) |
| 375 self.assertEquals(expected_content, page['content']) |
| 376 |
| 377 def test_fetch_console(self): |
| 378 test_dir = os.path.join(TEST_DIR, 'test_fetch_console') |
| 379 |
| 380 def fetch_url(url): |
| 381 fr = FetchTestCase.FakeResponse() |
| 382 if url == 'http://build.chromium.org/p/chromium/console': |
| 383 fr.content = self._load_content(test_dir, 'input.html') |
| 384 return fr |
| 385 |
| 386 expected_content = self._load_content(test_dir, 'expected.html') |
| 387 app.fetch_page( |
| 388 localpath='chromium/console', |
| 389 remoteurl='http://build.chromium.org/p/chromium/console', |
| 390 maxage=60, |
| 391 postfetch=app.console_handler, |
| 392 fetch_url=fetch_url) |
| 393 page = app.get_and_cache_pagedata('chromium/console') |
| 394 # Uncomment if deeper inspection is needed of the returned console. |
| 395 # with open(os.path.join(test_dir, 'expected.html'), 'w') as fh: |
| 396 # fh.write(page['content']) |
| 397 self.assertEquals('interface', page['body_class']) |
| 398 self.assertEquals(expected_content, page['content']) |
| 399 self.assertEquals( |
| 400 'http://build.chromium.org/p/chromium/console/../', |
| 401 page['offsite_base']) |
| 402 self.assertEquals('BuildBot: Chromium', page['title']) |
OLD | NEW |