mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Refs #26022 -- Used context manager version of assertRaises in tests.
This commit is contained in:
parent
575706331b
commit
3d0dcd7f5a
118 changed files with 1086 additions and 760 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue