|
@@ -7,6 +7,61 @@ from django.test import TestCase
|
|
|
from conntrackt.models import Project, Location, Entity, Interface, Communication
|
|
|
|
|
|
|
|
|
class ProjectTest(TestCase):
|
|
|
|
|
|
def test_unique_name(self):
|
|
|
"""
|
|
|
Test if unique project name is enforced.
|
|
|
"""
|
|
|
|
|
|
project1 = Project(name="Test Project", description="This is a test project.")
|
|
|
project1.save()
|
|
|
|
|
|
project2 = Project(name="Test Project", description="This is a test project.")
|
|
|
self.assertRaises(IntegrityError, project2.save)
|
|
|
|
|
|
def test_representation(self):
|
|
|
"""
|
|
|
Test the representation of project.
|
|
|
"""
|
|
|
|
|
|
project = Project(name="Test Project", description="This is a test project.")
|
|
|
|
|
|
self.assertEqual(str(project), "Test Project")
|
|
|
|
|
|
def test_absolute_url(self):
|
|
|
"""
|
|
|
Tests if the absolute URL is generated properly.
|
|
|
"""
|
|
|
|
|
|
project = Project(pk=1, name="Test Project", description="This is a test project.")
|
|
|
|
|
|
self.assertEqual(project.get_absolute_url(), "/conntrackt/project/1/")
|
|
|
|
|
|
|
|
|
class LocationTest(TestCase):
|
|
|
|
|
|
def test_unique_name(self):
|
|
|
"""
|
|
|
Test if unique locationn name is enforced.
|
|
|
"""
|
|
|
|
|
|
location1 = Location(name="Test Location", description="This is a test location.")
|
|
|
location1.save()
|
|
|
|
|
|
location2 = Location(name="Test Location", description="This is a test location.")
|
|
|
self.assertRaises(IntegrityError, location2.save)
|
|
|
|
|
|
def test_representation(self):
|
|
|
"""
|
|
|
Test the representation of location.
|
|
|
"""
|
|
|
|
|
|
project = Location(name="Test Location", description="This is a test location.")
|
|
|
|
|
|
self.assertEqual(str(project), "Test Location")
|
|
|
|
|
|
|
|
|
class EntityTest(TestCase):
|
|
|
fixtures = ['test-data.json']
|
|
|
|
|
@@ -43,9 +98,44 @@ class EntityTest(TestCase):
|
|
|
self.assertEqual(str(ent), representation)
|
|
|
|
|
|
|
|
|
def test_unique_name(self):
|
|
|
"""
|
|
|
Test if unique entity name is enforced across same project.
|
|
|
"""
|
|
|
|
|
|
entity1 = Entity.objects.get(pk=1)
|
|
|
|
|
|
entity2 = Entity(name=entity1.name, description="Duplicate entity.", project=entity1.project, location=entity1.location)
|
|
|
|
|
|
self.assertRaises(IntegrityError, entity2.save)
|
|
|
|
|
|
def test_absolute_url(self):
|
|
|
"""
|
|
|
Tests if the absolute URL is generated properly.
|
|
|
"""
|
|
|
|
|
|
entity = Entity.objects.get(pk=1)
|
|
|
|
|
|
self.assertEqual(entity.get_absolute_url(), "/conntrackt/entity/1/")
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
interface = entity.interface_set.get(pk=1)
|
|
|
|
|
|
duplicate = Interface(name=interface.name, description = "Duplicate interface.", entity=entity, address="10.10.10.10", netmask="255.255.255.255")
|
|
|
|
|
|
self.assertRaises(IntegrityError, duplicate.save)
|
|
|
|
|
|
|
|
|
def test_representation_single(self):
|
|
|
"""
|
|
|
Test representation of single IP address.
|