Refs #26022 -- Used context manager version of assertRaises in tests.

This commit is contained in:
Hasan 2016-01-17 14:56:39 +03:30 committed by Tim Graham
parent 575706331b
commit 3d0dcd7f5a
118 changed files with 1086 additions and 760 deletions

View file

@ -145,12 +145,14 @@ class ViewTest(unittest.TestCase):
# Check each of the allowed method names
for method in SimpleView.http_method_names:
kwargs = dict(((method, "value"),))
self.assertRaises(TypeError, SimpleView.as_view, **kwargs)
with self.assertRaises(TypeError):
SimpleView.as_view(**kwargs)
# Check the case view argument is ok if predefined on the class...
CustomizableView.as_view(parameter="value")
# ...but raises errors otherwise.
self.assertRaises(TypeError, CustomizableView.as_view, foobar="value")
with self.assertRaises(TypeError):
CustomizableView.as_view(foobar="value")
def test_calling_more_than_once(self):
"""
@ -280,7 +282,8 @@ class TemplateViewTest(SimpleTestCase):
"""
A template view must provide a template name.
"""
self.assertRaises(ImproperlyConfigured, self.client.get, '/template/no_template/')
with self.assertRaises(ImproperlyConfigured):
self.client.get('/template/no_template/')
@require_jinja2
def test_template_engine(self):
@ -527,4 +530,5 @@ class SingleObjectTemplateResponseMixinTest(unittest.TestCase):
TemplateDoesNotExist.
"""
view = views.TemplateResponseWithoutTemplate()
self.assertRaises(ImproperlyConfigured, view.get_template_names)
with self.assertRaises(ImproperlyConfigured):
view.get_template_names()