ソースを参照

style improvements and remove of stackoverflow test

Roey Regev 6 年 前
コミット
a468e4df7d

+ 2 - 4
code/Test/test_NamedQueries.py

@@ -1,11 +1,9 @@
 import unittest, pyparsing
 
-from definitions import ROOT_DIR
+import ID2TLib.TestLibrary as Lib
 import Core.Controller as Ctrl
 
-pcap = ROOT_DIR + "/../resources/test/reference_1998.pcap"
-
-controller = Ctrl.Controller(pcap_file_path=pcap, do_extra_tests=False, non_verbose=False)
+controller = Ctrl.Controller(pcap_file_path=Lib.test_pcap, do_extra_tests=False, non_verbose=False)
 controller.load_pcap_statistics(flag_write_file=False, flag_recalculate_stats=True, flag_print_statistics=False)
 
 allWinSize = [0, 822, 1330, 5082, 8192, 9900, 27060, 35657, 39917, 47030, 50782, 51310, 52202, 52740, 55062, 56492,

+ 6 - 24
code/Test/test_NestedNamedQueries.py

@@ -1,11 +1,9 @@
 import unittest, sqlite3, pyparsing
 
-from definitions import ROOT_DIR
+import ID2TLib.TestLibrary as Lib
 import Core.Controller as Ctrl
 
-pcap = ROOT_DIR + "/../resources/test/reference_1998.pcap"
-
-controller = Ctrl.Controller(pcap_file_path=pcap, do_extra_tests=False, non_verbose=False)
+controller = Ctrl.Controller(pcap_file_path=Lib.test_pcap, do_extra_tests=False, non_verbose=False)
 controller.load_pcap_statistics(flag_write_file=False, flag_recalculate_stats=True, flag_print_statistics=False)
 
 
@@ -22,26 +20,10 @@ class UnitTestPyparsing(unittest.TestCase):
         self.assertEqual(controller.statistics.process_db_query('ipaddress(macaddress in [08:00:27:a3:83:43])'),
                          '10.0.2.15')
         self.assertEqual(controller.statistics.process_db_query('ipaddress(macaddress in most_used(macaddress))'),
-                         ['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',
+                         ['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'])
         # semantically incorrect query
         with self.assertRaises(sqlite3.OperationalError):

+ 5 - 19
code/Test/test_SQLQueries.py

@@ -1,11 +1,9 @@
 import unittest, sqlite3
 
-from definitions import ROOT_DIR
+import ID2TLib.TestLibrary as Lib
 import Core.Controller as Ctrl
 
-pcap = ROOT_DIR + "/../resources/test/reference_1998.pcap"
-
-controller = Ctrl.Controller(pcap_file_path=pcap, do_extra_tests=False, non_verbose=False)
+controller = Ctrl.Controller(pcap_file_path=Lib.test_pcap, do_extra_tests=False, non_verbose=False)
 controller.load_pcap_statistics(flag_write_file=False, flag_recalculate_stats=True, flag_print_statistics=False)
 
 
@@ -17,15 +15,15 @@ class UnitTestPyparsing(unittest.TestCase):
         self.assertEqual(controller.statistics.stats_db.process_db_query(query),
                          controller.statistics.stats_db.process_db_query(query2))
 
-    def test_paranthesis(self):
+    def test_parenthesis(self):
         query = "Select (ipAddress) from (ip_Statistics) where (pktsSent) = (2 + (3))"
         self.assertEqual("72.247.178.67", controller.statistics.stats_db.process_db_query(query))
 
-    def test_noresult(self):
+    def test_noResult(self):
         query = "Select ipAddress from ip_statistics where ipaddress = 'abc'"
         self.assertEqual([], controller.statistics.stats_db.process_db_query(query))
 
-    def test_severaloperator(self):
+    def test_severalOperator(self):
         query1 = "Select ipAddress from ip_Statistics where pktsSent = '5'"
         query2 = "Select ipAddress from ip_Statistics where pktsSent < '5'"
         query3 = "Select ipAddress from ip_Statistics where pktsSent <= '5'"
@@ -38,18 +36,6 @@ class UnitTestPyparsing(unittest.TestCase):
         self.assertEqual("10.0.2.15", controller.statistics.stats_db.process_db_query(query4))
         self.assertEqual(["10.0.2.15", "172.217.23.174"], controller.statistics.stats_db.process_db_query(query5))
 
-        # too long query (stackoverflow)
-        with self.assertRaises(sqlite3.OperationalError):
-            query = "Select ipAddress from ip_statistics where pktsSent = "
-            i = 0
-            while (i < 15):
-                query += "(Select pktsSent from ip_statistics where pktsSent ="
-                i += 1
-            query += "5"
-            while (i > 0):
-                query += ")"
-                i -= 1
-            controller.statistics.stats_db.process_db_query(query)
         # compare of tables with different dimension
         with self.assertRaises(sqlite3.OperationalError):
             controller.statistics.stats_db.process_db_query('Select ipAddress from ip_Statistics where pktsSent'

+ 6 - 26
code/Test/test_pyparsing_functionality.py → code/Test/test_internalQueries.py

@@ -1,35 +1,15 @@
 import unittest
 
-from definitions import ROOT_DIR
+import ID2TLib.TestLibrary as Lib
 import Core.Controller as Ctrl
 
-pcap = ROOT_DIR + "/../resources/test/reference_1998.pcap"
-
-controller = Ctrl.Controller(pcap_file_path=pcap, do_extra_tests=False, non_verbose=False)
+controller = Ctrl.Controller(pcap_file_path=Lib.test_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']
+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_functionality(self):

+ 0 - 3
code/definitions.py

@@ -1,3 +0,0 @@
-import os
-
-ROOT_DIR = os.path.dirname(os.path.abspath(__file__))