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.

47 lines
1.6 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. self.assertFalse(check.is_down())
  10. def test_it_handles_paused_check(self):
  11. check = Check(status="paused")
  12. check.last_ping = timezone.now() - td(days=2)
  13. self.assertEqual(check.going_down_after(), None)
  14. self.assertFalse(check.is_down())
  15. def test_it_handles_up(self):
  16. check = Check(status="up")
  17. check.last_ping = timezone.now() - td(hours=1)
  18. expected_aa = check.last_ping + td(days=1, hours=1)
  19. self.assertEqual(check.going_down_after(), expected_aa)
  20. self.assertFalse(check.is_down())
  21. def test_it_handles_paused_then_started_check(self):
  22. check = Check(status="paused")
  23. check.last_start = timezone.now() - td(days=2)
  24. expected_aa = check.last_start + td(hours=1)
  25. self.assertEqual(check.going_down_after(), expected_aa)
  26. self.assertTrue(check.is_down())
  27. def test_it_handles_down(self):
  28. check = Check(status="down")
  29. check.last_ping = timezone.now() - td(hours=1)
  30. self.assertEqual(check.going_down_after(), None)
  31. self.assertTrue(check.is_down())
  32. def test_it_handles_down_then_started_check(self):
  33. check = Check(status="down")
  34. check.last_start = timezone.now() - td(minutes=10)
  35. self.assertEqual(check.going_down_after(), None)
  36. self.assertTrue(check.is_down())