Changeset - 40cc47b13d9b
[Not reviewed]
default
0 3 0
Branko Majic (branko) - 11 years ago 2013-07-17 21:39:18
branko@majic.rs
Noticket: PEP8 fixes.
3 files changed with 11 insertions and 12 deletions:
0 comments (0 inline, 0 general)
conntrackt/tests/test_models.py
Show inline comments
 
@@ -118,25 +118,25 @@ class EntityTest(TestCase):
 
        self.assertEqual(entity.get_absolute_url(), "/conntrackt/entity/1/")
 

	
 
    def test_project_move_constraints(self):
 
        """
 
        Tests if entity is prevented from being moved to different project in
 
        case of existing communications.
 
        """
 

	
 
        entity = Entity.objects.get(pk=1)
 
        new_project = Project.objects.get(pk=2)
 

	
 
        entity.project = new_project
 
        self.assertRaisesRegexp(ValidationError, "The entity cannot be moved to different project as long as it has valid communications with entities in current project." ,entity.clean)
 
        self.assertRaisesRegexp(ValidationError, "The entity cannot be moved to different project as long as it has valid communications with entities in current project.", entity.clean)
 

	
 

	
 
class InterfaceTest(TestCase):
 
    fixtures = ['test-data.json']
 

	
 
    def test_unique_name(self):
 
        """
 
        Test if unique interface name is enforced across same entity.
 
        """
 

	
 
        entity = Entity.objects.get(pk=1)
 

	
conntrackt/tests/test_views.py
Show inline comments
 
@@ -185,34 +185,34 @@ class EntityViewTest(ViewTest):
 
    def test_entity_show(self):
 
        """
 
        Tests if the entity information is shown properly.
 
        """
 

	
 
        self.client.login(username="fullperms", password="fullperms")
 

	
 
        response = self.client.get(reverse("entity", args=(1,)))
 

	
 
        expected_incoming_communications = ["<Communication: Test Entity 2 -> Test Entity 1 (TCP:22)>",
 
                                            "<Communication: Test Entity 2 -> Test Entity 1 (ICMP:8)>",
 
                                            "<Communication: Test Entity 3 -> Test Entity 1 (TCP:3306)>",
 
                                            "<Communication: Test Subnet -> Test Entity 1 (TCP:22)>",]
 
                                            "<Communication: Test Subnet -> Test Entity 1 (TCP:22)>"]
 

	
 
        expected_outgoing_communications = ["<Communication: Test Entity 1 -> Test Entity 2 (UDP:123)>",
 
                                            "<Communication: Test Entity 1 -> Test Entity 3 (UDP:53)>"]
 

	
 
        expected_interfaces = ["<Interface: Test Entity 1 (192.168.1.1)>"]
 

	
 
        self.assertQuerysetEqual(response.context["interfaces"], expected_interfaces)
 
        self.assertQuerysetEqual(response.context["incoming_communications"], expected_incoming_communications)
 
        self.assertQuerysetEqual(response.context["outgoing_communications"], expected_outgoing_communications) 
 
        self.assertQuerysetEqual(response.context["outgoing_communications"], expected_outgoing_communications)
 
        self.assertEqual(str(response.context["entity"]), "Test Entity 1 (Test Project 1 - Test Location 1)")
 
        self.assertContains(response, "Test Entity 1")
 
        self.assertContains(response, ":INPUT")
 
        self.assertContains(response, ":OUTPUT")
 
        self.assertContains(response, ":FORWARD")
 

	
 

	
 
