Refactoring _has_context_key

This commit is contained in:
reverend 2020-09-13 12:41:31 +02:00
parent 6b00452830
commit 05481fc0c8
2 changed files with 8 additions and 3 deletions

View File

@ -1,13 +1,18 @@
from django.test import Client
class ViewTestCaseMixin:
'''
This is a mixni for testing views. It provides functionality to
test the context, forms and HTTP Response of responses.
Also works with django's ReqeustFactory.
'''
view = None
def setUp(self):
self.view_name = self.view.__name__
self. client = Client()
def _test_has_context_key(self, response, context_key):
def assertHasContextKey(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,
@ -16,7 +21,7 @@ class ViewTestCaseMixin:
)
def assertHasForm(self, response, context_key, form_class):
self._test_has_context_key(response, context_key)
self.assertHasContextKey(response, context_key)
self.assertEqual(
type(response.context[context_key]),
form_class,

View File

@ -68,6 +68,6 @@ class TestPlaceListView(ViewTestCaseMixin, TestCase):
self.client.login(username='testpeter', password='Develop123')
response = self.client.get(reverse_lazy('place_list'))
self._test_has_context_key(response, 'map_config')
self.assertHasContextKey(response, 'map_config')