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.

131 lines
4.8 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_current_project(self):
  29. self.profile.current_project = None
  30. self.profile.save()
  31. self.client.login(username="[email protected]", password="password")
  32. r = self.client.get(self.url)
  33. self.assertEqual(r.status_code, 200)
  34. self.profile.refresh_from_db()
  35. self.assertEqual(self.profile.current_project, self.project)
  36. def test_it_checks_access(self):
  37. self.client.login(username="[email protected]", password="password")
  38. r = self.client.get(self.url)
  39. self.assertEqual(r.status_code, 404)
  40. def test_it_shows_green_check(self):
  41. self.check.last_ping = timezone.now()
  42. self.check.status = "up"
  43. self.check.save()
  44. self.client.login(username="[email protected]", password="password")
  45. r = self.client.get(self.url)
  46. self.assertContains(r, "icon-up")
  47. def test_it_shows_red_check(self):
  48. self.check.last_ping = timezone.now() - td(days=3)
  49. self.check.status = "up"
  50. self.check.save()
  51. self.client.login(username="[email protected]", password="password")
  52. r = self.client.get(self.url)
  53. self.assertContains(r, "icon-down")
  54. def test_it_shows_amber_check(self):
  55. self.check.last_ping = timezone.now() - td(days=1, minutes=30)
  56. self.check.status = "up"
  57. self.check.save()
  58. self.client.login(username="[email protected]", password="password")
  59. r = self.client.get(self.url)
  60. self.assertContains(r, "icon-grace")
  61. def test_it_hides_add_check_button(self):
  62. self.profile.check_limit = 0
  63. self.profile.save()
  64. self.client.login(username="[email protected]", password="password")
  65. r = self.client.get(self.url)
  66. self.assertContains(r, "Check limit reached", status_code=200)
  67. def test_it_saves_sort_field(self):
  68. self.client.login(username="[email protected]", password="password")
  69. self.client.get(self.url + "?sort=name")
  70. self.profile.refresh_from_db()
  71. self.assertEqual(self.profile.sort, "name")
  72. def test_it_ignores_bad_sort_value(self):
  73. self.client.login(username="[email protected]", password="password")
  74. self.client.get(self.url + "?sort=invalid")
  75. self.profile.refresh_from_db()
  76. self.assertEqual(self.profile.sort, "created")
  77. def test_it_shows_started_but_down_badge(self):
  78. self.check.last_start = timezone.now()
  79. self.check.tags = "foo"
  80. self.check.status = "down"
  81. self.check.save()
  82. self.client.login(username="[email protected]", password="password")
  83. r = self.client.get(self.url)
  84. self.assertContains(r, """<div class="btn btn-xs down ">foo</div>""")
  85. def test_it_shows_grace_badge(self):
  86. self.check.last_ping = timezone.now() - td(days=1, minutes=10)
  87. self.check.tags = "foo"
  88. self.check.status = "up"
  89. self.check.save()
  90. self.client.login(username="[email protected]", password="password")
  91. r = self.client.get(self.url)
  92. self.assertContains(r, """<div class="btn btn-xs grace ">foo</div>""")
  93. def test_it_shows_grace_started_badge(self):
  94. self.check.last_start = timezone.now()
  95. self.check.last_ping = timezone.now() - td(days=1, minutes=10)
  96. self.check.tags = "foo"
  97. self.check.status = "up"
  98. self.check.save()
  99. self.client.login(username="[email protected]", password="password")
  100. r = self.client.get(self.url)
  101. self.assertContains(r, """<div class="btn btn-xs grace ">foo</div>""")