Changeset - 30e997a9d6c9
[Not reviewed]
default
0 2 1
Branko Majic (branko) - 11 years ago 2013-06-25 23:31:01
branko@majic.rs
Added test fixtures. Switched tests to use fixed textures. Minor clean-up of homepage template.
3 files changed with 282 insertions and 3 deletions:
0 comments (0 inline, 0 general)
conntrackt/fixtures/test-data.json
Show inline comments
 
new file 100644
 
[
 
{
 
  "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."
 
  }
 
}
 
]
conntrackt/templates/conntrackt/index.html
Show inline comments
 
@@ -4,8 +4,12 @@
 
{% load conntrackt_tags %}
 

	
 
{% block content %}
 
<h1>Welcome to Conntrackt</h1>
 
<div>Below you may find the list of projects that are available to you. Clicking on the project will take you to the summary page for that particular project. Clicking on an entity inside of a project will take you to the summary page of an entity.</div>
 
<div class="row">
 
  <h1>Welcome to Conntrackt</h1>
 
</div>
 
<div class="row">
 
    <div>Below you may find the list of projects that are available to you. Clicking on the project will take you to the summary page for that particular project. Clicking on an entity inside of a project will take you to the summary page of an entity.</div>
 
</div>
 
<hr>
 
<div class="row">
 
{% if projects %}
 
@@ -15,7 +19,7 @@
 
  </div>
 
  {% endfor %}
 
{% else %}
 
  <div class="span12">Currently there are no project defined in the database. Use the administration pages in order to add a new project.</div>
 
  <div>Currently there are no projects defined in the database. Use the administration pages in order to add a new project.</div>
 
{% endif %}
 
</div>
 

	
conntrackt/tests/test_models.py
Show inline comments
 
# Django imports.
 
from django.core.exceptions import ValidationError
 
from django.db import IntegrityError
 
from django.test import TestCase
 

	
 
# Application imports.
 
from conntrackt.models import Project, Location, Entity, Interface, Communication
 

	
 

	
 
class EntityTest(TestCase):
 
    fixtures = ['test-data.json']
 

	
 
    def test_incoming_communications(self):
 
        """
 
        Test that we get correct list of incoming connections with the sample
 
        data.
 
        """
 

	
 
        entity = Entity.objects.get(name="Test Entity 1")
 
        incoming = Communication.objects.filter(pk__in=(1, 2, 3, 5))
 

	
 
        self.assertItemsEqual(entity.incoming_communications(), incoming)
 

	
 
    def test_outgoing_communications(self):
 
        """
 
        Test that we get correct list of outgoing connections with the sample
 
        data.
 
        """
 

	
 
        entity = Entity.objects.get(name="Test Entity 1")
 
        outgoing = Communication.objects.filter(pk__in=(4, 6))
 

	
 
        self.assertItemsEqual(entity.outgoing_communications(), outgoing)
 

	
 
    def test_unique_communication(self):
 
        """
 
        Test enforcement of unique communications.
 
        """
 

	
 
        comm = Communication.objects.get(pk=1)
 

	
 
        self.assertRaises(IntegrityError, Communication.objects.create, source=comm.source, destination=comm.destination, protocol=comm.protocol, port=comm.port, description="Duplicate communication.")
 

	
 
    def test_project_same(self):
 
        """
 
        Test enforcement of same project entities for communications.
 
        """
 

	
 
        ent1 = Entity.objects.get(name="Test Entity 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")
 

	
 
        # Set-up a communication between different projects.
 
        comm = Communication.objects.create(source=ent1_eth0, destination=ent2_eth0, protocol="ICMP", port="8", description="Ping.")
 

	
 
        self.assertRaises(ValidationError, comm.full_clean)
 

	
 
    def test_unsupported_protocol(self):
 
        """
 
        Test enforcement of supported protocol.
 
        """
 

	
 
        ent1 = Entity.objects.get(name="Test Entity 1")
 
        ent1_eth0 = ent1.interface_set.get(name="eth0")
 
        ent2 = Entity.objects.get(name="Test Entity 2")
 
        ent2_eth0 = ent1.interface_set.get(name="eth0")
 

	
 
        comm = Communication(source=ent1_eth0, destination=ent2_eth0, protocol="BOGUS", port="1234")
 
        self.assertRaises(ValidationError, comm.full_clean)
0 comments (0 inline, 0 general)