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.

98 lines
3.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. 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")
  52. def test_it_shows_started_but_down_badge(self):
  53. self.check.last_start = timezone.now()
  54. self.check.tags = "foo"
  55. self.check.status = "down"
  56. self.check.save()
  57. self.client.login(username="[email protected]", password="password")
  58. r = self.client.get("/checks/")
  59. self.assertContains(r, """<div class="btn btn-xs down ">foo</div>""")
  60. def test_it_shows_grace_badge(self):
  61. self.check.last_ping = timezone.now() - td(days=1, minutes=10)
  62. self.check.tags = "foo"
  63. self.check.status = "up"
  64. self.check.save()
  65. self.client.login(username="[email protected]", password="password")
  66. r = self.client.get("/checks/")
  67. self.assertContains(r, """<div class="btn btn-xs grace ">foo</div>""")
  68. def test_it_shows_grace_started_badge(self):
  69. self.check.last_start = timezone.now()
  70. self.check.last_ping = timezone.now() - td(days=1, minutes=10)
  71. self.check.tags = "foo"
  72. self.check.status = "up"
  73. self.check.save()
  74. self.client.login(username="[email protected]", password="password")
  75. r = self.client.get("/checks/")
  76. self.assertContains(r, """<div class="btn btn-xs grace ">foo</div>""")