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 @@ -27,15 +27,21 @@ from conntrackt.views import Communicati from .forms import FormWithWidgetCSSClassFormMixin, FormWithPlaceholderFormMixin from .helpers import PermissionTestMixin, create_get_request, generate_get_response, FakeMessages from .views import RedirectToNextMixinView +from .factories import setup_test_data class IndexViewTest(PermissionTestMixin, TestCase): - fixtures = ['test-data.json'] - sufficient_permissions = ("view",) view_class = IndexView + def setUp(self): + """ + Set-up some test data. + """ + + setup_test_data() + def test_context_no_projects(self): """ Verifies that the context is properly set-up when the view is called and @@ -102,12 +108,17 @@ class IndexViewTest(PermissionTestMixin, class ProjectViewTest(PermissionTestMixin, TestCase): - fixtures = ['test-data.json'] - sufficient_permissions = ("view",) permission_test_view_kwargs = {"pk": "1"} view_class = ProjectView + def setUp(self): + """ + Set-up some test data. + """ + + setup_test_data() + def test_context(self): """ Verifies that the context is properly set-up when the view is called. @@ -135,7 +146,7 @@ class ProjectViewTest(PermissionTestMixi # Set-up expected context data values. expected_entities = ["", - ""] + ""] # Validate context data. self.assertEqual(location.name, "Test Location 2") @@ -147,12 +158,17 @@ class ProjectViewTest(PermissionTestMixi class EntityViewTest(PermissionTestMixin, TestCase): - fixtures = ['test-data.json'] - view_class = EntityView sufficient_permissions = ("view",) permission_test_view_kwargs = {"pk": "1"} + def setUp(self): + """ + Set-up some test data. + """ + + setup_test_data() + def test_context(self): """ Tests if the form comes pre-populated with proper content. @@ -170,7 +186,7 @@ class EntityViewTest(PermissionTestMixin expected_incoming_communications = [" Test Entity 1 (TCP:22)>", " Test Entity 1 (ICMP:8)>", " Test Entity 1 (TCP:3306)>", - " Test Entity 1 (TCP:22)>"] + " Test Entity 1 (TCP:22)>"] expected_outgoing_communications = [" Test Entity 2 (UDP:123)>", " Test Entity 3 (UDP:53)>"] @@ -187,12 +203,17 @@ class EntityViewTest(PermissionTestMixin class EntityIptablesTest(PermissionTestMixin, TestCase): - fixtures = ['test-data.json'] - view_function = staticmethod(entity_iptables) sufficient_permissions = ("view",) permission_test_view_kwargs = {"pk": "1"} + def setUp(self): + """ + Set-up some test data. + """ + + setup_test_data() + def test_invalid_entity(self): """ Tests if a 404 is returned if no entity was found (invalid ID). @@ -251,12 +272,17 @@ class EntityIptablesTest(PermissionTestM class ProjectIptablesTest(PermissionTestMixin, TestCase): - fixtures = ['test-data.json'] - view_function = staticmethod(project_iptables) sufficient_permissions = ("view",) permission_test_view_kwargs = {"project_id": 1} + def setUp(self): + """ + Set-up some test data. + """ + + setup_test_data() + def test_invalid_project(self): """ Tests if a 404 is returned if no project was found (invalid ID). @@ -334,7 +360,7 @@ class ProjectIptablesTest(PermissionTest expected_zip_files = ["test_entity_1-iptables.conf", "test_entity_2-iptables.conf", "test_entity_3-iptables.conf", - "test_subnet-iptables.conf"] + "test_subnet_4-iptables.conf"] self.assertEqual(len(zipped_iptables.namelist()), 4) self.assertEqual(zipped_iptables.namelist(), expected_zip_files) @@ -385,12 +411,17 @@ class ProjectCreateViewTest(PermissionTe class ProjectUpdateViewTest(PermissionTestMixin, TestCase): - fixtures = ['test-data.json'] - view_class = ProjectUpdateView sufficient_permissions = ("change_project",) permission_test_view_kwargs = {"pk": 1} + def setUp(self): + """ + Set-up some test data. + """ + + setup_test_data() + def test_context(self): """ Verifies that the context is properly set-up when the view is called for @@ -409,12 +440,17 @@ class ProjectUpdateViewTest(PermissionTe class ProjectDeleteViewTest(PermissionTestMixin, TestCase): - fixtures = ['test-data.json'] - view_class = ProjectDeleteView sufficient_permissions = ("delete_project",) permission_test_view_kwargs = {"pk": "1"} + def setUp(self): + """ + Set-up some test data. + """ + + setup_test_data() + def test_context(self): """ Verifies that the context is properly set-up when the view is called for @@ -461,12 +497,17 @@ class LocationCreateViewTest(PermissionT class LocationUpdateViewTest(PermissionTestMixin, TestCase): - fixtures = ['test-data.json'] - view_class = LocationUpdateView sufficient_permissions = ("change_location",) permission_test_view_kwargs = {"pk": 1} + def setUp(self): + """ + Set-up some test data. + """ + + setup_test_data() + def test_context(self): """ Verifies that the context is properly set-up when the view is called for @@ -485,12 +526,17 @@ class LocationUpdateViewTest(PermissionT class LocationDeleteViewTest(PermissionTestMixin, TestCase): - fixtures = ['test-data.json'] - view_class = LocationDeleteView sufficient_permissions = ("delete_location",) permission_test_view_kwargs = {"pk": "1"} + def setUp(self): + """ + Set-up some test data. + """ + + setup_test_data() + def test_context(self): """ Verifies that the context is properly set-up when the view is called for @@ -609,12 +655,17 @@ class EntityCreateViewTest(PermissionTes class EntityDeleteViewTest(PermissionTestMixin, TestCase): - fixtures = ['test-data.json'] - view_class = EntityDeleteView sufficient_permissions = ("delete_entity",) permission_test_view_kwargs = {"pk": 1} + def setUp(self): + """ + Set-up some test data. + """ + + setup_test_data() + def test_context(self): """ Verifies that the context is properly set-up when the view is called for @@ -675,12 +726,17 @@ class EntityDeleteViewTest(PermissionTes class EntityUpdateViewTest(PermissionTestMixin, TestCase): - fixtures = ['test-data.json'] - view_class = EntityUpdateView sufficient_permissions = ("change_entity",) permission_test_view_kwargs = {"pk": 1} + def setUp(self): + """ + Set-up some test data. + """ + + setup_test_data() + def test_context(self): """ Verifies that the context is properly set-up when the view is called for @@ -769,12 +825,17 @@ class InterfaceCreateViewTest(Permission class InterfaceUpdateViewTest(PermissionTestMixin, TestCase): - fixtures = ['test-data.json'] - view_class = InterfaceUpdateView sufficient_permissions = ("change_interface",) permission_test_view_kwargs = {"pk": 1} + def setUp(self): + """ + Set-up some test data. + """ + + setup_test_data() + def test_context(self): """ Verifies that the context is properly set-up when the view is called for @@ -810,7 +871,7 @@ class InterfaceUpdateViewTest(Permission expected_entities = ["", "", "", - ""] + ""] self.assertQuerysetEqual(form.fields["entity"].queryset, expected_entities) @@ -842,12 +903,17 @@ class InterfaceUpdateViewTest(Permission class InterfaceDeleteViewTest(PermissionTestMixin, TestCase): - fixtures = ['test-data.json'] - view_class = InterfaceDeleteView sufficient_permissions = ("delete_interface",) permission_test_view_kwargs = {"pk": 1} + def setUp(self): + """ + Set-up some test data. + """ + + setup_test_data() + def test_context(self): """ Verifies that the context is properly set-up when the view is called for @@ -1130,12 +1196,17 @@ class CommunicationCreateViewTest(Permis class CommunicationUpdateViewTest(PermissionTestMixin, TestCase): - fixtures = ['test-data.json'] - view_class = CommunicationUpdateView sufficient_permissions = ("change_communication",) permission_test_view_kwargs = {"pk": 1} + def setUp(self): + """ + Set-up some test data. + """ + + setup_test_data() + def test_context(self): """ Verifies that the context is properly set-up. @@ -1170,7 +1241,7 @@ class CommunicationUpdateViewTest(Permis expected_interfaces = ["", "", "", - ""] + ""] self.assertQuerysetEqual(form.fields["source"].queryset, expected_interfaces) self.assertQuerysetEqual(form.fields["destination"].queryset, expected_interfaces) @@ -1232,12 +1303,17 @@ class CommunicationUpdateViewTest(Permis class CommunicationDeleteViewTest(PermissionTestMixin, TestCase): - fixtures = ['test-data.json'] - view_class = CommunicationDeleteView sufficient_permissions = ("delete_communication",) permission_test_view_kwargs = {"pk": 1} + def setUp(self): + """ + Set-up some test data. + """ + + setup_test_data() + def test_context(self): """ Verifies that the context is properly set-up when the view is called for @@ -1339,12 +1415,17 @@ class CommunicationDeleteViewTest(Permis class ProjectDiagramTest(PermissionTestMixin, TestCase): - fixtures = ['test-data.json'] - view_function = staticmethod(project_diagram) sufficient_permissions = ("view",) permission_test_view_kwargs = {"pk": "1"} + def setUp(self): + """ + Set-up some test data. + """ + + setup_test_data() + def test_invalid_project(self): """ Tests if a 404 is returned if no project was found (invalid ID).