Changeset - 321777f25793
[Not reviewed]
default
0 1 0
Branko Majic (branko) - 11 years ago 2013-07-03 21:38:56
branko@majic.rs
Added tests for models Project and Location. Added tests for uniqueness constraints. Added tests for getting absolute URL.
1 file changed with 90 insertions and 0 deletions:
0 comments (0 inline, 0 general)
conntrackt/tests/test_models.py
Show inline comments
 
@@ -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.
0 comments (0 inline, 0 general)