Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1567)

Unified Diff: app_test.py

Issue 10448057: Add refresh support to the console page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/chromium-build
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: app_test.py
diff --git a/app_test.py b/app_test.py
index 0f51351e61d55cd80fcdadc3512928fc288cdff0..1758394f40d0164908b0a00b88fa36e813453225 100644
--- a/app_test.py
+++ b/app_test.py
@@ -10,6 +10,9 @@ import unittest
import app
+TEST_DIR = os.path.join(os.path.dirname(__file__), 'tests')
+
+
class GaeTestCase(unittest.TestCase):
def setUp(self, *args, **kwargs):
self.clear_datastore()
@@ -17,12 +20,14 @@ class GaeTestCase(unittest.TestCase):
@staticmethod
def save_page(localpath, content):
+ page_data = {}
+ page_data['content'] = content
fetch_timestamp = datetime.datetime.now()
model = app.Page(localpath=localpath, content=None,
fetch_timestamp=fetch_timestamp)
model.put()
- app.save_page(model, localpath=localpath, content=content,
- fetch_timestamp=fetch_timestamp)
+ app.save_page(model, localpath=localpath, fetch_timestamp=fetch_timestamp,
+ page_data=page_data)
return model
@staticmethod
@@ -34,15 +39,11 @@ class GaeTestCase(unittest.TestCase):
for key in ['datastore', 'datastore_v3']:
# W0212: 23,16:GaeTestCase.clear_datastore: Access to a protected member
# _APIProxyStubMap__stub_map of a client class
- # E1101: 26,16:GaeTestCase.clear_datastore: Instance of 'APIProxyStubMap'
- # has no '_APIProxyStubMap__stub_map' member
- # pylint: disable=W0212,E1101
+ # pylint: disable=W0212
if key in apiproxy_stub_map.apiproxy._APIProxyStubMap__stub_map:
# W0212: 24,12:GaeTestCase.clear_datastore: Access to a protected
# member _APIProxyStubMap__stub_map of a client class
- # E1101: 30,12:GaeTestCase.clear_datastore: Instance of
- # 'APIProxyStubMap' has no '_APIProxyStubMap__stub_map' member
- # pylint: disable=W0212,E1101
+ # pylint: disable=W0212
del apiproxy_stub_map.apiproxy._APIProxyStubMap__stub_map[key]
# Use a fresh stub datastore.
@@ -51,9 +52,6 @@ class GaeTestCase(unittest.TestCase):
apiproxy_stub_map.apiproxy.RegisterStub('datastore', stub)
# Flush memcache.
- # E1101: 42,4:GaeTestCase.clear_datastore: Module
- # 'google.appengine.api.memcache' has no 'flush_all' member
- # pylint: disable=E1101
memcache.flush_all()
class MainTestCase(GaeTestCase):
@@ -174,9 +172,7 @@ class AppTestCase(GaeTestCase):
class ConsoleTestCase(GaeTestCase):
def test_console_handler(self):
- test_dir = os.path.join(os.path.dirname(__file__),
- 'tests',
- 'test_console_handler')
+ test_dir = os.path.join(TEST_DIR, 'test_console_handler')
self.save_page(localpath='chromium/sheriff.js',
content='document.write(\'sheriff1\')')
self.save_page(localpath='chromium/sheriff_webkit.js',
@@ -195,20 +191,19 @@ class ConsoleTestCase(GaeTestCase):
input_console = input_fh.read()
with open(os.path.join(test_dir, 'console-expected.html')) as expected_fh:
expected_console = expected_fh.read()
+ page_data = {'content': input_console}
actual_console = app.console_handler(
unquoted_localpath='chromium/console',
remoteurl='http://build.chromium.org/p/chromium/console',
- content=input_console)
+ page_data=page_data)
# Uncomment if deeper inspection is needed of the returned console.
# with open(os.path.join(test_dir, 'console-expected.html'), 'w') as fh:
- # fh.write(actual_console)
- self.assertEquals(expected_console, actual_console,
+ # fh.write(actual_console['content'])
+ self.assertEquals(expected_console, actual_console['content'],
'Unexpected console output found')
def test_console_handler_utf8(self):
- test_dir = os.path.join(os.path.dirname(__file__),
- 'tests',
- 'test_console_handler_utf8')
+ test_dir = os.path.join(TEST_DIR, 'test_console_handler_utf8')
self.save_page(localpath='chromium/sheriff.js',
content='document.write(\'sheriff1\')')
self.save_page(localpath='chromium/sheriff_webkit.js',
@@ -227,20 +222,19 @@ class ConsoleTestCase(GaeTestCase):
input_console = input_fh.read()
with open(os.path.join(test_dir, 'console-expected.html')) as expected_fh:
expected_console = expected_fh.read()
+ page_data = {'content': input_console}
actual_console = app.console_handler(
unquoted_localpath='chromium/console',
remoteurl='http://build.chromium.org/p/chromium/console',
- content=input_console)
+ page_data=page_data)
# Uncomment if deeper inspection is needed of the returned console.
# with open(os.path.join(test_dir, 'console-expected.html'), 'w') as fh:
- # fh.write(actual_console)
- self.assertEquals(expected_console, actual_console,
+ # fh.write(actual_console['content'])
+ self.assertEquals(expected_console, actual_console['content'],
'Unexpected console output found')
def test_console_merger(self):
- test_dir = os.path.join(os.path.dirname(__file__),
- 'tests',
- 'test_console_merger')
+ test_dir = os.path.join(TEST_DIR, 'test_console_merger')
filedata = {}
for filename in [
'chromium_chrome_console_input.html',
@@ -259,26 +253,26 @@ class ConsoleTestCase(GaeTestCase):
content=filedata['chromium_main_console_input.html'])
self.save_page(localpath='chromium.memory/console',
content=filedata['chromium_memory_console_input.html'])
- actual_mergedconsole = app.console_merger(
+ page_data = {'content': filedata['chromium_merged_console.html']}
+ app.console_merger(
'chromium.main/console',
'http://build.chromium.org/p/chromium/console',
- content=filedata['chromium_merged_console.html'])
+ page_data=page_data)
+ actual_mergedconsole = app.get_and_cache_pagedata('chromium/console')
# Uncomment if deeper inspection is needed of the returned console.
# import logging
# logging.debug('foo')
# with open(os.path.join(test_dir, 'chromium_merged_console.html'),
# 'w') as fh:
- # fh.write(actual_mergedconsole)
+ # fh.write(actual_mergedconsole['content'])
# import code
# code.interact(local=locals())
self.assertEquals(filedata['chromium_merged_console.html'],
- actual_mergedconsole,
+ actual_mergedconsole['content'],
'Unexpected console output found')
def test_console_merger_utf8(self):
- test_dir = os.path.join(os.path.dirname(__file__),
- 'tests',
- 'test_console_merger_utf8')
+ test_dir = os.path.join(TEST_DIR, 'test_console_merger_utf8')
filedata = {}
for filename in [
'chromium_chrome_console_input.html',
@@ -297,26 +291,26 @@ class ConsoleTestCase(GaeTestCase):
content=filedata['chromium_main_console_input.html'])
self.save_page(localpath='chromium.memory/console',
content=filedata['chromium_memory_console_input.html'])
- actual_mergedconsole = app.console_merger(
+ page_data = {'content': filedata['chromium_merged_console.html']}
+ app.console_merger(
'chromium.main/console',
'http://build.chromium.org/p/chromium/console',
- content=filedata['chromium_merged_console.html'])
+ page_data=page_data)
+ actual_mergedconsole = app.get_and_cache_pagedata('chromium/console')
# Uncomment if deeper inspection is needed of the returned console.
# import logging
# logging.debug('foo')
# merged_path = os.path.join(test_dir, 'chromium_merged_console.html')
# with open(merged_path, 'w') as fh:
- # fh.write(actual_mergedconsole)
+ # fh.write(actual_mergedconsole['content'])
# import code
# code.interact(local=locals())
self.assertEquals(filedata['chromium_merged_console.html'],
- actual_mergedconsole,
+ actual_mergedconsole['content'],
'Unexpected console output found')
def test_console_merger_splitrevs(self):
- test_dir = os.path.join(os.path.dirname(__file__),
- 'tests',
- 'test_console_merger_splitrevs')
+ test_dir = os.path.join(TEST_DIR, 'test_console_merger_splitrevs')
filedata = {}
for filename in [
'chromium_chrome_console.html',
@@ -335,18 +329,78 @@ class ConsoleTestCase(GaeTestCase):
content=filedata['chromium_console.html'])
self.save_page(localpath='chromium.memory/console',
content=filedata['chromium_memory_console.html'])
- actual_mergedconsole = app.console_merger(
+ page_data = {'content': filedata['chromium_merged_console.html']}
+ app.console_merger(
'chromium.main/console',
'http://build.chromium.org/p/chromium/console',
- content=filedata['chromium_merged_console.html'])
+ page_data=page_data)
+ actual_mergedconsole = app.get_and_cache_pagedata('chromium/console')
# Uncomment if deeper inspection is needed of the returned console.
# import logging
# logging.debug('foo')
# with open(os.path.join(test_dir, 'chromium_merged_console.html'),
# 'w') as fh:
- # fh.write(actual_mergedconsole)
+ # fh.write(actual_mergedconsole['content'])
# import code
# code.interact(local=locals())
self.assertEquals(filedata['chromium_merged_console.html'],
- actual_mergedconsole,
+ actual_mergedconsole['content'],
'Unexpected console output found')
+
+
+class FetchTestCase(GaeTestCase):
+ class FakeResponse(object):
+ status_code = 200
+ content = None
+
+ def test_fetch_direct(self):
+ test_dir = os.path.join(TEST_DIR, 'test_fetch_direct')
+
+ def fetch_url(url):
+ fr = FetchTestCase.FakeResponse()
+ if url == 'http://build.chromium.org/p/chromium/console':
+ with open(os.path.join(test_dir, 'input.html')) as fh:
+ fr.content = fh.read()
+ return fr
+
+ 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.
+ expected_content = fh.read()
+ app.fetch_page(
+ localpath='chromium/console',
+ remoteurl='http://build.chromium.org/p/chromium/console',
+ maxage=60,
+ fetch_url=fetch_url)
+ page = app.get_and_cache_pagedata('chromium/console')
+ # Uncomment if deeper inspection is needed of the returned console.
+ # with open(os.path.join(test_dir, 'expected.html'), 'w') as fh:
+ # fh.write(page['content'])
+ self.assertEquals(expected_content, page['content'])
+
+ def test_fetch_console(self):
+ test_dir = os.path.join(TEST_DIR, 'test_fetch_console')
+
+ def fetch_url(url):
+ fr = FetchTestCase.FakeResponse()
+ if url == 'http://build.chromium.org/p/chromium/console':
+ with open(os.path.join(test_dir, 'input.html')) as fh:
+ fr.content = fh.read()
+ return fr
+
+ with open(os.path.join(test_dir, 'expected.html')) as fh:
+ expected_content = fh.read()
+ app.fetch_page(
+ localpath='chromium/console',
+ remoteurl='http://build.chromium.org/p/chromium/console',
+ maxage=60,
+ postfetch=app.console_handler,
+ fetch_url=fetch_url)
+ page = app.get_and_cache_pagedata('chromium/console')
+ # Uncomment if deeper inspection is needed of the returned console.
+ # with open(os.path.join(test_dir, 'expected.html'), 'w') as fh:
+ # fh.write(page['content'])
+ self.assertEquals('interface', page['body_class'])
+ self.assertEquals(expected_content, page['content'])
+ self.assertEquals(
+ 'http://build.chromium.org/p/chromium/console/../',
+ page['offsite_base'])
+ self.assertEquals('BuildBot: Chromium', page['title'])

Powered by Google App Engine
This is Rietveld 408576698