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.

127 lines
4.7 KiB

9 years ago
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(project=self.project, name="Alice Was Here")
  9. self.check.save()
  10. self.url = "/projects/%s/checks/" % self.project.code
  11. def test_it_works(self):
  12. for email in ("[email protected]", "[email protected]"):
  13. self.client.login(username=email, password="password")
  14. r = self.client.get(self.url)
  15. self.assertContains(r, "Alice Was Here", status_code=200)
  16. # last_active_date should have been set
  17. self.profile.refresh_from_db()
  18. self.assertTrue(self.profile.last_active_date)
  19. def test_it_bumps_last_active_date(self):
  20. self.profile.last_active_date = timezone.now() - td(days=10)
  21. self.profile.save()
  22. self.client.login(username="[email protected]", password="password")
  23. self.client.get(self.url)
  24. # last_active_date should have been bumped
  25. self.profile.refresh_from_db()
  26. delta = timezone.now() - self.profile.last_active_date
  27. self.assertTrue(delta.total_seconds() < 1)
  28. def test_it_updates_session(self):
  29. self.client.login(username="[email protected]", password="password")
  30. r = self.client.get(self.url)
  31. self.assertEqual(r.status_code, 200)
  32. self.assertEqual(self.client.session["last_project_id"], self.project.id)
  33. def test_it_checks_access(self):
  34. self.client.login(username="[email protected]", password="password")
  35. r = self.client.get(self.url)
  36. self.assertEqual(r.status_code, 404)
  37. def test_it_shows_green_check(self):
  38. self.check.last_ping = timezone.now()
  39. self.check.status = "up"
  40. self.check.save()
  41. self.client.login(username="[email protected]", password="password")
  42. r = self.client.get(self.url)
  43. self.assertContains(r, "icon-up")
  44. def test_it_shows_red_check(self):
  45. self.check.last_ping = timezone.now() - td(days=3)
  46. self.check.status = "up"
  47. self.check.save()
  48. self.client.login(username="[email protected]", password="password")
  49. r = self.client.get(self.url)
  50. self.assertContains(r, "icon-down")
  51. def test_it_shows_amber_check(self):
  52. self.check.last_ping = timezone.now() - td(days=1, minutes=30)
  53. self.check.status = "up"
  54. self.check.save()
  55. self.client.login(username="[email protected]", password="password")
  56. r = self.client.get(self.url)
  57. self.assertContains(r, "icon-grace")
  58. def test_it_hides_add_check_button(self):
  59. self.profile.check_limit = 0
  60. self.profile.save()
  61. self.client.login(username="[email protected]", password="password")
  62. r = self.client.get(self.url)
  63. self.assertContains(r, "Check limit reached", status_code=200)
  64. def test_it_saves_sort_field(self):
  65. self.client.login(username="[email protected]", password="password")
  66. self.client.get(self.url + "?sort=name")
  67. self.profile.refresh_from_db()
  68. self.assertEqual(self.profile.sort, "name")
  69. def test_it_ignores_bad_sort_value(self):
  70. self.client.login(username="[email protected]", password="password")
  71. self.client.get(self.url + "?sort=invalid")
  72. self.profile.refresh_from_db()
  73. self.assertEqual(self.profile.sort, "created")
  74. def test_it_shows_started_but_down_badge(self):
  75. self.check.last_start = timezone.now()
  76. self.check.tags = "foo"
  77. self.check.status = "down"
  78. self.check.save()
  79. self.client.login(username="[email protected]", password="password")
  80. r = self.client.get(self.url)
  81. self.assertContains(r, """<div class="btn btn-xs down ">foo</div>""")
  82. def test_it_shows_grace_badge(self):
  83. self.check.last_ping = timezone.now() - td(days=1, minutes=10)
  84. self.check.tags = "foo"
  85. self.check.status = "up"
  86. self.check.save()
  87. self.client.login(username="[email protected]", password="password")
  88. r = self.client.get(self.url)
  89. self.assertContains(r, """<div class="btn btn-xs grace ">foo</div>""")
  90. def test_it_shows_grace_started_badge(self):
  91. self.check.last_start = timezone.now()
  92. self.check.last_ping = timezone.now() - td(days=1, minutes=10)
  93. self.check.tags = "foo"
  94. self.check.status = "up"
  95. self.check.save()
  96. self.client.login(username="[email protected]", password="password")
  97. r = self.client.get(self.url)
  98. self.assertContains(r, """<div class="btn btn-xs grace ">foo</div>""")