Skip to content
Snippets Groups Projects
Commit 29c72529 authored by Martin Burchell's avatar Martin Burchell
Browse files

Fixed tab rendering to use context

parent 8c0914d1
Branches
No related tags found
2 merge requests!23Tabbed view header styling,!22Tabbed page
......@@ -8,4 +8,6 @@ def render_tab(tab_instance):
template_name = tab.template_name
return render_to_string(template_name, {})
context = tab.get_context_data()
return render_to_string(template_name, context)
......@@ -55,3 +55,21 @@ def test_uses_template_name(render_to_string_method):
mock, 'template_name'
)
assert template_name == 'test-tab-template'
@pytest.mark.django_db
def test_uses_context(render_to_string_method):
test_context = {'is_test_tab': True}
tab = TestTab(context=test_context)
register_tab('test-tab', tab)
page = TabbedPageFactory()
tab_instance = TabInstanceFactory(page=page, name='test-tab')
with patch(render_to_string_method) as mock:
render_tab(tab_instance)
actual_context = get_mock_render_to_string_parameter(
mock, 'context'
)
assert actual_context == test_context
......@@ -2,9 +2,21 @@ import pytest
class TestTab(object):
def __init__(self, template_name=None):
def __init__(self, template_name=None, context=None):
self.template_name = template_name
if context is None:
context = {}
self.context = context
def get_context_data(self, **kwargs):
context = getattr(self, 'context', {})
context['kwargs'] = kwargs
return context
@pytest.fixture
def tab():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment