diff --git a/conntrackt/tests/test_views.py b/conntrackt/tests/test_views.py --- a/conntrackt/tests/test_views.py +++ b/conntrackt/tests/test_views.py @@ -1062,10 +1062,10 @@ class CommunicationCreateViewTest(Permis self.assertEqual(len(initial), 0) - def test_success_url_from_entity(self): + def test_success_url_next(self): """ Validate that the success URL is set properly after communication is - created if origin entity is provided. + created if "next" GET parameter is provided. """ # Get the view. @@ -1079,47 +1079,20 @@ class CommunicationCreateViewTest(Permis "protocol": "TCP", "port": "22", "description": "SSH."} - request = RequestFactory().post("/fake-path?from_entity=1", data=post_data) + request = RequestFactory().post("/fake-path?next=/next-page", data=post_data) request.user = mock.Mock() request._dont_enforce_csrf_checks = True # Get the response. response = view(request) - self.assertEqual(response["Location"], reverse("entity", args=(1,))) + self.assertEqual(response["Location"], "/next-page") self.assertEqual(response.status_code, 302) - def test_success_url_to_entity(self): + def test_success_url_no_next(self): """ Validate that the success URL is set properly after communication is - created if destination entity is provided. - """ - - # Get the view. - view = CommunicationCreateView.as_view() - - # Generate the request. - source = Interface.objects.get(pk=1) - destination = Interface.objects.get(pk=2) - post_data = {"source": source.pk, - "destination": destination.pk, - "protocol": "TCP", - "port": "22", - "description": "SSH."} - request = RequestFactory().post("/fake-path?to_entity=2", data=post_data) - request.user = mock.Mock() - request._dont_enforce_csrf_checks = True - - # Get the response. - response = view(request) - - self.assertEqual(response["Location"], reverse("entity", args=(2,))) - self.assertEqual(response.status_code, 302) - - def test_success_url_no_entity(self): - """ - Validate that the success URL is set properly after communication is - created if no entity source/destinantion is passed on. + created if no "next" GET parameter is provided. """ # Get the view. @@ -1140,7 +1113,7 @@ class CommunicationCreateViewTest(Permis # Get the response. response = view(request) - self.assertEqual(response["Location"], reverse("entity", args=(1,))) + self.assertEqual(response["Location"], reverse("project", args=(1,))) self.assertEqual(response.status_code, 302) @@ -1190,9 +1163,10 @@ class CommunicationUpdateViewTest(Permis self.assertQuerysetEqual(form.fields["source"].queryset, expected_interfaces) self.assertQuerysetEqual(form.fields["destination"].queryset, expected_interfaces) - def test_success_url_from_entity(self): + def test_success_url_next(self): """ - Validate that the success URL is set properly after update. + Validate that the success URL is set properly after update if GET + parameter is passed. """ # Get the view. @@ -1206,45 +1180,20 @@ class CommunicationUpdateViewTest(Permis "destination": communication.destination.pk, "protocol": communication.protocol, "port": communication.port} - request = RequestFactory().post("/fake-path?from_entity=1", data=post_data) + request = RequestFactory().post("/fake-path?next=/next-page", data=post_data) request.user = mock.Mock() request._dont_enforce_csrf_checks = True # Get the response. response = view(request, pk=1) - self.assertEqual(response["Location"], reverse("entity", args=(1,))) + self.assertEqual(response["Location"], "/next-page") self.assertEqual(response.status_code, 302) - def test_success_url_to_entity(self): - """ - Validate that the success URL is set properly after update. + def test_success_url_no_next(self): """ - - # Get the view. - view = CommunicationUpdateView.as_view() - - # Get the communication object. - communication = Communication.objects.get(pk=1) - - # Generate the request. - post_data = {"source": communication.source.pk, - "destination": communication.destination.pk, - "protocol": communication.protocol, - "port": communication.port} - request = RequestFactory().post("/fake-path?to_entity=1", data=post_data) - request.user = mock.Mock() - request._dont_enforce_csrf_checks = True - - # Get the response. - response = view(request, pk=1) - - self.assertEqual(response["Location"], reverse("entity", args=(1,))) - self.assertEqual(response.status_code, 302) - - def test_success_url_no_entity(self): - """ - Validate that the success URL is set properly after update. + Validate that the success URL is set properly after communication is + created if no "next" GET parameter is provided. """ # Get the view. @@ -1265,7 +1214,7 @@ class CommunicationUpdateViewTest(Permis # Get the response. response = view(request, pk=1) - self.assertEqual(response["Location"], reverse("entity", args=(communication.source.entity.pk,))) + self.assertEqual(response["Location"], reverse("project", args=(communication.source.entity.project.id,))) self.assertEqual(response.status_code, 302)