', not '
', response.content)
+ self.assertFalse(match is None)
+ id_repr = match.group('id')
+ self.assertFalse(re.search(b'[^c\d]', id_repr),
+ "Numeric IDs in debug response HTML page shouldn't be localized (value: %s)." % id_repr)
+
def test_template_exceptions(self):
for n in range(len(except_args)):
try:
diff --git a/tests/view_tests/tests/test_i18n.py b/tests/view_tests/tests/test_i18n.py
index cfee4f5093a..50677947b6b 100644
--- a/tests/view_tests/tests/test_i18n.py
+++ b/tests/view_tests/tests/test_i18n.py
@@ -85,20 +85,18 @@ class JsI18NTests(TestCase):
languages and you've set settings.LANGUAGE_CODE to some other language
than English.
"""
- with self.settings(LANGUAGE_CODE='es'):
- with override('en-us'):
- response = self.client.get('/views/jsi18n/')
- self.assertNotContains(response, 'esto tiene que ser traducido')
+ with self.settings(LANGUAGE_CODE='es'), override('en-us'):
+ response = self.client.get('/views/jsi18n/')
+ self.assertNotContains(response, 'esto tiene que ser traducido')
def test_jsi18n_fallback_language(self):
"""
Let's make sure that the fallback language is still working properly
in cases where the selected language cannot be found.
"""
- with self.settings(LANGUAGE_CODE='fr'):
- with override('fi'):
- response = self.client.get('/views/jsi18n/')
- self.assertContains(response, 'il faut le traduire')
+ with self.settings(LANGUAGE_CODE='fr'), override('fi'):
+ response = self.client.get('/views/jsi18n/')
+ self.assertContains(response, 'il faut le traduire')
def testI18NLanguageNonEnglishDefault(self):
"""
@@ -107,10 +105,9 @@ class JsI18NTests(TestCase):
is English and there is not 'en' translation available. See #13388,
#3594 and #13726 for more details.
"""
- with self.settings(LANGUAGE_CODE='fr'):
- with override('en-us'):
- response = self.client.get('/views/jsi18n/')
- self.assertNotContains(response, 'Choisir une heure')
+ with self.settings(LANGUAGE_CODE='fr'), override('en-us'):
+ response = self.client.get('/views/jsi18n/')
+ self.assertNotContains(response, 'Choisir une heure')
def test_nonenglish_default_english_userpref(self):
"""
@@ -119,20 +116,19 @@ class JsI18NTests(TestCase):
with the proper English translations. See #13726 for more details.
"""
extended_apps = list(settings.INSTALLED_APPS) + ['view_tests.app0']
- with self.settings(LANGUAGE_CODE='fr', INSTALLED_APPS=extended_apps):
- with override('en-us'):
- response = self.client.get('/views/jsi18n_english_translation/')
- self.assertContains(response, javascript_quote('this app0 string is to be translated'))
+ with self.settings(LANGUAGE_CODE='fr', INSTALLED_APPS=extended_apps), \
+ override('en-us'):
+ response = self.client.get('/views/jsi18n_english_translation/')
+ self.assertContains(response, javascript_quote('this app0 string is to be translated'))
def testI18NLanguageNonEnglishFallback(self):
"""
Makes sure that the fallback language is still working properly
in cases where the selected language cannot be found.
"""
- with self.settings(LANGUAGE_CODE='fr'):
- with override('none'):
- response = self.client.get('/views/jsi18n/')
- self.assertContains(response, 'Choisir une heure')
+ with self.settings(LANGUAGE_CODE='fr'), override('none'):
+ response = self.client.get('/views/jsi18n/')
+ self.assertContains(response, 'Choisir une heure')
class JsI18NTestsMultiPackage(TestCase):
@@ -149,10 +145,11 @@ class JsI18NTestsMultiPackage(TestCase):
#3594 and #13514 for more details.
"""
extended_apps = list(settings.INSTALLED_APPS) + ['view_tests.app1', 'view_tests.app2']
- with self.settings(LANGUAGE_CODE='en-us', INSTALLED_APPS=extended_apps):
- with override('fr'):
- response = self.client.get('/views/jsi18n_multi_packages1/')
- self.assertContains(response, javascript_quote('il faut traduire cette chaîne de caractères de app1'))
+ with self.settings(LANGUAGE_CODE='en-us', INSTALLED_APPS=extended_apps), \
+ override('fr'):
+ response = self.client.get('/views/jsi18n_multi_packages1/')
+ self.assertContains(response,
+ javascript_quote('il faut traduire cette chaîne de caractères de app1'))
def testI18NDifferentNonEnLangs(self):
"""
@@ -160,20 +157,21 @@ class JsI18NTestsMultiPackage(TestCase):
English.
"""
extended_apps = list(settings.INSTALLED_APPS) + ['view_tests.app3', 'view_tests.app4']
- with self.settings(LANGUAGE_CODE='fr', INSTALLED_APPS=extended_apps):
- with override('es-ar'):
- response = self.client.get('/views/jsi18n_multi_packages2/')
- self.assertContains(response, javascript_quote('este texto de app3 debe ser traducido'))
+ with self.settings(LANGUAGE_CODE='fr', INSTALLED_APPS=extended_apps), \
+ override('es-ar'):
+ response = self.client.get('/views/jsi18n_multi_packages2/')
+ self.assertContains(response,
+ javascript_quote('este texto de app3 debe ser traducido'))
def testI18NWithLocalePaths(self):
extended_locale_paths = settings.LOCALE_PATHS + (
path.join(path.dirname(
path.dirname(path.abspath(upath(__file__)))), 'app3', 'locale'),)
- with self.settings(LANGUAGE_CODE='es-ar', LOCALE_PATHS=extended_locale_paths):
- with override('es-ar'):
- response = self.client.get('/views/jsi18n/')
- self.assertContains(response,
- javascript_quote('este texto de app3 debe ser traducido'))
+ with self.settings(LANGUAGE_CODE='es-ar', LOCALE_PATHS=extended_locale_paths), \
+ override('es-ar'):
+ response = self.client.get('/views/jsi18n/')
+ self.assertContains(response,
+ javascript_quote('este texto de app3 debe ser traducido'))
skip_selenium = not os.environ.get('DJANGO_SELENIUM_TESTS', False)
diff --git a/tests/view_tests/tests/test_static.py b/tests/view_tests/tests/test_static.py
index d2f3f47fa70..8f67890c116 100644
--- a/tests/view_tests/tests/test_static.py
+++ b/tests/view_tests/tests/test_static.py
@@ -6,7 +6,7 @@ import unittest
from django.conf.urls.static import static
from django.http import HttpResponseNotModified
-from django.test import TestCase
+from django.test import SimpleTestCase
from django.test.utils import override_settings
from django.utils.http import http_date
from django.views.static import was_modified_since
@@ -16,7 +16,7 @@ from ..urls import media_dir
@override_settings(DEBUG=True)
-class StaticTests(TestCase):
+class StaticTests(SimpleTestCase):
"""Tests django views in django/views/static.py"""
prefix = 'site_media'
@@ -94,6 +94,10 @@ class StaticTests(TestCase):
self.assertEqual(len(response_content),
int(response['Content-Length']))
+ def test_404(self):
+ response = self.client.get('/views/%s/non_existing_resource' % self.prefix)
+ self.assertEqual(404, response.status_code)
+
class StaticHelperTest(StaticTests):
"""
diff --git a/tests/view_tests/urls.py b/tests/view_tests/urls.py
index f2c910368d7..4db3e262ed2 100644
--- a/tests/view_tests/urls.py
+++ b/tests/view_tests/urls.py
@@ -49,6 +49,7 @@ urlpatterns = patterns('',
(r'raises400/$', views.raises400),
(r'raises403/$', views.raises403),
(r'raises404/$', views.raises404),
+ (r'raises500/$', views.raises500),
# i18n views
(r'^i18n/', include('django.conf.urls.i18n')),
diff --git a/tests/view_tests/views.py b/tests/view_tests/views.py
index 0bac7d93218..04924bc9f7a 100644
--- a/tests/view_tests/views.py
+++ b/tests/view_tests/views.py
@@ -31,6 +31,14 @@ def raises(request):
except Exception:
return technical_500_response(request, *sys.exc_info())
+def raises500(request):
+ # We need to inspect the HTML generated by the fancy 500 debug view but
+ # the test client ignores it, so we send it explicitly.
+ try:
+ raise Exception
+ except Exception:
+ return technical_500_response(request, *sys.exc_info())
+
def raises400(request):
raise SuspiciousOperation