diff options
author | Tim Graham <timograham@gmail.com> | 2016-06-28 11:21:26 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-28 11:21:26 -0400 |
commit | c9ae09addffb839403312131d4251e9d8b454508 (patch) | |
tree | 74913fbe2e90d88e094f8594947ebf313ec5f12f /tests/test_client_regress | |
parent | c1b6f554e405fe733e8d80f7e3d77c277810e707 (diff) | |
download | django-c9ae09addffb839403312131d4251e9d8b454508.tar.gz |
Replaced use of TestCase.fail() with assertRaises().
Also removed try/except/fail antipattern that hides exceptions.
Diffstat (limited to 'tests/test_client_regress')
-rw-r--r-- | tests/test_client_regress/tests.py | 21 |
1 files changed, 4 insertions, 17 deletions
diff --git a/tests/test_client_regress/tests.py b/tests/test_client_regress/tests.py index d03b2d14e9..c45afc1244 100644 --- a/tests/test_client_regress/tests.py +++ b/tests/test_client_regress/tests.py @@ -875,21 +875,15 @@ class ExceptionTests(TestDataMixin, TestCase): login = self.client.login(username='testclient', password='password') self.assertTrue(login, 'Could not log in') - try: + with self.assertRaises(CustomTestException): self.client.get("/staff_only/") - self.fail("General users should not be able to visit this page") - except CustomTestException: - pass # At this point, an exception has been raised, and should be cleared. # This next operation should be successful; if it isn't we have a problem. login = self.client.login(username='staff', password='password') self.assertTrue(login, 'Could not log in') - try: - self.client.get("/staff_only/") - except CustomTestException: - self.fail("Staff should be able to visit this page") + self.client.get("/staff_only/") @override_settings(ROOT_URLCONF='test_client_regress.urls') @@ -901,12 +895,8 @@ class TemplateExceptionTests(SimpleTestCase): }]) def test_bad_404_template(self): "Errors found when rendering 404 error templates are re-raised" - try: + with self.assertRaises(TemplateSyntaxError): self.client.get("/no_such_view/") - except TemplateSyntaxError: - pass - else: - self.fail("Should get error about syntax error in template") # We need two different tests to check URLconf substitution - one to check @@ -945,11 +935,8 @@ class ContextTests(TestDataMixin, TestCase): self.assertEqual(response.context['get-foo'], 'whiz') self.assertEqual(response.context['data'], 'sausage') - try: + with self.assertRaisesMessage(KeyError, 'does-not-exist'): response.context['does-not-exist'] - self.fail('Should not be able to retrieve non-existent key') - except KeyError as e: - self.assertEqual(e.args[0], 'does-not-exist') def test_inherited_context(self): "Context variables can be retrieved from a list of contexts" |