Skip to content
Browse files

Added TestCaseBase to isolate templates from project TEMPLATE_DIRS

When running tests in a project with TEMPLATE_DIRS pointing at templates that
involve project level ROOT_URLCONF things blow up. This was a big issue for
Pinax as the test cases were isolating URLs, but templates still depended on
project ROOT_URLCONF.
  • Loading branch information...
1 parent d287d87 commit 2281d940a7e00dc2cca522162dfba6b1d77e603d @brosner committed Nov 29, 2009
Showing with 28 additions and 4 deletions.
  1. +6 −1 django_openid/tests/auth_tests.py
  2. +18 −0 django_openid/tests/base.py
  3. +4 −3 django_openid/tests/consumer_tests.py
View
7 django_openid/tests/auth_tests.py
@@ -9,14 +9,16 @@
from django.contrib.auth.models import User
from django.utils.decorators import decorator_from_middleware
+
+from base import TestCaseBase
from request_factory import RequestFactory
from openid_mocks import *
from openid.consumer import consumer as janrain_consumer
rf = RequestFactory()
-class AuthTestBase(TestCase):
+class AuthTestBase(TestCaseBase):
urls = 'django_openid.tests.auth_test_urls'
def setUp(self):
@@ -29,6 +31,8 @@ def setUp(self):
'django_openid.registration.RegistrationConsumer',
)
+ super(AuthTestBase, self).setUp()
+
# Create user accounts associated with OpenIDs
self.no_openids = User.objects.create(
username = 'noopenids',
@@ -44,6 +48,7 @@ def setUp(self):
def tearDown(self):
settings.MIDDLEWARE_CLASSES = self.old_middleware
+ super(AuthTestBase, self).tearDown()
class AuthTest(AuthTestBase):
View
18 django_openid/tests/base.py
@@ -0,0 +1,18 @@
+import os
+
+from django.conf import settings
+from django.test import TestCase
+
+import django_openid
+
+
+class TestCaseBase(TestCase):
+
+ def setUp(self):
+ self.old_template_dirs = settings.TEMPLATE_DIRS
+ settings.TEMPLATE_DIRS = (
+ os.path.join(os.path.dirname(django_openid.__file__), "templates"),
+ )
+
+ def tearDown(self):
+ settings.TEMPLATE_DIRS = self.old_template_dirs
View
7 django_openid/tests/consumer_tests.py
@@ -3,14 +3,15 @@
from django_openid.consumer import Consumer
from django_openid import signed
+from base import TestCaseBase
from request_factory import RequestFactory
from openid_mocks import *
from openid.consumer import consumer as janrain_consumer
rf = RequestFactory()
-class ConsumerTest(TestCase):
+class ConsumerTest(TestCaseBase):
def testBadMethod(self):
"Non existent methods should result in a 404"
@@ -110,7 +111,7 @@ def testLogo(self):
response = openid_consumer(get, 'logo/')
self.assert_('image/gif' in response['Content-Type'])
-class SessionConsumerTest(TestCase):
+class SessionConsumerTest(TestCaseBase):
def login(self):
openid_consumer = MySessionConsumer()
@@ -142,7 +143,7 @@ def testLogout(self):
self.assertEqual(response['Location'], '/')
self.assertEqual(len(request.session['openids']), 0)
-class CookieConsumerTest(TestCase):
+class CookieConsumerTest(TestCaseBase):
def login(self):
openid_consumer = MyCookieConsumer()

0 comments on commit 2281d94

Please sign in to comment.
Something went wrong with that request. Please try again.