test_graph_new.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Tests for dak/graph_new.py
  2. # Copyright 2020 Federico Ceratto <federico@debian.org>
  3. # License: GPL-2+
  4. from datetime import datetime, timedelta
  5. from dak.graph_new import gen_stats, process_events
  6. def test_gen_stats():
  7. now = datetime(2012, 8, 13, 0, 17, 49)
  8. q = {
  9. "python-pyknon_1.0-1_amd64": datetime(2012, 8, 12, 13, 46),
  10. "seascope_0.6.1.hgr112-1_amd64": datetime(2012, 8, 12, 13, 46, 6),
  11. "simgear_2.6.0-2_i386": datetime(2012, 8, 12, 13, 46, 8),
  12. "simgear_2.6.0-3_i386": datetime(2012, 8, 12, 13, 46, 10),
  13. "storymaps_1.0-1_i386": datetime(2012, 8, 12, 13, 46, 13),
  14. "telepathy-salut_0.8.0-3_amd64": datetime(2012, 8, 12, 13, 46, 17),
  15. "webauth_4.3.0-1_i386": datetime(2012, 8, 12, 13, 46, 20),
  16. "webauth_4.3.1-1_i386": datetime(2012, 8, 12, 13, 46, 24),
  17. "wifite_2.0r85-1_i386": datetime(2012, 8, 12, 13, 46, 27),
  18. "xwiimote_0.3+20120630-1_amd64": datetime(2012, 8, 12, 13, 46, 28),
  19. "yii_1.1.11-1_amd64": datetime(2012, 8, 12, 13, 46, 30),
  20. "nut_2.6.5-1_amd64": datetime(2012, 8, 13, 0, 17, 49),
  21. }
  22. stats = gen_stats(now, q)
  23. assert stats == (
  24. timedelta(seconds=37909),
  25. timedelta(seconds=37909),
  26. timedelta(seconds=37889),
  27. )
  28. def test_processing():
  29. queue = {}
  30. init_time = last_update = None
  31. events = []
  32. rrdtool_updates, begin_time = process_events(events, last_update, init_time, queue)
  33. assert rrdtool_updates == []
  34. assert queue == {}
  35. events = [
  36. ("a", "Policy Queue ACCEPT", datetime(2020, 11, 19, 0, 0, 1)),
  37. ("x", "ACCEPT-TO-NEW", datetime(2020, 11, 19, 0, 0, 2)),
  38. ("y", "ACCEPT-TO-NEW", datetime(2020, 11, 19, 0, 0, 3)),
  39. ("a", "ACCEPT-TO-NEW", datetime(2020, 11, 22, 0, 0, 1)),
  40. ("b", "ACCEPT-TO-NEW", datetime(2020, 11, 22, 0, 0, 2)),
  41. ("a", "REJECT", datetime(2020, 11, 23, 0, 0, 1)),
  42. ]
  43. # for pname, event, event_time in events:
  44. rrdtool_updates, begin_time = process_events(events, last_update, init_time, queue)
  45. assert queue == {
  46. "b": datetime(2020, 11, 22, 0, 0, 2),
  47. "x": datetime(2020, 11, 19, 0, 0, 2),
  48. "y": datetime(2020, 11, 19, 0, 0, 3),
  49. }
  50. assert rrdtool_updates == ["1606003201:2:2:2", "1606089601:3:3:3"]