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