test_NestedNamedQueries.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import unittest, sqlite3, pyparsing
  2. from definitions import ROOT_DIR
  3. import Core.Controller as Ctrl
  4. pcap = ROOT_DIR + "/../resources/test/reference_1998.pcap"
  5. controller = Ctrl.Controller(pcap_file_path=pcap, do_extra_tests=False, non_verbose=False)
  6. controller.load_pcap_statistics(flag_write_file=False, flag_recalculate_stats=True, flag_print_statistics=False)
  7. class UnitTestPyparsing(unittest.TestCase):
  8. def test_nested_query(self):
  9. self.assertEqual(controller.statistics.process_db_query('macaddress(ipaddress in most_used(ipaddress))'),
  10. '08:00:27:a3:83:43')
  11. self.assertEqual(controller.statistics.process_db_query('macaddress(ipaddress in least_used(ipaddress))'),
  12. '52:54:00:12:35:02')
  13. self.assertEqual(controller.statistics.process_db_query('ipaddress(macaddress in least_used(macaddress))'),
  14. '10.0.2.15')
  15. self.assertEqual(controller.statistics.process_db_query('ipaddress(macaddress in most_used(macaddress))'),
  16. ['104.83.103.45',
  17. '13.107.21.200',
  18. '131.253.61.100',
  19. '172.217.23.142',
  20. '172.217.23.174',
  21. '192.168.33.254',
  22. '204.79.197.200',
  23. '23.51.123.27',
  24. '35.161.3.50',
  25. '52.11.17.245',
  26. '52.34.37.177',
  27. '52.39.210.199',
  28. '52.41.250.141',
  29. '52.85.173.182',
  30. '54.149.74.139',
  31. '54.187.98.195',
  32. '54.192.44.108',
  33. '54.192.44.177',
  34. '72.247.178.113',
  35. '72.247.178.67',
  36. '93.184.220.29'])
  37. # semantically incorrect query
  38. with self.assertRaises(sqlite3.OperationalError):
  39. controller.statistics.process_db_query('ipaddress(ipaddress in most_used(macaddress))')
  40. # syntactically incorrect query
  41. with self.assertRaises(pyparsing.ParseException):
  42. controller.statistics.process_db_query('ipaddress(macaddress in most_used(macaddress(ipaddress in'
  43. ' least_used(ipaddress))))')