Changeset - f03d215e52f1
[Not reviewed]
default
0 6 0
Branko Majic (branko) - 6 years ago 2017-12-20 16:43:47
branko@majic.rs
CONNT-31: Fix incorrect version requirement for Django Crispy Forms:

- Implemented test helper for verifying that no exceptions are thrown when
responses are being rendered.
- Updated all tests related to views that render responses to use the new
mixin.
- Updated development requiremnts to use correct version of package.
- Updated setup script ti require lower version of package.
6 files changed with 91 insertions and 24 deletions:
0 comments (0 inline, 0 general)
conntrackt/tests/helpers.py
Show inline comments
 
@@ -181,6 +181,58 @@ class FakeMessages(object):
 
    def add(self, level, message, extra_tags):
 
        """
 
        Adds a message.
 
        """
 

	
 
        self.messages.append(message)
 

	
 

	
 
class RenderTestMixin(object):
 
    """
 
    Mixin class for testing that response rendering works correctly.
 

	
 
    In order to use this mixin, add it the left side of the class list the test
 
    is inheriting from, and configure it providing the following class options:
 

	
 
    view_class - Class used for the CBV that will be tested.
 
    view_function - View function that will be tested.
 
    render_test_view_args - Positional arguments to pass to the view.
 
    render_test_view_kwargs - Keyword arguments to pass to the view.
 
    """
 

	
 
    view_class = None
 
    view_function = None
 
    render_test_view_args = ()
 
    render_test_view_kwargs = {}
 

	
 
    def __init__(self, *args, **kwargs):
 
        """
 
        Initialises the mixin. Takes care of some basic validation of
 
        passed configuration options.
 
        """
 

	
 
        super(RenderTestMixin, self).__init__(*args, **kwargs)
 

	
 
        if self.view_class is None and self.view_function is None:
 
            raise ValueError("Render test mixin configured improperly - no CBV class or function was supplied via parameters 'view_class' or 'view_function'.")
 

	
 
        if type(self.render_test_view_kwargs) is not dict:
 
            raise ValueError("Render test mixin configured improperly - parameter 'render_test_view_kwargs' must be a dictionary.")
 

	
 
        if type(self.render_test_view_args) is not tuple:
 
            raise ValueError("Render test mixin configured improperly - parameter 'render_test_view_args' must be a tuple.")
 

	
 
    def test_no_render_exception_thrown_on_GET(self):
 

	
 
        # Get the view.
 
        if self.view_class is not None:
 
            view = self.view_class.as_view()
 
        elif self.view_function is not None:
 
            view = self.view_function
 

	
 
        # Grab the response.
 
        args = self.render_test_view_args
 
        kwargs = self.render_test_view_kwargs
 
        response = generate_get_response(view, *args, **kwargs)
 

	
 
        # Should not raise.
 
        response.render()
conntrackt/tests/test_views.py
Show inline comments
 
@@ -46,18 +46,18 @@ from conntrackt.views import LocationCre
 
from conntrackt.views import EntityView, EntityCreateView, EntityUpdateView, EntityDeleteView
 
from conntrackt.views import InterfaceCreateView, InterfaceUpdateView, InterfaceDeleteView
 
from conntrackt.views import CommunicationCreateView, CommunicationUpdateView, CommunicationDeleteView
 

	
 
# Test imports.
 
from .forms import FormWithWidgetCSSClassFormMixin, FormWithPlaceholderFormMixin
 
from .helpers import PermissionTestMixin, create_get_request, generate_get_response, FakeMessages
 
from .helpers import PermissionTestMixin, RenderTestMixin, create_get_request, generate_get_response, FakeMessages
 
from .views import RedirectToNextMixinView
 
from .factories import setup_test_data
 

	
 

	
 
class IndexViewTest(PermissionTestMixin, TestCase):
 