class EntityIptablesTest(ViewTest):
 

	
 
    def test_permission_denied(self):
 
        """
 
        Tests if permission will be denied for client without sufficient privileges.
 
@@ -832,39 +832,39 @@ class EntityCreateViewTest(TestCase):
 
        view.object = None
 

	
 
        # Get the form.
 
        form = view.get_form(view.get_form_class())
 

	
 
        self.assertQuerysetEqual(form.fields["location"].queryset, ["<Location: Test Location 1>"])
 

	
 
    def test_initial_project(self):
 
        """
 
        Tests if the choice field for project is defaulted to project passed as
 
        part of GET parameters.
 
        """
 
        
 

	
 
        view = EntityCreateView()
 
        view.request = RequestFactory().get("/fake-path?project=1")
 
        view.object = None
 

	
 
        initial = view.get_initial()
 

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

	
 
    def test_initial_location(self):
 
        """
 
        Tests if the choice field for location is defaulted to location passed
 
        as part of GET parameters.
 
        """
 
        
 

	
 
        view = EntityCreateView()
 
        view.request = RequestFactory().get("/fake-path?location=1")
 
        view.object = None
 

	
 
        initial = view.get_initial()
 

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

	
 

	
 
class EntityDeleteViewTest(TestCase):
 

	
 
    fixtures = ['test-data.json']
 
@@ -926,25 +926,25 @@ class EntityDeleteViewTest(TestCase):
 
        response = self.client.post(reverse("entity_delete", args=(1,)),
 
                                    {'csrfmiddlewaretoken': response.context['request'].META['CSRF_COOKIE']},
 
                                    follow=True)
 

	
 
        self.assertContains(response, "Entity Test Entity 1 has been removed.")
 

	
 
    def test_success_url(self):
 
        """
 
        Validate that the success URL is set properly after delete.
 
        """
 

	
 
        self.client.login(username="fullperms", password="fullperms")
 
        
 

	
 
        response = self.client.get(reverse("entity_delete", args=(1,)))
 

	
 
        response = self.client.post(reverse("entity_delete", args=(1,)),
 
                                    {'csrfmiddlewaretoken': response.context['request'].META['CSRF_COOKIE']},
 
                                    follow=True)
 

	
 
        self.assertEqual(response.context["request"].META["PATH_INFO"], reverse("project", args=(1,)))
 

	
 

	
 
class EntityUpdateViewTest(TestCase):
 

	
 
    fixtures = ['test-data.json']
 
@@ -1047,25 +1047,25 @@ class InterfaceCreateViewTest(TestCase):
 
        view.object = None
 

	
 
        # Get the form.
 
        form = view.get_form(view.get_form_class())
 

	
 
        self.assertQuerysetEqual(form.fields["entity"].queryset, ["<Entity: Test Entity 1 (Test Project - Test Location)>"])
 

	
 
    def test_initial_project(self):
 
        """
 
        Tests if the choice field for entity is defaulted to entity passed as
 
        part of GET parameters.
 
        """
 
        
 

	
 
        view = InterfaceCreateView()
 
        view.request = RequestFactory().get("/fake-path?entity=1")
 
        view.object = None
 

	
 
        initial = view.get_initial()
 

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

	
 

	
 
class InterfaceUpdateViewTest(TestCase):
 

	
 
    fixtures = ['test-data.json']
 
@@ -1135,25 +1135,25 @@ class InterfaceUpdateViewTest(TestCase):
 
                             "<Entity: Test Subnet (Test Project 1 - Test Location 2)>"]
 

	
 
        self.assertQuerysetEqual(form.fields["entity"].queryset, expected_entities)
 

	
 
    def test_success_url(self):
 
        """
 
        Validate that the success URL is set properly after update.
 
        """
 

	
 
        self.client.login(username="fullperms", password="fullperms")
 

	
 
        interface = Interface.objects.get(pk=1)
 
        
 

	
 
        response = self.client.get(reverse("interface_update", args=(1,)))
 

	
 
        response = self.client.post(reverse("interface_update", args=(1,)),
 
                                    {'csrfmiddlewaretoken': response.context['request'].META['CSRF_COOKIE'],
 
                                     "name": interface.name,
 
                                     "description": interface.name,
 
                                     "entity": "1",
 
                                     "address": "192.168.1.1",
 
                                     "netmask": "255.255.255.255"},
 
                                    follow=True)
 

	
 
        self.assertEqual(response.context["request"].META["PATH_INFO"], reverse("entity", args=(1,)))
 
@@ -1220,20 +1220,20 @@ class InterfaceDeleteViewTest(TestCase):
 
        response = self.client.post(reverse("interface_delete", args=(1,)),
 
                                    {'csrfmiddlewaretoken': response.context['request'].META['CSRF_COOKIE']},
 
                                    follow=True)
 

	
 
        self.assertContains(response, "Interface eth0 has been removed.")
 

	
 
    def test_success_url(self):
 
        """
 
        Validate that the success URL is set properly after delete.
 
        """
 

	
 
        self.client.login(username="fullperms", password="fullperms")
 
        
 

	
 
        response = self.client.get(reverse("interface_delete", args=(1,)))
 

	
 
        response = self.client.post(reverse("interface_delete", args=(1,)),
 
                                    {'csrfmiddlewaretoken': response.context['request'].META['CSRF_COOKIE']},
 
                                    follow=True)
 

	
 
        self.assertEqual(response.context["request"].META["PATH_INFO"], reverse("entity", args=(1,)))
conntrackt/views.py
Show inline comments
 
@@ -460,25 +460,25 @@ class EntityCreateView(MultiplePermissio
 

	
 
        # Limit the project selection if required.
 
        project_id = self.request.GET.get("project", None)
 
        if project_id:
 
            form.fields["project"].queryset = Project.objects.filter(pk=project_id)
 
            form.fields["project"].widget.attrs["readonly"] = True
 

	
 
        # Limit the location selection if required.
 
        location_id = self.request.GET.get("location", None)
 
        if location_id:
 
            form.fields["location"].queryset = Location.objects.filter(pk=location_id)
 
            form.fields["location"].widget.attrs["readonly"] = True
 
        
 

	
 
        return form
 

	
 
    def get_initial(self):
 
        """
 
        Returns initial values that should be pre-selected (if they were
 
        specified through a GET parameter).
 
        """
 

	
 
        initial = super(EntityCreateView, self).get_initial()
 

	
 
        initial["project"] = self.request.GET.get("project", None)
 
        initial["location"] = self.request.GET.get("location", None)
 
@@ -493,25 +493,25 @@ class EntityUpdateView(MultiplePermissio
 

	
 
    model = Entity
 
    form_class = EntityForm
 
    template_name_suffix = "_update_form"
 

	
 
    # Required permissions.
 
    permissions = {
 
        "all": ("conntrackt.change_entity",),
 
        }
 

	
 
    # Raise authorisation denied exception for unmet permissions.
 
    raise_exception = True
 
    
 

	
 

	
 
class EntityDeleteView(MultiplePermissionsRequiredMixin, DeleteView):
 
    """
 
    View for deleting an entity.
 
    """
 

	
 
    model = Entity
 

	
 
    # Required permissions.
 
    permissions = {
 
        "all": ("conntrackt.delete_entity",),
 
        }
 
@@ -671,13 +671,12 @@ class InterfaceDeleteView(MultiplePermis
 

	
 
    def delete(self, *args, **kwargs):
 
        """
 
        Deletes the object. This method is overridden in order to obtain the
 
        entity ID for success URL.
 

	
 
        @TODO: Fix this once Django 1.6 comes out with fix from ticket 19044.
 
        """
 

	
 
        self.success_url = reverse("entity", args=(self.get_object().entity.id,))
 

	
 
        return super(InterfaceDeleteView, self).delete(*args, **kwargs)
 

	
0 comments (0 inline, 0 general)