diff options
author | Hasan <hasan.r67@gmail.com> | 2016-01-17 14:56:39 +0330 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2016-01-29 12:32:18 -0500 |
commit | 3d0dcd7f5af378d3ab6adb303b913e6c7b2e0ee5 (patch) | |
tree | 0d1074cc65a72096e44a4165611fddfc5b7ef7fb /tests/sites_tests | |
parent | 575706331bec4bf58ce36a9540c4c61fca49025b (diff) | |
download | django-3d0dcd7f5af378d3ab6adb303b913e6c7b2e0ee5.tar.gz |
Refs #26022 -- Used context manager version of assertRaises in tests.
Diffstat (limited to 'tests/sites_tests')
-rw-r--r-- | tests/sites_tests/tests.py | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/tests/sites_tests/tests.py b/tests/sites_tests/tests.py index 6bf7ce4d0b..ffd6223866 100644 --- a/tests/sites_tests/tests.py +++ b/tests/sites_tests/tests.py @@ -35,7 +35,8 @@ class SitesFrameworkTests(TestCase): s = Site.objects.get_current() self.assertIsInstance(s, Site) s.delete() - self.assertRaises(ObjectDoesNotExist, Site.objects.get_current) + with self.assertRaises(ObjectDoesNotExist): + Site.objects.get_current() def test_site_cache(self): # After updating a Site object (e.g. via the admin), we shouldn't return a @@ -53,7 +54,8 @@ class SitesFrameworkTests(TestCase): # be cleared and get_current() should raise a DoesNotExist. self.assertIsInstance(Site.objects.get_current(), Site) Site.objects.all().delete() - self.assertRaises(Site.DoesNotExist, Site.objects.get_current) + with self.assertRaises(Site.DoesNotExist): + Site.objects.get_current() @override_settings(ALLOWED_HOSTS=['example.com']) def test_get_current_site(self): @@ -70,7 +72,8 @@ class SitesFrameworkTests(TestCase): # Test that an exception is raised if the sites framework is installed # but there is no matching Site site.delete() - self.assertRaises(ObjectDoesNotExist, get_current_site, request) + with self.assertRaises(ObjectDoesNotExist): + get_current_site(request) # A RequestSite is returned if the sites framework is not installed with self.modify_settings(INSTALLED_APPS={'remove': 'django.contrib.sites'}): @@ -112,7 +115,8 @@ class SitesFrameworkTests(TestCase): # Host header with non-matching domain request.META = {'HTTP_HOST': 'example.net'} - self.assertRaises(ObjectDoesNotExist, get_current_site, request) + with self.assertRaises(ObjectDoesNotExist): + get_current_site(request) # Ensure domain for RequestSite always matches host header with self.modify_settings(INSTALLED_APPS={'remove': 'django.contrib.sites'}): @@ -128,11 +132,14 @@ class SitesFrameworkTests(TestCase): # Regression for #17320 # Domain names are not allowed contain whitespace characters site = Site(name="test name", domain="test test") - self.assertRaises(ValidationError, site.full_clean) + with self.assertRaises(ValidationError): + site.full_clean() site.domain = "test\ttest" - self.assertRaises(ValidationError, site.full_clean) + with self.assertRaises(ValidationError): + site.full_clean() site.domain = "test\ntest" - self.assertRaises(ValidationError, site.full_clean) + with self.assertRaises(ValidationError): + site.full_clean() def test_clear_site_cache(self): request = HttpRequest() |