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
 
@@ -398,12 +398,13 @@ class ProjectUpdateViewTest(PermissionTe
 
        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']
 

	
 
@@ -424,12 +425,13 @@ class ProjectDeleteViewTest(PermissionTe
 
        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.
 
        """
 

	
 
@@ -472,12 +474,13 @@ class LocationUpdateViewTest(PermissionT
 
        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']
 

	
 
@@ -498,12 +501,13 @@ class LocationDeleteViewTest(PermissionT
 
        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.
 
        """
 

	
 
@@ -621,12 +625,13 @@ class EntityDeleteViewTest(PermissionTes
 
        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.
 
        """
 

	
 
@@ -683,12 +688,13 @@ class EntityUpdateViewTest(PermissionTes
 
        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",)
 
@@ -779,12 +785,13 @@ class InterfaceUpdateViewTest(Permission
 
        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.
 
        """
 
@@ -851,12 +858,13 @@ class InterfaceDeleteViewTest(Permission
 
        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.
 
        """
 

	
 
@@ -1137,12 +1145,13 @@ class CommunicationUpdateViewTest(Permis
 
        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.
 
        """
 
@@ -1239,12 +1248,13 @@ class CommunicationDeleteViewTest(Permis
 
        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.
 
        """
 

	
conntrackt/urls.py
Show inline comments
 
@@ -30,13 +30,12 @@ urlpatterns = patterns(
 
    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.
 
@@ -61,10 +60,11 @@ urlpatterns = patterns(
 
    # 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
 
@@ -775,19 +775,12 @@ class CommunicationCreateView(SetHeadlin
 
        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.
 
    """
 

	
0 comments (0 inline, 0 general)