Changeset - a960569196d0
[Not reviewed]
default
0 2 0
Branko Majic (branko) - 10 years ago 2013-11-09 19:00:25
branko@majic.rs
CONNT-17: PEP8 styling fix. Added tests for the communications summary method.
2 files changed with 59 insertions and 1 deletions:
0 comments (0 inline, 0 general)
conntrackt/models.py
Show inline comments
 
@@ -181,13 +181,13 @@ class Project(RelatedCollectorMixin, mod
 
        for communication in Communication.objects.filter(source__entity__project=self).select_related().order_by("source__entity__pk"):
 
            communications.append({"source": communication.source.entity.name,
 
                                   "source_color": entity_colors[communication.source.entity.pk],
 
                                   "destination": communication.destination.entity.name,
 
                                   "destination_color": entity_colors[communication.destination.entity.pk],
 
                                   "protocol": communication.protocol,
 
                                   "port": communication.port,})
 
                                   "port": communication.port})
 

	
 
        # Finally return the result.
 
        return communications
 

	
 

	
 
class Location(RelatedCollectorMixin, models.Model):
conntrackt/tests/test_models.py
Show inline comments
 
@@ -20,12 +20,13 @@
 

	
 
# Standard Python library import.
 
import collections
 

	
 
# Python third-party library imports.
 
import mock
 
from palette import Color
 

	
 
# Django imports.
 
from django.core.exceptions import ValidationError
 
from django.db import IntegrityError
 
from django.db.models import Model
 
from django.test import TestCase
 
@@ -176,12 +177,69 @@ class ProjectTest(TestCase):
 
        """
 
        Tests if the custom manager is being used.
 
        """
 

	
 
        self.assertIsInstance(Project.objects, SearchManager)
 

	
 
    def test_get_project_communications_summary_count(self):
 
        """
 
        Test if the method returns correct number of entries in the list.
 
        """
 

	
 
        # Set-up some test data to work with.
 
        setup_test_data()
 

	
 
        # Get the first project from test data.
 
        project = Project.objects.get(pk=1)
 

	
 
        # Fetch the project communications
 
        communications = project.get_project_communications_summary()
 

	
 
        # Validate the number of returned communications.
 
        self.assertEqual(len(communications), 6)
 

	
 
    def test_get_project_communications_summary_return_value(self):
 
        """
 
        Test if the method returns correct type.
 
        """
 

	
 
        # Set-up some test data.
 
        setup_test_data()
 

	
 
        # Fetch one of the projects.
 
        project = Project.objects.get(pk=1)
 

	
 
        # Get the communications summary for the project.
 
        communications = project.get_project_communications_summary()
 

	
 
        # Validate the return value type.
 
        self.assertIsInstance(communications, list)
 

	
 
        # Perform verification on every summary element returned.
 
        for comm in communications:
 
            # Verify the type of element and its size.
 
            self.assertIsInstance(comm, dict)
 
            self.assertEqual(len(comm), 6)
 

	
 
            # Verify the presence of correct dictionary keys.
 
            keys = comm.keys()
 
            self.assertIn("source", keys)
 
            self.assertIn("source_color", keys)
 
            self.assertIn("destination", keys)
 
            self.assertIn("destination_color", keys)
 
            self.assertIn("protocol", keys)
 
            self.assertIn("port", keys)
 

	
 
            # Verify the value types.
 
            self.assertIsInstance(comm["source"], unicode)
 
            self.assertIsInstance(comm["source_color"], Color)
 
            self.assertIsInstance(comm["destination"], unicode)
 
            self.assertIsInstance(comm["destination_color"], Color)
 
            self.assertIsInstance(comm["protocol"], unicode)
 
            self.assertIsInstance(comm["port"], int)
 

	
 

	
 
class LocationTest(TestCase):
 

	
 
    def test_unique_name(self):
 
        """
 
        Test if unique location name is enforced.
0 comments (0 inline, 0 general)