diff --git a/conntrackt/fixtures/test-data.json b/conntrackt/fixtures/test-data.json deleted file mode 100644 --- a/conntrackt/fixtures/test-data.json +++ /dev/null @@ -1,205 +0,0 @@ -[ -{ - "pk": 1, - "model": "conntrackt.project", - "fields": { - "name": "Test Project 1", - "description": "This is a test project 1." - } -}, -{ - "pk": 2, - "model": "conntrackt.project", - "fields": { - "name": "Test Project 2", - "description": "This is a test project 2." - } -}, -{ - "pk": 1, - "model": "conntrackt.location", - "fields": { - "name": "Test Location 1", - "description": "This is a test location 1." - } -}, -{ - "pk": 2, - "model": "conntrackt.location", - "fields": { - "name": "Test Location 2", - "description": "This is a test location 2." - } -}, -{ - "pk": 1, - "model": "conntrackt.entity", - "fields": { - "project": 1, - "location": 1, - "name": "Test Entity 1", - "description": "This is a test entity 1." - } -}, -{ - "pk": 2, - "model": "conntrackt.entity", - "fields": { - "project": 1, - "location": 1, - "name": "Test Entity 2", - "description": "This is a test entity 2." - } -}, -{ - "pk": 3, - "model": "conntrackt.entity", - "fields": { - "project": 1, - "location": 2, - "name": "Test Entity 3", - "description": "This is a test entity 3." - } -}, -{ - "pk": 4, - "model": "conntrackt.entity", - "fields": { - "project": 1, - "location": 2, - "name": "Test Subnet", - "description": "This is a test subnet." - } -}, -{ - "pk": 5, - "model": "conntrackt.entity", - "fields": { - "project": 2, - "location": 1, - "name": "Other Project Test Entity", - "description": "This is a test entity from different project." - } -}, -{ - "pk": 1, - "model": "conntrackt.interface", - "fields": { - "netmask": "255.255.255.255", - "entity": 1, - "name": "eth0", - "address": "192.168.1.1", - "description": "Main network interface." - } -}, -{ - "pk": 2, - "model": "conntrackt.interface", - "fields": { - "netmask": "255.255.255.255", - "entity": 2, - "name": "eth0", - "address": "192.168.1.2", - "description": "Main network interface." - } -}, -{ - "pk": 3, - "model": "conntrackt.interface", - "fields": { - "netmask": "255.255.255.255", - "entity": 3, - "name": "eth0", - "address": "192.168.1.3", - "description": "Main network interface." - } -}, -{ - "pk": 4, - "model": "conntrackt.interface", - "fields": { - "netmask": "255.255.255.0", - "entity": 4, - "name": "eth0", - "address": "192.168.2.0", - "description": "Main network interface." - } -}, -{ - "pk": 5, - "model": "conntrackt.interface", - "fields": { - "netmask": "255.255.255.255", - "entity": 5, - "name": "eth0", - "address": "192.168.100.1", - "description": "Main network interface." - } -}, -{ - "pk": 1, - "model": "conntrackt.communication", - "fields": { - "source": 2, - "destination": 1, - "protocol": "TCP", - "port": 22, - "description": "SSH." - } -}, -{ - "pk": 2, - "model": "conntrackt.communication", - "fields": { - "source": 2, - "destination": 1, - "protocol": "ICMP", - "port": 8, - "description": "Ping." - } -}, -{ - "pk": 3, - "model": "conntrackt.communication", - "fields": { - "source": 3, - "destination": 1, - "protocol": "TCP", - "port": 3306, - "description": "MySQL." - } -}, -{ - "pk": 4, - "model": "conntrackt.communication", - "fields": { - "source": 1, - "destination": 3, - "protocol": "UDP", - "port": 53, - "description": "DNS." - } -}, -{ - "pk": 5, - "model": "conntrackt.communication", - "fields": { - "source": 4, - "destination": 1, - "protocol": "TCP", - "port": 22, - "description": "SSH." - } -}, -{ - "pk": 6, - "model": "conntrackt.communication", - "fields": { - "source": 1, - "destination": 2, - "protocol": "UDP", - "port": 123, - "description": "NTP." - } -} -] diff --git a/conntrackt/tests/factories.py b/conntrackt/tests/factories.py new file mode 100644 --- /dev/null +++ b/conntrackt/tests/factories.py @@ -0,0 +1,140 @@ +# Third-party application imports. +import factory + +# Application imports. +from conntrackt.models import Project, Location, Entity, Interface, Communication + + +class ProjectFactory(factory.django.DjangoModelFactory): + """ + Factory for producing projects where name is set to "Test Project N", and N + is an increasing sequence. Description is based on name. + """ + + FACTORY_FOR = Project + + @factory.sequence + def name(n): + return "Test Project %d" % n + + description = factory.LazyAttribute(lambda d: "This is %s." % d.name) + + +class LocationFactory(factory.django.DjangoModelFactory): + """ + Factory for producing locations where name is set to "Test Location N", and + N is an increasing sequence. Description is based on name. + """ + + FACTORY_FOR = Location + + @factory.sequence + def name(n): + return "Test Location %d" % n + + description = factory.LazyAttribute(lambda d: "This is %s." % d.name) + + +class ServerInterfaceFactory(factory.django.DjangoModelFactory): + """ + Factory for producing server interfaces. Interface IP address is set to + 192.168.1.N, where N is a sequence. The netmask is always set to + "255.255.255.255". The interface name is always set to eth0. + """ + + FACTORY_FOR = Interface + netmask = "255.255.255.255" + name = "eth0" + + @factory.sequence + def address(n): + return "192.168.1.%d" % (n) + + +class SubnetInterfaceFactory(factory.django.DjangoModelFactory): + """ + Factory for producing subnet "interfaces". Interface IP address is set to + 10.10.N.0, where N is a sequence. Interface name is always set to + switch0. Netmask is set to "255.255.255.0". + """ + + FACTORY_FOR = Interface + netmask = "255.255.255.0" + name = "switch0" + + @factory.sequence + def address(n): + return "10.10.%d.0" % (n) + + +class ServerEntityFactory(factory.django.DjangoModelFactory): + """ + Factory for producing server entities where name is set to "Test Entity N", + and N is an increasing sequence. + """ + + FACTORY_FOR = Entity + + interface = factory.RelatedFactory(ServerInterfaceFactory, "entity") + + @factory.sequence + def name(n): + return "Test Entity %d" % n + + description = factory.LazyAttribute(lambda d: "This is %s." % d.name) + + +class SubnetEntityFactory(factory.django.DjangoModelFactory): + """ + Factory for producing subnet entities where name is set to "Test Subnet N", + and N is an increasing sequence. + """ + + FACTORY_FOR = Entity + + interface = factory.RelatedFactory(SubnetInterfaceFactory, "entity") + + @factory.sequence + def name(n): + return "Test Subnet %d" % n + + description = factory.LazyAttribute(lambda d: "This is %s." % d.name) + + +class CommunicationFactory(factory.django.DjangoModelFactory): + """ + Factory for producing communications. The descriptin of communication will + be based on protocol and port. + """ + + FACTORY_FOR = Communication + + description = factory.LazyAttribute(lambda d: "Communicate over %s:%s" % (d.protocol, d.port)) + + +def setup_test_data(): + """ + Sets-up some test data for testing more complex functionality. + """ + + for factory in ProjectFactory, LocationFactory, ServerEntityFactory, SubnetEntityFactory, ServerInterfaceFactory, SubnetInterfaceFactory, CommunicationFactory: + factory.reset_sequence() + + project1 = ProjectFactory(pk=1) + project2 = ProjectFactory(pk=2) + + location1 = LocationFactory(pk=1) + location2 = LocationFactory(pk=2) + + entity1 = ServerEntityFactory(pk=1, project=project1, location=location1) + entity2 = ServerEntityFactory(pk=2, project=project1, location=location1) + entity3 = ServerEntityFactory(pk=3, project=project1, location=location2) + entity4 = SubnetEntityFactory(pk=4, project=project1, location=location2) + entity5 = ServerEntityFactory(pk=5, project=project2, location=location1) + + communication1 = CommunicationFactory(pk=1, source_id=2, destination_id=1, protocol="TCP", port="22") + communication2 = CommunicationFactory(pk=2, source_id=2, destination_id=1, protocol="ICMP", port="8") + communication3 = CommunicationFactory(pk=3, source_id=3, destination_id=1, protocol="TCP", port="3306") + communication4 = CommunicationFactory(pk=4, source_id=1, destination_id=3, protocol="UDP", port="53") + communication5 = CommunicationFactory(pk=5, source_id=4, destination_id=1, protocol="TCP", port="22") + communication6 = CommunicationFactory(pk=6, source_id=1, destination_id=2, protocol="UDP", port="123") diff --git a/conntrackt/tests/test_models.py b/conntrackt/tests/test_models.py --- a/conntrackt/tests/test_models.py +++ b/conntrackt/tests/test_models.py @@ -6,6 +6,13 @@ from django.test import TestCase # Application imports. from conntrackt.models import Project, Location, Entity, Interface, Communication +# Test imports. +from .factories import ProjectFactory, LocationFactory +from .factories import ServerEntityFactory, ServerInterfaceFactory +from .factories import SubnetEntityFactory, SubnetInterfaceFactory +from .factories import CommunicationFactory +from .factories import setup_test_data + class ProjectTest(TestCase): @@ -14,18 +21,16 @@ class ProjectTest(TestCase): Test if unique project name is enforced. """ - project1 = Project(name="Test Project", description="This is a test project.") - project1.save() + project = ProjectFactory() - project2 = Project(name="Test Project", description="This is a test project.") - self.assertRaises(IntegrityError, project2.save) + self.assertRaises(IntegrityError, ProjectFactory, name=project.name) def test_representation(self): """ Test the representation of project. """ - project = Project(name="Test Project", description="This is a test project.") + project = ProjectFactory(name="Test Project") self.assertEqual(str(project), "Test Project") @@ -34,7 +39,7 @@ class ProjectTest(TestCase): Tests if the absolute URL is generated properly. """ - project = Project(pk=1, name="Test Project", description="This is a test project.") + project = ProjectFactory(pk=1) self.assertEqual(project.get_absolute_url(), "/conntrackt/project/1/") @@ -43,27 +48,31 @@ class LocationTest(TestCase): def test_unique_name(self): """ - Test if unique locationn name is enforced. + Test if unique location name is enforced. """ - location1 = Location(name="Test Location", description="This is a test location.") - location1.save() + location = LocationFactory() - location2 = Location(name="Test Location", description="This is a test location.") - self.assertRaises(IntegrityError, location2.save) + self.assertRaises(IntegrityError, LocationFactory, name=location.name) def test_representation(self): """ Test the representation of location. """ - project = Location(name="Test Location", description="This is a test location.") + project = LocationFactory(name="Test Location") self.assertEqual(str(project), "Test Location") class EntityTest(TestCase): - fixtures = ['test-data.json'] + + def setUp(cls): + """ + Set-up some test data. + """ + + setup_test_data() def test_incoming_communications(self): """ @@ -71,7 +80,7 @@ class EntityTest(TestCase): data. """ - entity = Entity.objects.get(name="Test Entity 1") + entity = Entity.objects.get(pk=1) incoming = Communication.objects.filter(pk__in=(1, 2, 3, 5)) self.assertItemsEqual(entity.incoming_communications(), incoming) @@ -82,7 +91,7 @@ class EntityTest(TestCase): data. """ - entity = Entity.objects.get(name="Test Entity 1") + entity = Entity.objects.get(pk=1) outgoing = Communication.objects.filter(pk__in=(4, 6)) self.assertItemsEqual(entity.outgoing_communications(), outgoing) @@ -92,7 +101,7 @@ class EntityTest(TestCase): Test the representation of entity. """ - ent = Entity.objects.get(name="Test Entity 1") + ent = Entity.objects.get(pk=1) representation = "Test Entity 1 (Test Project 1 - Test Location 1)" self.assertEqual(str(ent), representation) @@ -104,9 +113,9 @@ class EntityTest(TestCase): entity1 = Entity.objects.get(pk=1) - entity2 = Entity(name=entity1.name, description="Duplicate entity.", project=entity1.project, location=entity1.location) + entity_dup = Entity(name=entity1.name, description="Duplicate entity.", project=entity1.project, location=entity1.location) - self.assertRaises(IntegrityError, entity2.save) + self.assertRaises(IntegrityError, entity_dup.save) def test_absolute_url(self): """ @@ -131,7 +140,13 @@ class EntityTest(TestCase): class InterfaceTest(TestCase): - fixtures = ['test-data.json'] + + def setUp(self): + """ + Set-up some test data. + """ + + setup_test_data() def test_unique_name(self): """ @@ -174,14 +189,20 @@ class InterfaceTest(TestCase): Test representation of subnet. """ - interface = Entity.objects.get(name="Test Subnet").interface_set.get(name="eth0") - representation = "Test Subnet (192.168.2.0/255.255.255.0)" + interface = Entity.objects.get(pk=4).interface_set.get(name="switch0") + representation = "Test Subnet 4 (10.10.4.0/255.255.255.0)" self.assertEqual(str(interface), representation) class CommunicationTest(TestCase): - fixtures = ['test-data.json'] + + def setUp(self): + """ + Set-up some test data. + """ + + setup_test_data() def test_unique_communication(self): """ @@ -197,13 +218,13 @@ class CommunicationTest(TestCase): Test enforcement of same project entities for communications. """ - ent1 = Entity.objects.get(name="Test Entity 1") + ent1 = Entity.objects.get(pk=1) ent1_eth0 = ent1.interface_set.get(name="eth0") - ent2 = Entity.objects.get(name="Other Project Test Entity") - ent2_eth0 = ent2.interface_set.get(name="eth0") + ent5 = Entity.objects.get(pk=5) + ent5_eth0 = ent5.interface_set.get(name="eth0") # Set-up a communication between different projects. - comm = Communication.objects.create(source=ent1_eth0, destination=ent2_eth0, protocol="ICMP", port="8", description="Ping.") + comm = Communication.objects.create(source=ent1_eth0, destination=ent5_eth0, protocol="ICMP", port="8", description="Ping.") self.assertRaisesRegexp(ValidationError, 'Source and destination entities do not belong to the same project', comm.full_clean) @@ -212,7 +233,7 @@ class CommunicationTest(TestCase): Test enforcement of differing entities for communication. """ - ent = Entity.objects.get(name="Test Entity 1") + ent = Entity.objects.get(pk=1) ent_eth0 = ent.interface_set.get(name="eth0") # Set-up a communication between same entity. @@ -225,9 +246,9 @@ class CommunicationTest(TestCase): Test enforcement of supported protocol. """ - ent1 = Entity.objects.get(name="Test Entity 1") + ent1 = Entity.objects.get(pk=1) ent1_eth0 = ent1.interface_set.get(name="eth0") - ent2 = Entity.objects.get(name="Test Entity 2") + ent2 = Entity.objects.get(pk=2) ent2_eth0 = ent2.interface_set.get(name="eth0") comm = Communication(source=ent1_eth0, destination=ent2_eth0, protocol="BOGUS", port="1234") diff --git a/conntrackt/tests/test_utils.py b/conntrackt/tests/test_utils.py --- a/conntrackt/tests/test_utils.py +++ b/conntrackt/tests/test_utils.py @@ -8,11 +8,17 @@ import pydot # Application imports. from conntrackt.models import Entity, Project, Communication from conntrackt import utils +from .factories import setup_test_data class GenerateEntityIptablesTest(TestCase): - fixtures = ['test-data.json'] + def setUp(self): + """ + Set-up some test data. + """ + + setup_test_data() def test_generated_iptables(self): """ @@ -30,15 +36,15 @@ class GenerateEntityIptablesTest(TestCas # Accept all incoming traffic on loopback interface. -A INPUT -i lo -j ACCEPT -# MySQL. --A INPUT -s 192.168.1.3/255.255.255.255 -d 192.168.1.1/255.255.255.255 -p tcp -m tcp --dport 3306 -j ACCEPT - -# Ping. +# Communicate over ICMP:8 -A INPUT -s 192.168.1.2/255.255.255.255 -d 192.168.1.1/255.255.255.255 -p icmp -m icmp --icmp-type 8 -j ACCEPT -# SSH. +# Communicate over TCP:22 -A INPUT -s 192.168.1.2/255.255.255.255 -d 192.168.1.1/255.255.255.255 -p tcp -m tcp --dport 22 -j ACCEPT --A INPUT -s 192.168.2.0/255.255.255.0 -d 192.168.1.1/255.255.255.255 -p tcp -m tcp --dport 22 -j ACCEPT +-A INPUT -s 10.10.4.0/255.255.255.0 -d 192.168.1.1/255.255.255.255 -p tcp -m tcp --dport 22 -j ACCEPT + +# Communicate over TCP:3306 +-A INPUT -s 192.168.1.3/255.255.255.255 -d 192.168.1.1/255.255.255.255 -p tcp -m tcp --dport 3306 -j ACCEPT :OUTPUT ACCEPT [0:0] :FORWARD DROP [0:0] @@ -117,7 +123,12 @@ class GenerateProjectDiagramTest(TestCas Tests the generate_project_diagram function. """ - fixtures = ["test-data.json"] + def setUp(self): + """ + Set-up some test data. + """ + + setup_test_data() def test_unique_entity_colors(self): """ @@ -171,7 +182,7 @@ class GenerateProjectDiagramTest(TestCas diagram = utils.generate_project_diagram(project) # Set-up expected node names. - expected_node_names = ["Test Entity 1", "Test Entity 2", "Test Entity 3", "Test Subnet"] + expected_node_names = [u"Test Entity 1", u"Test Entity 2", u"Test Entity 3", u"Test Subnet 4"] # Get all nodes from diagram. clusters = diagram.get_subgraphs() @@ -204,9 +215,12 @@ class GenerateProjectDiagramTest(TestCas e.get_label().replace('"', '')) for e in edges] # Create list of expected edge labels - expected_edge_labels = ['Test Entity 1 -> Test Entity 2 (UDP:123)', 'Test Entity 1 -> Test Entity 3 (UDP:53)', - 'Test Entity 2 -> Test Entity 1 (ICMP:8)', 'Test Entity 2 -> Test Entity 1 (TCP:22)', - 'Test Entity 3 -> Test Entity 1 (TCP:3306)', 'Test Subnet -> Test Entity 1 (TCP:22)'] + expected_edge_labels = [u'Test Entity 1 -> Test Entity 2 (UDP:123)', + u'Test Entity 1 -> Test Entity 3 (UDP:53)', + u'Test Entity 2 -> Test Entity 1 (ICMP:8)', + u'Test Entity 2 -> Test Entity 1 (TCP:22)', + u'Test Entity 3 -> Test Entity 1 (TCP:3306)', + u'Test Subnet 4 -> Test Entity 1 (TCP:22)'] self.assertEqual(sorted(expected_edge_labels), sorted(edge_labels)) 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).