Index: chrome/common/extensions/docs/server2/integration_test.py |
diff --git a/chrome/common/extensions/docs/server2/integration_test.py b/chrome/common/extensions/docs/server2/integration_test.py |
index e833f73d6c14669bfea6a4f453df60f033f3f5d0..3f20d2966860a8c945500df9d779c6683f2984c9 100755 |
--- a/chrome/common/extensions/docs/server2/integration_test.py |
+++ b/chrome/common/extensions/docs/server2/integration_test.py |
@@ -3,8 +3,6 @@ |
# Use of this source code is governed by a BSD-style license that can be |
# found in the LICENSE file. |
-from __future__ import print_function |
- |
# Run build_server so that files needed by tests are copied to the local |
# third_party directory. |
import build_server |
@@ -17,20 +15,19 @@ import sys |
import time |
import unittest |
-from cron_servlet import CronServlet |
from local_renderer import LocalRenderer |
-from render_servlet import AlwaysOnline |
-from test_util import DisableLogging |
+from fake_fetchers import ConfigureFakeFetchers |
+from handler import Handler |
+from servlet import Request |
+from test_util import EnableLogging, DisableLogging |
# Arguments set up if __main__ specifies them. |
-_BASE_PATH = os.path.join( |
- os.path.abspath(os.path.dirname(__file__)), os.pardir, os.pardir) |
_EXPLICIT_TEST_FILES = None |
def _GetPublicFiles(): |
'''Gets all public files mapped to their contents. |
''' |
- public_path = os.path.join(_BASE_PATH, 'docs', 'templates', 'public', '') |
+ public_path = os.path.join(sys.path[0], os.pardir, 'templates', 'public') |
public_files = {} |
for path, dirs, files in os.walk(public_path, topdown=True): |
dirs[:] = [d for d in dirs if d != '.svn'] |
@@ -42,8 +39,9 @@ def _GetPublicFiles(): |
class IntegrationTest(unittest.TestCase): |
def setUp(self): |
- self._renderer = LocalRenderer(_BASE_PATH) |
+ ConfigureFakeFetchers() |
+ @EnableLogging('info') |
def testCronAndPublicFiles(self): |
'''Runs cron then requests every public file. Cron needs to be run first |
because the public file requests are offline. |
@@ -54,13 +52,10 @@ class IntegrationTest(unittest.TestCase): |
print('Running cron...') |
start_time = time.time() |
try: |
- logging_info = logging.info |
- logging.info = print |
- response = self._renderer.Render('/stable', servlet=CronServlet) |
+ response = Handler(Request.ForTest('/_cron/stable')).Get() |
self.assertEqual(200, response.status) |
self.assertEqual('Success', response.content.ToString()) |
finally: |
- logging.info = logging_info |
print('Took %s seconds' % (time.time() - start_time)) |
public_files = _GetPublicFiles() |
@@ -76,16 +71,18 @@ class IntegrationTest(unittest.TestCase): |
# that render large files. At least it'll catch zero-length responses. |
self.assertTrue(len(response.content) >= len(content), |
'Content was "%s" when rendering %s' % (response.content, path)) |
- check_result(self._renderer.Render(path)) |
+ check_result(Handler(Request.ForTest(path)).Get()) |
# Samples are internationalized, test some locales. |
if path.endswith('/samples.html'): |
for lang in ['en-US', 'es', 'ar']: |
- check_result(self._renderer.Render( |
- path, headers={'Accept-Language': '%s;q=0.8' % lang})) |
+ check_result(Handler(Request.ForTest( |
+ path, |
+ headers={'Accept-Language': '%s;q=0.8' % lang})).Get()) |
finally: |
print('Took %s seconds' % (time.time() - start_time)) |
- @AlwaysOnline |
+ # TODO(kalman): Move this test elsewhere, it's not an integration test. |
+ # Perhaps like "presubmit_tests" or something. |
def testExplicitFiles(self): |
'''Tests just the files in _EXPLICIT_TEST_FILES. |
''' |
@@ -95,27 +92,23 @@ class IntegrationTest(unittest.TestCase): |
print('Rendering %s...' % filename) |
start_time = time.time() |
try: |
- response = self._renderer.Render(filename) |
+ response = LocalRenderer.Render(filename) |
self.assertEqual(200, response.status) |
self.assertTrue(response.content != '') |
finally: |
print('Took %s seconds' % (time.time() - start_time)) |
@DisableLogging('warning') |
- @AlwaysOnline |
def testFileNotFound(self): |
- response = self._renderer.Render('/extensions/notfound.html') |
+ response = Handler(Request.ForTest('/extensions/notfound.html')).Get() |
self.assertEqual(404, response.status) |
if __name__ == '__main__': |
parser = optparse.OptionParser() |
- parser.add_option('-p', '--path', default=None) |
parser.add_option('-a', '--all', action='store_true', default=False) |
(opts, args) = parser.parse_args() |
if not opts.all: |
_EXPLICIT_TEST_FILES = args |
- if opts.path is not None: |
- _BASE_PATH = opts.path |
# Kill sys.argv because we have our own flags. |
sys.argv = [sys.argv[0]] |
unittest.main() |