diff --git a/conntrackt/tests/test_models.py b/conntrackt/tests/test_models.py --- a/conntrackt/tests/test_models.py +++ b/conntrackt/tests/test_models.py @@ -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):