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

Refactored tests to use basic html tab

parent 99e868e1
No related branches found
No related tags found
2 merge requests!23Tabbed view header styling,!22Tabbed page
......@@ -16,7 +16,7 @@ def get_tab(name):
try:
return _pool[name]
except KeyError:
raise MissingTabError()
raise MissingTabError("Tab named '%s' has not been registered" % name)
def clear_tabs():
......
......@@ -5,10 +5,9 @@ from .factories import (
TabbedPageFactory,
TabInstanceFactory,
)
from ..tab_pool import register_tab
from ..templatetags.render_tab import render_tab
from .test_tab import TestTab
from ..tab_pool import register_tab, BasicHtmlTab
from ..templatetags.render_tab import render_tab
class MockTabInstance(object):
......@@ -21,16 +20,16 @@ render_to_string_method = 'tabbed_page.templatetags.render_tab.render_to_string'
@pytest.mark.django_db
@patch(render_to_string_method)
def test_uses_template_name(mock_render):
tab = TestTab(template_name='test-tab-template')
register_tab('test-tab', tab)
tab = BasicHtmlTab()
register_tab('basic-html-tab', tab)
page = TabbedPageFactory()
tab_instance = TabInstanceFactory(page=page, view_name='test-tab')
tab_instance = TabInstanceFactory(page=page, view_name='basic-html-tab')
render_tab(None, tab_instance)
args, _ = mock_render.call_args
assert args[0] == 'test-tab-template'
assert args[0] == tab.template_name
@pytest.mark.django_db
......@@ -38,14 +37,16 @@ def test_uses_template_name(mock_render):
def test_uses_context(mock_render):
test_context = {'is_test_tab': True}
tab = TestTab(context=test_context)
register_tab('test-tab', tab)
with patch.object(BasicHtmlTab, 'get_context_data') as mock_get_context:
mock_get_context.return_value = test_context
page = TabbedPageFactory()
tab = BasicHtmlTab()
register_tab('basic-html-tab', tab)
tab_instance = TabInstanceFactory(page=page, view_name='test-tab')
page = TabbedPageFactory()
tab_instance = TabInstanceFactory(page=page, view_name='basic-html-tab')
render_tab(None, tab_instance)
render_tab(None, tab_instance)
_, kwargs = mock_render.call_args
assert kwargs['context'] == test_context
......@@ -54,11 +55,11 @@ def test_uses_context(mock_render):
@pytest.mark.django_db
@patch(render_to_string_method)
def test_uses_request(mock_render):
tab = TestTab()
register_tab('test-tab', tab)
tab = BasicHtmlTab()
register_tab('basic-html-tab', tab)
page = TabbedPageFactory()
tab_instance = TabInstanceFactory(page=page, view_name='test-tab')
tab_instance = TabInstanceFactory(page=page, view_name='basic-html-tab')
request = 'a request'
context = {'request': request}
......@@ -71,15 +72,15 @@ def test_uses_request(mock_render):
@pytest.mark.django_db
@patch(render_to_string_method)
def test_settings_passed_to_widget_get_context_data(render_to_string_method):
with patch.object(TestTab, 'get_context_data') as mock_get_context:
tab = TestTab()
register_tab('test-tab', tab)
with patch.object(BasicHtmlTab, 'get_context_data') as mock_get_context:
tab = BasicHtmlTab()
register_tab('basic-html-tab', tab)
page = TabbedPageFactory()
columns = ['body', 'timestamp', 'network_provider']
settings = {'columns': columns}
tab_instance = TabInstanceFactory(page=page,
view_name='test-tab',
view_name='basic-html-tab',
settings=settings)
render_tab(None, tab_instance)
......
......@@ -2,18 +2,7 @@ import pytest
class TestTab(object):
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', {})
return context
pass
@pytest.fixture
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment