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:
Felipe Lee 2019-10-10 00:22:43 -05:00 committed by Mariusz Felisiak
parent 31d1822532
commit c2c27867ef
4 changed files with 12 additions and 7 deletions

View file

@ -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.