From 26286984c22abeec78f712b884ecc814162093f2 Mon Sep 17 00:00:00 2001 From: reverend Date: Sat, 12 Sep 2020 11:02:23 +0200 Subject: [PATCH] Base functions for testing views --- .../lostplaces_app/tests/views/__init__.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lostplaces/lostplaces_app/tests/views/__init__.py b/lostplaces/lostplaces_app/tests/views/__init__.py index e69de29..689e3d6 100644 --- a/lostplaces/lostplaces_app/tests/views/__init__.py +++ b/lostplaces/lostplaces_app/tests/views/__init__.py @@ -0,0 +1,28 @@ +from django.test import Client + +class ViewTestCase: + view = None + + def setUp(self): + self.view_name = self.view.__name__ + self. client = Client() + + def _test_has_context_key(self, response, context_key): + self.assertTrue( context_key in response.context, + msg='Expecting the context of %s to have an attribute \'%s\'' % ( + self.view_name, + context_key + ) + ) + + def _test_form(self, response, context_key, form_class): + self._test_has_context_key(response, context_key) + self.assertEqual( + type(response.context[context_key]), + form_class, + msg='Expecting %s\'s context.%s to be of the type %s' % ( + self.view_name, + context_key, + form_class.__name__ + ) + ) \ No newline at end of file