Refactoring _has_context_key
This commit is contained in:
parent
6b00452830
commit
05481fc0c8
@ -1,13 +1,18 @@
|
|||||||
from django.test import Client
|
from django.test import Client
|
||||||
|
|
||||||
class ViewTestCaseMixin:
|
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
|
view = None
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.view_name = self.view.__name__
|
self.view_name = self.view.__name__
|
||||||
self. client = Client()
|
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,
|
self.assertTrue( context_key in response.context,
|
||||||
msg='Expecting the context of %s to have an attribute \'%s\'' % (
|
msg='Expecting the context of %s to have an attribute \'%s\'' % (
|
||||||
self.view_name,
|
self.view_name,
|
||||||
@ -16,7 +21,7 @@ class ViewTestCaseMixin:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def assertHasForm(self, response, context_key, form_class):
|
def assertHasForm(self, response, context_key, form_class):
|
||||||
self._test_has_context_key(response, context_key)
|
self.assertHasContextKey(response, context_key)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
type(response.context[context_key]),
|
type(response.context[context_key]),
|
||||||
form_class,
|
form_class,
|
||||||
|
@ -68,6 +68,6 @@ class TestPlaceListView(ViewTestCaseMixin, TestCase):
|
|||||||
self.client.login(username='testpeter', password='Develop123')
|
self.client.login(username='testpeter', password='Develop123')
|
||||||
response = self.client.get(reverse_lazy('place_list'))
|
response = self.client.get(reverse_lazy('place_list'))
|
||||||
|
|
||||||
self._test_has_context_key(response, 'map_config')
|
self.assertHasContextKey(response, 'map_config')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user