diff options
author | Felipe Lee <felipe.lee.garcia@gmail.com> | 2019-10-10 00:22:43 -0500 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-10-30 14:43:52 +0100 |
commit | c2c27867ef1d4ad32369f8cda42a6d72b262cae5 (patch) | |
tree | 36b7dec30f45db612dfe97562bc646d2b984c03e /tests/generic_views | |
parent | 31d1822532d716d5b2f1422372d07dd05067bfc6 (diff) | |
download | django-c2c27867ef1d4ad32369f8cda42a6d72b262cae5.tar.gz |
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.
Diffstat (limited to 'tests/generic_views')
-rw-r--r-- | tests/generic_views/test_base.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/tests/generic_views/test_base.py b/tests/generic_views/test_base.py index f6479d858c..c1ad30526e 100644 --- a/tests/generic_views/test_base.py +++ b/tests/generic_views/test_base.py @@ -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. |