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.

82 lines
2.6 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. # Desktop
  22. self.assertContains(r, "icon-up")
  23. # Mobile
  24. self.assertContains(r, "label-up")
  25. def test_it_shows_red_check(self):
  26. self.check.last_ping = timezone.now() - td(days=3)
  27. self.check.status = "up"
  28. self.check.save()
  29. self.client.login(username="[email protected]", password="password")
  30. r = self.client.get("/checks/")
  31. # Desktop
  32. self.assertContains(r, "icon-down")
  33. # Mobile
  34. self.assertContains(r, "label-down")
  35. def test_it_shows_amber_check(self):
  36. self.check.last_ping = timezone.now() - td(days=1, minutes=30)
  37. self.check.status = "up"
  38. self.check.save()
  39. self.client.login(username="[email protected]", password="password")
  40. r = self.client.get("/checks/")
  41. # Desktop
  42. self.assertContains(r, "icon-grace")
  43. # Mobile
  44. self.assertContains(r, "label-grace")
  45. def test_it_hides_add_check_button(self):
  46. self.profile.check_limit = 0
  47. self.profile.save()
  48. self.client.login(username="[email protected]", password="password")
  49. r = self.client.get("/checks/")
  50. self.assertContains(r, "Check limit reached", status_code=200)
  51. def test_it_saves_sort_field(self):
  52. self.client.login(username="[email protected]", password="password")
  53. self.client.get("/checks/?sort=name")
  54. self.profile.refresh_from_db()
  55. self.assertEqual(self.profile.sort, "name")
  56. def test_it_ignores_bad_sort_value(self):
  57. self.client.login(username="[email protected]", password="password")
  58. self.client.get("/checks/?sort=invalid")
  59. self.profile.refresh_from_db()
  60. self.assertEqual(self.profile.sort, "created")