mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +00:00
Refs #20456 -- Moved initialization of HEAD method based on GET to the View.setup() for generic views.
This will ease unit testing of views since setup will essentially do everything needed to set the view instance up (other than instantiating it). Credit for idea goes to Vincent Prouillet.
This commit is contained in:
parent
31d1822532
commit
c2c27867ef
4 changed files with 12 additions and 7 deletions
|
@ -113,6 +113,13 @@ class ViewTest(SimpleTestCase):
|
|||
response = SimpleView.as_view()(self.rf.head('/'))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_setup_get_and_head(self):
|
||||
view_instance = SimpleView()
|
||||
self.assertFalse(hasattr(view_instance, 'head'))
|
||||
view_instance.setup(self.rf.get('/'))
|
||||
self.assertTrue(hasattr(view_instance, 'head'))
|
||||
self.assertEqual(view_instance.head, view_instance.get)
|
||||
|
||||
def test_head_no_get(self):
|
||||
"""
|
||||
Test a view which supplies no GET method responds to HEAD with HTTP 405.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue