Parcourir la source

added tests for functions using pyparsing

Roey Regev il y a 6 ans
Parent
commit
32f56440c5
2 fichiers modifiés avec 43 ajouts et 3 suppressions
  1. 2 0
      code/Test/test_NamedQueries.py
  2. 41 3
      code/Test/test_pyparsing_functionality.py

+ 2 - 0
code/Test/test_NamedQueries.py

@@ -31,6 +31,8 @@ class UnitTestPyparsing(unittest.TestCase):
                          65535)
         self.assertEqual(controller.statistics.process_db_query('most_used(ipclass)'),
                          'A')
+       # self.assertEqual(controller.statistics.process_db_query('least_used(ipclass)'),
+        #                 ['A-private', 'C', 'C-private'])
         self.assertEqual(controller.statistics.process_db_query('avg(pktsreceived)'),
                          90.36363636363636)
         self.assertEqual(controller.statistics.process_db_query('avg(pktssent)'),

+ 41 - 3
code/Test/test_pyparsing_functionality.py

@@ -8,8 +8,46 @@ pcap = ROOT_DIR + "/../resources/test/reference_1998.pcap"
 controller = Ctrl.Controller(pcap_file_path=pcap, do_extra_tests=False, non_verbose=False)
 controller.load_pcap_statistics(flag_write_file=False, flag_recalculate_stats=True, flag_print_statistics=False)
 
+ipAddresses = ['10.0.2.15',
+ '104.83.103.45',
+ '13.107.21.200',
+ '131.253.61.100',
+ '172.217.23.142',
+ '172.217.23.174',
+ '192.168.33.254',
+ '204.79.197.200',
+ '23.51.123.27',
+ '35.161.3.50',
+ '52.11.17.245',
+ '52.34.37.177',
+ '52.39.210.199',
+ '52.41.250.141',
+ '52.85.173.182',
+ '54.149.74.139',
+ '54.187.98.195',
+ '54.192.44.108',
+ '54.192.44.177',
+ '72.247.178.113',
+ '72.247.178.67',
+ '93.184.220.29']
 
 class UnitTestPyparsing(unittest.TestCase):
-    def test_nested_query(self):
-        self.assertEqual(1,1)
-        #TODO Write tests
+    def test_functionality(self):
+        self.assertEqual(controller.statistics.get_pps_sent('10.0.2.15'),32)
+        self.assertEqual(controller.statistics.get_general_file_statistics(), [('Avg. packet rate', 78.57034301757812,
+                                                                                'packets/sec'),('Avg. packet size', 0.0,
+                                                                                'kbytes'),('Avg. packets sent', 90.0,
+                                                                                'packets'),('Avg. bandwidth in',
+                                                                                9.529011726379395, 'kbit/s'),
+                                                                               ('Avg. bandwidth out', 9.529012680053711,
+                                                                                'kbit/s')])
+        self.assertEqual(controller.statistics.get_most_used_ip_address(), '10.0.2.15')
+        self.assertEqual(controller.statistics.get_ttl_distribution('10.0.2.15'), {128: 817})
+        self.assertEqual(controller.statistics.get_mss_distribution('10.0.2.15'), {1460: 36})
+        self.assertEqual(controller.statistics.get_tos_distribution('10.0.2.15'), {0: 817})
+        self.assertEqual(controller.statistics.get_ip_address_count(), 22)
+        self.assertEqual(controller.statistics.get_ip_addresses(), ipAddresses)
+        self.assertEqual(controller.statistics.get_ip_address_from_mac('08:00:27:a3:83:43'), '10.0.2.15')
+        self.assertEqual(controller.statistics.get_mac_address('10.0.2.15'), '08:00:27:a3:83:43')
+        self.assertEqual(controller.statistics.get_most_used_mss('10.0.2.15'), 1460)
+        self.assertEqual(controller.statistics.get_most_used_ttl('10.0.2.15'), 128)