From e4708bfbeae2e125aec017a5a4b5ff8a48dc014d Mon Sep 17 00:00:00 2001
From: Martin Burchell <martinb@aptivate.org>
Date: Thu, 6 Aug 2015 12:03:08 +0100
Subject: [PATCH] Refactored tests to use basic html tab

---
 django/website/tabbed_page/tab_pool.py        |  2 +-
 .../website/tabbed_page/tests/render_tests.py | 39 ++++++++++---------
 django/website/tabbed_page/tests/test_tab.py  | 13 +------
 3 files changed, 22 insertions(+), 32 deletions(-)

diff --git a/django/website/tabbed_page/tab_pool.py b/django/website/tabbed_page/tab_pool.py
index cf8e2c7f..36d7d401 100644
--- a/django/website/tabbed_page/tab_pool.py
+++ b/django/website/tabbed_page/tab_pool.py
@@ -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():
diff --git a/django/website/tabbed_page/tests/render_tests.py b/django/website/tabbed_page/tests/render_tests.py
index 98d67ded..67e646df 100644
--- a/django/website/tabbed_page/tests/render_tests.py
+++ b/django/website/tabbed_page/tests/render_tests.py
@@ -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)
 
diff --git a/django/website/tabbed_page/tests/test_tab.py b/django/website/tabbed_page/tests/test_tab.py
index 59e3f8e5..9ece61e0 100644
--- a/django/website/tabbed_page/tests/test_tab.py
+++ b/django/website/tabbed_page/tests/test_tab.py
@@ -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
-- 
GitLab