class IndexViewTest(RenderTestMixin, PermissionTestMixin, TestCase):
 

	
 
    sufficient_permissions = ("view",)
 
    view_class = IndexView
 

	
 
    def setUp(self):
 
        """
 
@@ -127,16 +127,17 @@ class IndexViewTest(PermissionTestMixin,
 
        response = generate_get_response(view)
 

	
 
        # Validate the response.
 
        self.assertQuerysetEqual(response.context_data["locations"], ["<Location: Test Location 1>", "<Location: Test Location 2>"])
 

	
 

	
 
class ProjectViewTest(PermissionTestMixin, TestCase):
 
class ProjectViewTest(RenderTestMixin, PermissionTestMixin, TestCase):
 

	
 
    sufficient_permissions = ("view",)
 
    permission_test_view_kwargs = {"pk": "1"}
 
    render_test_view_kwargs = {"pk": "1"}
 
    view_class = ProjectView
 

	
 
    def setUp(self):
 
        """
 
        Set-up some test data.
 
        """
 
@@ -180,17 +181,18 @@ class ProjectViewTest(PermissionTestMixi
 
        self.assertEqual(str(response.context_data["project"]), "Test Project 1")
 

	
 
        # Validate context data is present.
 
        self.assertIn("communications", response.context_data.keys())
 

	
 

	
 
class EntityViewTest(PermissionTestMixin, TestCase):
 
class EntityViewTest(RenderTestMixin, PermissionTestMixin, TestCase):
 

	
 
    view_class = EntityView
 
    sufficient_permissions = ("view",)
 
    permission_test_view_kwargs = {"pk": "1"}
 
    render_test_view_kwargs = {"pk": "1"}
 

	
 
    def setUp(self):
 
        """
 
        Set-up some test data.
 
        """
 

	
 
@@ -230,12 +232,13 @@ class EntityViewTest(PermissionTestMixin
 

	
 
class EntityIptablesTest(PermissionTestMixin, TestCase):
 

	
 
    view_function = staticmethod(entity_iptables)
 
    sufficient_permissions = ("view",)
 
    permission_test_view_kwargs = {"pk": "1"}
 
    render_test_view_kwargs = {"pk": "1"}
 

	
 
    def setUp(self):
 
        """
 
        Set-up some test data.
 
        """
 

	
 
@@ -299,12 +302,13 @@ class EntityIptablesTest(PermissionTestM
 

	
 
class ProjectIptablesTest(PermissionTestMixin, TestCase):
 

	
 
    view_function = staticmethod(project_iptables)
 
    sufficient_permissions = ("view",)
 
    permission_test_view_kwargs = {"project_id": 1}
 
    render_test_view_kwargs = {"project_id": 1}
 

	
 
    def setUp(self):
 
        """
 
        Set-up some test data.
 
        """
 

	
 
@@ -427,23 +431,24 @@ class ProjectIptablesTest(PermissionTest
 
            self.assertIn(":OUTPUT", iptables_file)
 
            self.assertIn(":FORWARD", iptables_file)
 

	
 
        zipped_iptables.close()
 

	
 

	
 
class ProjectCreateViewTest(PermissionTestMixin, TestCase):
 
class ProjectCreateViewTest(RenderTestMixin, PermissionTestMixin, TestCase):
 

	
 
    view_class = ProjectCreateView
 
    sufficient_permissions = ("add_project",)
 

	
 

	
 
class ProjectUpdateViewTest(PermissionTestMixin, TestCase):
 
class ProjectUpdateViewTest(RenderTestMixin, PermissionTestMixin, TestCase):
 

	
 
    view_class = ProjectUpdateView
 
    sufficient_permissions = ("change_project",)
 
    permission_test_view_kwargs = {"pk": 1}
 
    render_test_view_kwargs = {"pk": 1}
 

	
 
    def setUp(self):
 
        """
 
        Set-up some test data.
 
        """
 

	
 
@@ -462,17 +467,18 @@ class ProjectUpdateViewTest(PermissionTe
 
        response = generate_get_response(view, None, pk=1)
 

	
 
        self.assertEqual(response.context_data["project"].name, "Test Project 1")
 
        self.assertEqual(response.context_data["headline"], "Update project Test Project 1")
 

	
 

	
 
class ProjectDeleteViewTest(PermissionTestMixin, TestCase):
 
class ProjectDeleteViewTest(RenderTestMixin, PermissionTestMixin, TestCase):
 

	
 
    view_class = ProjectDeleteView
 
    sufficient_permissions = ("delete_project",)
 
    permission_test_view_kwargs = {"pk": "1"}
 
    render_test_view_kwargs = {"pk": "1"}
 

	
 
    def setUp(self):
 
        """
 
        Set-up some test data.
 
        """
 

	
 
@@ -513,23 +519,24 @@ class ProjectDeleteViewTest(PermissionTe
 
        # Get the response.
 
        response = view(request, pk=1)
 

	
 
        self.assertIn("Project Test Project 1 has been removed.", request._messages.messages)
 

	
 

	
 
class LocationCreateViewTest(PermissionTestMixin, TestCase):
 
class LocationCreateViewTest(RenderTestMixin, PermissionTestMixin, TestCase):
 

	
 
    view_class = LocationCreateView
 
    sufficient_permissions = ("add_location",)
 

	
 

	
 
class LocationUpdateViewTest(PermissionTestMixin, TestCase):
 
class LocationUpdateViewTest(RenderTestMixin, PermissionTestMixin, TestCase):
 

	
 
    view_class = LocationUpdateView
 
    sufficient_permissions = ("change_location",)
 
    permission_test_view_kwargs = {"pk": 1}
 
    render_test_view_kwargs = {"pk": 1}
 

	
 
    def setUp(self):
 
        """
 
        Set-up some test data.
 
        """
 

	
 
@@ -548,17 +555,18 @@ class LocationUpdateViewTest(PermissionT
 
        response = generate_get_response(view, None, pk=1)
 

	
 
        self.assertEqual(response.context_data["location"].name, "Test Location 1")
 
        self.assertEqual(response.context_data["headline"], "Update location Test Location 1")
 

	
 

	
 
class LocationDeleteViewTest(PermissionTestMixin, TestCase):
 
class LocationDeleteViewTest(RenderTestMixin, PermissionTestMixin, TestCase):
 

	
 
    view_class = LocationDeleteView
 
    sufficient_permissions = ("delete_location",)
 
    permission_test_view_kwargs = {"pk": "1"}
 
    render_test_view_kwargs = {"pk": "1"}    
 

	
 
    def setUp(self):
 
        """
 
        Set-up some test data.
 
        """
 

	
 
@@ -600,13 +608,13 @@ class LocationDeleteViewTest(PermissionT
 
        # Get the response.
 
        response = view(request, pk=1)
 

	
 
        self.assertIn("Location Test Location 1 has been removed.", request._messages.messages)
 

	
 

	
 
class EntityCreateViewTest(PermissionTestMixin, TestCase):
 
class EntityCreateViewTest(RenderTestMixin, PermissionTestMixin, TestCase):
 

	
 
    view_class = EntityCreateView
 
    sufficient_permissions = ("add_entity",)
 

	
 
    def setUp(self):
 
        """
 
