Testing improvements.

Fixes bug 903349 -- sets socket timeout and overrides httplib2 connection
method so that escaping external URI calls don't sit around forever.

Fixes bug 894776 -- run_tests.sh properly respects the -N flag again.

Change-Id: I979f49f065021cb91d8b9d01b6a36f78de1897df
This commit is contained in:
Gabriel Hurley 2011-12-12 11:34:42 -08:00
parent 17b02f9e6e
commit c63d0973fa
3 changed files with 30 additions and 15 deletions

View File

@ -25,6 +25,7 @@ from django import shortcuts
from django import test as django_test from django import test as django_test
from django import template as django_template from django import template as django_template
from django.conf import settings from django.conf import settings
import httplib2
import mox import mox
from horizon import context_processors from horizon import context_processors
@ -114,6 +115,13 @@ class TestCase(django_test.TestCase):
def setUp(self): def setUp(self):
self.mox = mox.Mox() self.mox = mox.Mox()
def fake_conn_request(*args, **kwargs):
raise Exception("An external URI request tried to escape through "
"an httplib2 client. Args: %s, kwargs: %s"
% (args, kwargs))
self._real_conn_request = httplib2.Http._conn_request
httplib2.Http._conn_request = fake_conn_request
self._real_horizon_context_processor = context_processors.horizon self._real_horizon_context_processor = context_processors.horizon
context_processors.horizon = lambda request: self.TEST_CONTEXT context_processors.horizon = lambda request: self.TEST_CONTEXT
@ -127,6 +135,7 @@ class TestCase(django_test.TestCase):
def tearDown(self): def tearDown(self):
self.mox.UnsetStubs() self.mox.UnsetStubs()
httplib2.Http._conn_request = self._real_conn_request
context_processors.horizon = self._real_horizon_context_processor context_processors.horizon = self._real_horizon_context_processor
users.get_user_from_request = self._real_get_user_from_request users.get_user_from_request = self._real_get_user_from_request
self.mox.VerifyAll() self.mox.VerifyAll()

View File

@ -19,6 +19,9 @@
# under the License. # under the License.
import os import os
import socket
socket.setdefaulttimeout(1)
ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
DEBUG = True DEBUG = True

View File

@ -209,21 +209,24 @@ function environment_check {
function sanity_check { function sanity_check {
# Anything that should be determined prior to running the tests, server, etc. # Anything that should be determined prior to running the tests, server, etc.
if [ ! -e ${venv} ]; then # Don't sanity-check anything environment-related in -N flag is set
echo "Virtualenv not found at openstack-dashboard/.dashboard-venv. Did install_venv.py succeed?" if [ $never_venv -eq 0 ]; then
exit 1 if [ ! -e ${venv} ]; then
fi echo "Virtualenv not found at openstack-dashboard/.dashboard-venv. Did install_venv.py succeed?"
if [ ! -f horizon/bin/test ]; then exit 1
echo "Error: Test script not found at horizon/bin/test. Did buildout succeed?" fi
exit 1 if [ ! -f horizon/bin/test ]; then
fi echo "Error: Test script not found at horizon/bin/test. Did buildout succeed?"
if [ ! -f horizon/bin/coverage ]; then exit 1
echo "Error: Coverage script not found at horizon/bin/coverage. Did buildout succeed?" fi
exit 1 if [ ! -f horizon/bin/coverage ]; then
fi echo "Error: Coverage script not found at horizon/bin/coverage. Did buildout succeed?"
if [ ! -f horizon/bin/seleniumrc ]; then exit 1
echo "Error: Selenium script not found at horizon/bin/seleniumrc. Did buildout succeed?" fi
exit 1 if [ ! -f horizon/bin/seleniumrc ]; then
echo "Error: Selenium script not found at horizon/bin/seleniumrc. Did buildout succeed?"
exit 1
fi
fi fi
} }