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.

67 lines
2.3 KiB

9 years ago
9 years ago
9 years ago
9 years ago
8 years ago
8 years ago
8 years ago
  1. from hc.api.models import Check
  2. from hc.test import BaseTestCase
  3. from datetime import timedelta as td
  4. from django.utils import timezone
  5. class MyChecksTestCase(BaseTestCase):
  6. def setUp(self):
  7. super(MyChecksTestCase, self).setUp()
  8. self.check = Check(user=self.alice, name="Alice Was Here")
  9. self.check.save()
  10. def test_it_works(self):
  11. for email in ("[email protected]", "[email protected]"):
  12. self.client.login(username=email, password="password")
  13. r = self.client.get("/checks/")
  14. self.assertContains(r, "Alice Was Here", status_code=200)
  15. def test_it_shows_green_check(self):
  16. self.check.last_ping = timezone.now()
  17. self.check.status = "up"
  18. self.check.save()
  19. self.client.login(username="[email protected]", password="password")
  20. r = self.client.get("/checks/")
  21. self.assertContains(r, "icon-up")
  22. def test_it_shows_red_check(self):
  23. self.check.last_ping = timezone.now() - td(days=3)
  24. self.check.status = "up"
  25. self.check.save()
  26. self.client.login(username="[email protected]", password="password")
  27. r = self.client.get("/checks/")
  28. self.assertContains(r, "icon-down")
  29. def test_it_shows_amber_check(self):
  30. self.check.last_ping = timezone.now() - td(days=1, minutes=30)
  31. self.check.status = "up"
  32. self.check.save()
  33. self.client.login(username="[email protected]", password="password")
  34. r = self.client.get("/checks/")
  35. self.assertContains(r, "icon-grace")
  36. def test_it_hides_add_check_button(self):
  37. self.profile.check_limit = 0
  38. self.profile.save()
  39. self.client.login(username="[email protected]", password="password")
  40. r = self.client.get("/checks/")
  41. self.assertContains(r, "Check limit reached", status_code=200)
  42. def test_it_saves_sort_field(self):
  43. self.client.login(username="[email protected]", password="password")
  44. self.client.get("/checks/?sort=name")
  45. self.profile.refresh_from_db()
  46. self.assertEqual(self.profile.sort, "name")
  47. def test_it_ignores_bad_sort_value(self):
  48. self.client.login(username="[email protected]", password="password")
  49. self.client.get("/checks/?sort=invalid")
  50. self.profile.refresh_from_db()
  51. self.assertEqual(self.profile.sort, "created")