Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Cleaned up test_client_regress tests

  • Loading branch information...
commit ea4e0aad9efd691aa200bf7bbabd282267234b3a 1 parent 4553f51
Claude Paroz claudep authored
39 tests/regressiontests/test_client_regress/tests.py
View
@@ -17,14 +17,10 @@
from django.http import HttpResponse
+@override_settings(
+ TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__), 'templates'),)
+)
class AssertContainsTests(TestCase):
- def setUp(self):
- self.old_templates = settings.TEMPLATE_DIRS
- settings.TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__), 'templates'),)
-
- def tearDown(self):
- settings.TEMPLATE_DIRS = self.old_templates
-
def test_contains(self):
"Responses can be inspected for content, including counting repeated substrings"
response = self.client.get('/test_client_regress/no_template_view/')
@@ -544,17 +540,13 @@ def test_login_different_client(self):
self.assertRedirects(response, "http://testserver/test_client_regress/get_view/")
-@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
+@override_settings(
+ PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',),
+ SESSION_ENGINE='regressiontests.test_client_regress.session'
+)
class SessionEngineTests(TestCase):
fixtures = ['testdata']
- def setUp(self):
- self.old_SESSION_ENGINE = settings.SESSION_ENGINE
- settings.SESSION_ENGINE = 'regressiontests.test_client_regress.session'
-
- def tearDown(self):
- settings.SESSION_ENGINE = self.old_SESSION_ENGINE
-
def test_login(self):
"A session engine that modifies the session key can be used to log in"
login = self.client.login(username='testclient', password='password')
@@ -616,6 +608,8 @@ def test_exception_cleared(self):
except SuspiciousOperation:
self.fail("Staff should be able to visit this page")
+
+@override_settings(TEMPLATE_DIRS=())
class TemplateExceptionTests(TestCase):
def setUp(self):
# Reset the loaders so they don't try to render cached templates.
@@ -623,11 +617,6 @@ def setUp(self):
for template_loader in loader.template_source_loaders:
if hasattr(template_loader, 'reset'):
template_loader.reset()
- self.old_templates = settings.TEMPLATE_DIRS
- settings.TEMPLATE_DIRS = ()
-
- def tearDown(self):
- settings.TEMPLATE_DIRS = self.old_templates
def test_no_404_template(self):
"Missing templates are correctly reported by test client"
@@ -980,11 +969,8 @@ class RequestFactoryStateTest(TestCase):
# run the tests individually, and if any are failing it is confusing to run
# them with any other set of tests.
- def setUp(self):
- self.factory = RequestFactory()
-
def common_test_that_should_always_pass(self):
- request = self.factory.get('/')
+ request = RequestFactory().get('/')
request.session = {}
self.assertFalse(hasattr(request, 'user'))
@@ -1007,11 +993,8 @@ class RequestFactoryEnvironmentTests(TestCase):
are set correctly in RequestFactory.
"""
- def setUp(self):
- self.factory = RequestFactory()
-
def test_should_set_correct_env_variables(self):
- request = self.factory.get('/path/')
+ request = RequestFactory().get('/path/')
self.assertEqual(request.META.get('REMOTE_ADDR'), '127.0.0.1')
self.assertEqual(request.META.get('SERVER_NAME'), 'testserver')
5 tests/regressiontests/test_client_regress/views.py
View
@@ -5,7 +5,6 @@
from django.http import HttpResponse, HttpResponseRedirect
from django.core.exceptions import SuspiciousOperation
from django.shortcuts import render_to_response
-from django.utils.encoding import smart_str
from django.core.serializers.json import DjangoJSONEncoder
from django.test.client import CONTENT_TYPE_RE
from django.template import RequestContext
@@ -84,8 +83,8 @@ def return_json_file(request):
obj_json = json.dumps(obj_dict, encoding=charset,
cls=DjangoJSONEncoder,
ensure_ascii=False)
- response = HttpResponse(smart_str(obj_json, encoding=charset), status=200,
- mimetype='application/json; charset=' + charset)
+ response = HttpResponse(obj_json.encode(charset), status=200,
+ mimetype='application/json; charset=%s' % charset)
response['Content-Disposition'] = 'attachment; filename=testfile.json'
return response
Please sign in to comment.
Something went wrong with that request. Please try again.