Changeset - 9b889983cd7b
[Not reviewed]
default
0 3 0
Branko Majic (branko) - 11 years ago 2013-07-27 10:57:18
branko@majic.rs
CONNT-15: Fixed some headline stuff. Added context tests for generated headlines.
3 files changed with 11 insertions and 8 deletions:
0 comments (0 inline, 0 general)
conntrackt/tests/test_views.py
Show inline comments
 
@@ -392,24 +392,25 @@ class ProjectUpdateViewTest(PermissionTe
 
        """
 
        Verifies that the context is properly set-up when the view is called for
 
        specific project.
 
        """
 

	
 
        # Get the view.
 
        view = ProjectUpdateView.as_view()
 

	
 
        # Get the response.
 
        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):
 

	
 
    fixtures = ['test-data.json']
 

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

	
 
    def test_context(self):
 
        """
 
@@ -418,24 +419,25 @@ class ProjectDeleteViewTest(PermissionTe
 
        """
 

	
 
        # Get the expected project.
 
        project = Project.objects.get(pk=1)
 

	
 
        # Get the view.
 
        view = ProjectDeleteView.as_view()
 

	
 
        # Get the response.
 
        response = generate_get_response(view, None, pk=1)
 

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

	
 
    def test_message(self):
 
        """
 
        Tests if the message gets added when the project is deleted.
 
        """
 

	
 
        # Get the view.
 
        view = ProjectDeleteView.as_view()
 

	
 
        # Generate the request.
 
        request = RequestFactory().post("/fake-path/")
 
        request.user = mock.Mock()
 
@@ -466,24 +468,25 @@ class LocationUpdateViewTest(PermissionT
 
        """
 
        Verifies that the context is properly set-up when the view is called for
 
        specific location.
 
        """
 

	
 
        # Get the view.
 
        view = LocationUpdateView.as_view()
 

	
 
        # Get the response.
 
        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):
 

	
 
    fixtures = ['test-data.json']
 

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

	
 
    def test_context(self):
 
        """
 
@@ -492,24 +495,25 @@ class LocationDeleteViewTest(PermissionT
 
        """
 

	
 
        # Get the expected location.
 
        location = Location.objects.get(pk=1)
 

	
 
        # Get the view.
 
        view = LocationDeleteView.as_view()
 

	
 
        # Get the response.
 
        response = generate_get_response(view, None, pk=1)
 

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

	
 
    def test_message(self):
 
        """
 
        Tests if the message gets added when the location is deleted.
 
        """
 

	
 
        # Get the view.
 
        view = LocationDeleteView.as_view()
 

	
 
        # Generate the request.
 
        request = RequestFactory().post("/fake-path/")
 
        request.user = mock.Mock()
 