@@ -677,17 +685,18 @@ class EntityCreateViewTest(PermissionTes
 

	
 
        initial = view.get_initial()
 

	
 
        self.assertDictContainsSubset({"location": "1"}, initial)
 

	
 

	
 
class EntityDeleteViewTest(PermissionTestMixin, TestCase):
 
class EntityDeleteViewTest(RenderTestMixin, PermissionTestMixin, TestCase):
 

	
 
    view_class = EntityDeleteView
 
    sufficient_permissions = ("delete_entity",)
 
    permission_test_view_kwargs = {"pk": 1}
 
    render_test_view_kwargs = {"pk": 1}
 

	
 
    def setUp(self):
 
        """
 
        Set-up some test data.
 
        """
 

	
 
@@ -748,17 +757,18 @@ class EntityDeleteViewTest(PermissionTes
 
        # Get the response.
 
        response = view(request, pk=1)
 

	
 
        self.assertEqual(response["Location"], reverse("project", args=(1,)))
 

	
 

	
 
class EntityUpdateViewTest(PermissionTestMixin, TestCase):
 
class EntityUpdateViewTest(RenderTestMixin, PermissionTestMixin, TestCase):
 

	
 
    view_class = EntityUpdateView
 
    sufficient_permissions = ("change_entity",)
 
    permission_test_view_kwargs = {"pk": 1}
 
    render_test_view_kwargs = {"pk": 1}
 

	
 
    def setUp(self):
 
        """
 
        Set-up some test data.
 
        """
 

	
 
@@ -777,13 +787,13 @@ class EntityUpdateViewTest(PermissionTes
 
        response = generate_get_response(view, None, pk=1)
 

	
 
        self.assertEqual(response.context_data["entity"].name, "Test Entity 1")
 
        self.assertEqual(response.context_data["headline"], "Update entity Test Entity 1")
 

	
 

	
 
class InterfaceCreateViewTest(PermissionTestMixin, TestCase):
 
class InterfaceCreateViewTest(RenderTestMixin, PermissionTestMixin, TestCase):
 

	
 
    view_class = InterfaceCreateView
 
    sufficient_permissions = ("add_interface",)
 

	
 
    def setUp(self):
 
        """
 
@@ -847,17 +857,18 @@ class InterfaceCreateViewTest(Permission
 
        response = view(request, pk=1)
 

	
 
        self.assertEqual(response["Location"], reverse("entity", args=(1,)))
 
        self.assertEqual(response.status_code, 302)
 

	
 

	
 
class InterfaceUpdateViewTest(PermissionTestMixin, TestCase):
 
class InterfaceUpdateViewTest(RenderTestMixin, PermissionTestMixin, TestCase):
 

	
 
    view_class = InterfaceUpdateView
 
    sufficient_permissions = ("change_interface",)
 
    permission_test_view_kwargs = {"pk": 1}
 
    render_test_view_kwargs = {"pk": 1}
 

	
 
    def setUp(self):
 
        """
 
        Set-up some test data.
 
        """
 

	
 
@@ -925,17 +936,18 @@ class InterfaceUpdateViewTest(Permission
 
        response = view(request, pk=1)
 

	
 
        self.assertEqual(response["Location"], reverse("entity", args=(1,)))
 
        self.assertEqual(response.status_code, 302)
 

	
 

	
 
class InterfaceDeleteViewTest(PermissionTestMixin, TestCase):
 
class InterfaceDeleteViewTest(RenderTestMixin, PermissionTestMixin, TestCase):
 

	
 
    view_class = InterfaceDeleteView
 
    sufficient_permissions = ("delete_interface",)
 
    permission_test_view_kwargs = {"pk": 1}
 
    render_test_view_kwargs = {"pk": 1}
 

	
 
    def setUp(self):
 
        """
 
        Set-up some test data.
 
        """
 

	
 
@@ -996,13 +1008,13 @@ class InterfaceDeleteViewTest(Permission
 
        # Get the response.
 
        response = view(request, pk=1)
 

	
 
        self.assertEqual(response["Location"], reverse("entity", args=(1,)))
 

	
 

	
 
class CommunicationCreateViewTest(PermissionTestMixin, TestCase):
 
class CommunicationCreateViewTest(RenderTestMixin, PermissionTestMixin, TestCase):
 

	
 
    view_class = CommunicationCreateView
 
    sufficient_permissions = ("add_communication",)
 

	
 
    def setUp(self):
 
        """
 
@@ -1218,17 +1230,18 @@ class CommunicationCreateViewTest(Permis
 
        response = view(request)
 

	
 
        self.assertEqual(response["Location"], reverse("project", args=(1,)))
 
        self.assertEqual(response.status_code, 302)
 

	
 

	
 
class CommunicationUpdateViewTest(PermissionTestMixin, TestCase):
 
class CommunicationUpdateViewTest(RenderTestMixin, PermissionTestMixin, TestCase):
 

	
 
    view_class = CommunicationUpdateView
 
    sufficient_permissions = ("change_communication",)
 
    permission_test_view_kwargs = {"pk": 1}
 
    render_test_view_kwargs = {"pk": 1}
 

	
 
    def setUp(self):
 
        """
 
        Set-up some test data.
 
        """
 

	
 
@@ -1325,17 +1338,18 @@ class CommunicationUpdateViewTest(Permis
 
        response = view(request, pk=1)
 

	
 
        self.assertEqual(response["Location"], reverse("project", args=(communication.source.entity.project.id,)))
 
        self.assertEqual(response.status_code, 302)
 

	
 

	
 
class CommunicationDeleteViewTest(PermissionTestMixin, TestCase):
 
class CommunicationDeleteViewTest(RenderTestMixin, PermissionTestMixin, TestCase):
 

	
 
    view_class = CommunicationDeleteView
 
    sufficient_permissions = ("delete_communication",)
 
    permission_test_view_kwargs = {"pk": 1}
 
    render_test_view_kwargs = {"pk": 1}
 

	
 
    def setUp(self):
 
        """
 
        Set-up some test data.
 
        """
 

	
 
@@ -1442,12 +1456,13 @@ class CommunicationDeleteViewTest(Permis
 

	
 
class ProjectDiagramTest(PermissionTestMixin, TestCase):
 

	
 
    view_function = staticmethod(project_diagram)
 
    sufficient_permissions = ("view",)
 
    permission_test_view_kwargs = {"pk": "1"}
 
    render_test_view_kwargs = {"pk": "1"}
 

	
 
    def setUp(self):
 
        """
 
        Set-up some test data.
 
        """
 

	
 
@@ -1537,13 +1552,13 @@ class RedirectToNextMixinTest(TestCase):
 
        view = RedirectToNextMixinView(request)
 
        view.next_parameter = "custom"
 

	
 
        self.assertEqual("/next", view.get_success_url())
 

	
 

	
 
class SearchViewTest(PermissionTestMixin, TestCase):
 
class SearchViewTest(RenderTestMixin, PermissionTestMixin, TestCase):
 

	
 
    sufficient_permissions = ("view",)
 
    view_class = SearchView
 

	
 
    def setUp(self):
 
        """
requirements/base.in
Show inline comments
 
@@ -18,13 +18,13 @@
 
#
 

	
 
# Convenience mixins for Django (for authentication etc).
 
django-braces~=1.12.0
 

	
 
# Convenience tools for controlling rendering of forms while embracing DRY.
 
django-crispy-forms~=1.7.0
 
django-crispy-forms~=1.6.0
 

	
 
# Web framework used by application.
 
django~=1.5.0
 

	
 
# Library for programatic calculation of colours (contrasts,
 
# inversions etc).
requirements/development.txt
Show inline comments
 
@@ -7,13 +7,13 @@
 
alabaster==0.7.10         # via sphinx
 
babel==2.5.1              # via sphinx
 
certifi==2017.11.5        # via requests
 
chardet==3.0.4            # via requests
 
coverage==4.4.2
 
django-braces==1.12.0
 
django-crispy-forms==1.7.0
 
django-crispy-forms==1.6.1
 
django-discover-runner==0.3
 
django==1.5.12
 
docutils==0.14            # via sphinx
 
factory-boy==2.1.2
 
funcsigs==1.0.2           # via mock
 
idna==2.6                 # via requests
requirements/test.txt
Show inline comments
 
@@ -7,13 +7,13 @@
 
alabaster==0.7.10         # via sphinx
 
babel==2.5.1              # via sphinx
 
certifi==2017.11.5        # via requests
 
chardet==3.0.4            # via requests
 
coverage==4.4.2
 
django-braces==1.12.0
 
django-crispy-forms==1.7.0
 
django-crispy-forms==1.6.1
 
django-discover-runner==0.3
 
django==1.5.12
 
docutils==0.14            # via sphinx
 
factory-boy==2.1.2
 
funcsigs==1.0.2           # via mock
 
idna==2.6                 # via requests
setup.py
Show inline comments
 
@@ -22,13 +22,13 @@
 
import os
 
from setuptools import setup, find_packages
 

	
 
README = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read()
 
INSTALL_REQUIREMENTS = [
 
    "django-braces~=1.12.0",
 
    "django-crispy-forms~=1.7.0",
 
    "django-crispy-forms~=1.6.0",
 
    "django~=1.5.0",
 
    "palette~=0.2.0",
 
    "pydot~=1.2.0",
 
    "south~=1.0.0",
 
]
 

	
0 comments (0 inline, 0 general)