You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.4 KiB

  1. from datetime import timedelta as td
  2. from django.test import TestCase
  3. from django.utils import timezone
  4. from hc.api.models import Check
  5. class CheckModelTestCase(TestCase):
  6. def test_it_handles_new_check(self):
  7. check = Check()
  8. self.assertEqual(check.going_down_after(), None)
  9. def test_it_handles_paused_check(self):
  10. check = Check(status="paused")
  11. check.last_ping = timezone.now() - td(days=2)
  12. self.assertEqual(check.going_down_after(), None)
  13. def test_it_handles_up(self):
  14. check = Check(status="up")
  15. check.last_ping = timezone.now() - td(hours=1)
  16. expected_aa = check.last_ping + td(days=1, hours=1)
  17. self.assertEqual(check.going_down_after(), expected_aa)
  18. def test_it_handles_paused_then_started_check(self):
  19. check = Check(status="paused")
  20. check.last_start = timezone.now() - td(days=2)
  21. expected_aa = check.last_start + td(hours=1)
  22. self.assertEqual(check.going_down_after(), expected_aa)
  23. def test_it_handles_down(self):
  24. check = Check(status="down")
  25. check.last_ping = timezone.now() - td(hours=1)
  26. self.assertEqual(check.going_down_after(), None)
  27. def test_it_handles_down_then_started_check(self):
  28. check = Check(status="down")
  29. check.last_start = timezone.now() - td(minutes=10)
  30. self.assertEqual(check.going_down_after(), None)