@@ -615,24 +619,25 @@ class EntityDeleteViewTest(PermissionTes
 
        """
 

	
 
        # Get the expected entity.
 
        entity = Entity.objects.get(pk=1)
 

	
 
        # Get the view.
 
        view = EntityDeleteView.as_view()
 

	
 
        # Get the response.
 
        response = generate_get_response(view, None, pk=1)
 

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

	
 
    def test_message(self):
 
        """
 
        Tests if the message gets added when the entity is deleted.
 
        """
 

	
 
        # Get the view.
 
        view = EntityDeleteView.as_view()
 

	
 
        # Generate the request.
 
        request = RequestFactory().post("/fake-path/")
 
        request.user = mock.Mock()
 
@@ -677,24 +682,25 @@ class EntityUpdateViewTest(PermissionTes
 
        """
 
        Verifies that the context is properly set-up when the view is called for
 
        specific entity.
 
        """
 

	
 
        # Get the view.
 
        view = EntityUpdateView.as_view()
 

	
 
        # Get the response.
 
        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):
 

	
 
    view_class = InterfaceCreateView
 
    sufficient_permissions = ("add_interface",)
 

	
 
    def setUp(self):
 
        """
 
        Sets-up some data necessary for testing.
 
        """
 

	
 
@@ -773,24 +779,25 @@ class InterfaceUpdateViewTest(Permission
 
        """
 

	
 
        # Get the view.
 
        view = InterfaceUpdateView.as_view()
 

	
 
        # Get the response.
 
        response = generate_get_response(view, None, pk=1)
 

	
 
        # Set-up expected interface.
 
        interface = Interface.objects.get(pk=1)
 

	
 
        self.assertEqual(response.context_data["interface"], interface)
 
        self.assertEqual(response.context_data["headline"], "Update interface eth0")
 

	
 
    def test_form_entity_limit(self):
 
        """
 
        Tests if the queryset is properly limitted to specific project's
 
        entities.
 
        """
 

	
 
        # Set-up the view.
 
        view = InterfaceUpdateView()
 
        view.request = RequestFactory().get("/fake-path/1")
 
        view.object = Interface.objects.get(pk=1)
 

	
 
@@ -845,24 +852,25 @@ class InterfaceDeleteViewTest(Permission
 
        """
 

	
 
        # Get the expected entity.
 
        interface = Interface.objects.get(pk=1)
 

	
 
        # Get the view.
 
        view = InterfaceDeleteView.as_view()
 

	
 
        # Get the response.
 
        response = generate_get_response(view, None, pk=1)
 

	
 
        self.assertEqual(response.context_data["interface"], interface)
 
        self.assertEqual(response.context_data["headline"], "Delete interface eth0")
 

	
 
    def test_message(self):
 
        """
 
        Tests if the message gets added when the interface is deleted.
 
        """
 

	
 
        # Get the view.
 
        view = InterfaceDeleteView.as_view()
 

	
 
        # Generate the request.
 
        request = RequestFactory().post("/fake-path/")
 
        request.user = mock.Mock()
 
@@ -1131,24 +1139,25 @@ class CommunicationUpdateViewTest(Permis
 
        """
 

	
 
        # Get the view.
 
        view = CommunicationUpdateView.as_view()
 

	
 
        # Get the response.
 
        response = generate_get_response(view, None, pk=1)
 

	
 
        # Set-up expected interface.
 
        communication = Communication.objects.get(pk=1)
 

	
 
        self.assertEqual(response.context_data["communication"], communication)
 
        self.assertEqual(response.context_data["headline"], "Update communication Test Entity 2 -> Test Entity 1 (TCP:22)")
 

	
 
    def test_form_interface_limit(self):
 
        """
 
        Tests if the queryset is properly limitted to specific project's
 
        entity interfaces.
 
        """
 

	
 
        # Set-up the view.
 
        view = CommunicationUpdateView()
 
        view.request = RequestFactory().get("/fake-path/1")
 
        view.object = Communication.objects.get(pk=1)
 

	
 
@@ -1233,24 +1242,25 @@ class CommunicationDeleteViewTest(Permis
 
        """
 

	
 
        # Get the expected entity.
 
        communication = Communication.objects.get(pk=1)
 

	
 
        # Get the view.
 
        view = CommunicationDeleteView.as_view()
 

	
 
        # Get the response.
 
        response = generate_get_response(view, None, pk=1)
 

	
 
        self.assertEqual(response.context_data["communication"], communication)
 
        self.assertEqual(response.context_data["headline"], "Delete communication Test Entity 2 -> Test Entity 1 (TCP:22)")
 

	
 
    def test_message(self):
 
        """
 
        Tests if the message gets added when the communication is deleted.
 
        """
 

	
 
        # Get the view.
 
        view = CommunicationDeleteView.as_view()
 

	
 
        # Generate the request.
 
        request = RequestFactory().post("/fake-path/")
 
        request.user = mock.Mock()
conntrackt/urls.py
Show inline comments
 
@@ -24,25 +24,24 @@ urlpatterns = patterns(
 
    # View for updating an existing project.
 
    url(r'^project/(?P<pk>\d+)/edit/$', ProjectUpdateView.as_view(), name="project_update"),
 
    # View for deleting a project.
 
    url(r'^project/(?P<pk>\d+)/remove/$', ProjectDeleteView.as_view(), name="project_delete"),
 

	
 
    # View for creating a new location.
 
    url(r'^location/add/$', LocationCreateView.as_view(), name="location_create"),
 
    # View for updating an existing location.
 
    url(r'^location/(?P<pk>\d+)/edit/$', LocationUpdateView.as_view(), name="location_update"),
 
    # View for deleting a location.
 
    url(r'^location/(?P<pk>\d+)/remove/$', LocationDeleteView.as_view(), name="location_delete"),
 

	
 

	
 
    # View for showing information about an entity.
 
    url(r'^entity/(?P<pk>\d+)/$', EntityView.as_view(),
 
        name='entity'),
 
    # View for creating a new entity.
 
    url(r'^entity/add/$', EntityCreateView.as_view(), name="entity_create"),
 
    # View for updating an existing entity.
 
    url(r'^entity/(?P<pk>\d+)/edit/$', EntityUpdateView.as_view(), name="entity_update"),
 
    # View for deleting an entity.
 
    url(r'^entity/(?P<pk>\d+)/remove/$', EntityDeleteView.as_view(), name="entity_delete"),
 

	
 
    # View for creating a new interface.
 
    url(r'^interface/add/$', InterfaceCreateView.as_view(), name="interface_create"),
 
@@ -55,16 +54,17 @@ urlpatterns = patterns(
 
    url(r'^communication/add/$', CommunicationCreateView.as_view(), name="communication_create"),
 
    # View for updating an existing communication.
 
    url(r'^communication/(?P<pk>\d+)/edit/$', CommunicationUpdateView.as_view(), name="communication_update"),
 
    # View for deleting a communication.
 
    url(r'^communication/(?P<pk>\d+)/remove/$', CommunicationDeleteView.as_view(), name="communication_delete"),
 

	
 
    # View for rendering iptables rules for a specific entity.
 
    url(r'^entity/(?P<pk>\d+)/iptables/$', entity_iptables, name="entity_iptables"),
 
    # View for rendering zip file with iptables rules for all entities in a project.
 
    url(r'^project/(?P<project_id>\d+)/iptables/$', project_iptables, name="project_iptables"),
 
    # View for rendering zip file with iptables rules for all entities in a project for a specific location.
 
    url(r'^project/(?P<project_id>\d+)/location/(?P<location_id>\d+)/iptables/$', project_iptables, name="project_location_iptables"),
 

	
 
    # Views for logging-in/out the users.
 
    url(r'^login/$', login, {'template_name': 'conntrackt/login.html'}, name="login"),
 
    url(r'^logout/$', logout, name="logout"),
 
)
conntrackt/views.py
Show inline comments
 
@@ -769,31 +769,24 @@ class CommunicationCreateView(SetHeadlin
 

	
 
    def get_success_url(self):
 
        """
 
        Returns the URL to which the user should be redirected after a
 
        communication has been created.
 

	
 
        The URL will either point to value provided via GET parameter "next", or
 
        to project page to which the communication belongs.
 
        """
 

	
 
        return self.request.GET.get("next", reverse("project", args=(self.object.source.entity.project.pk,)))
 

	
 
    def get_headline(self):
 
        """
 
        Set headline based on interface name.
 
        """
 

	
 
        return "Delete interface %s" % self.object.name
 

	
 

	
 
class CommunicationUpdateView(SetHeadlineMixin, MultiplePermissionsRequiredMixin, UpdateView):
 
    """
 
    View for updating an existing communication.
 
    """
 

	
 
    model = Communication
 
    form_class = CommunicationForm
 
    template_name = "conntrackt/update_form.html"
 

	
 
    # Required permissions.
 
    permissions = {
0 comments (0 inline, 0 general)