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
 
@@ -184,7 +184,7 @@ class Project(RelatedCollectorMixin, mod
 
                                   "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
conntrackt/tests/test_models.py
Show inline comments
 
@@ -23,6 +23,7 @@ import collections
 

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

	
 
# Django imports.
 
from django.core.exceptions import ValidationError
 
@@ -179,6 +180,63 @@ class ProjectTest(TestCase):
 

	
 
        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):
 

	
0 comments (0 inline, 0 general)