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.

116 lines
4.2 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. def test_it_updates_current_project(self):
  17. self.profile.current_project = None
  18. self.profile.save()
  19. self.client.login(username="[email protected]", password="password")
  20. r = self.client.get(self.url)
  21. self.assertEqual(r.status_code, 200)
  22. self.profile.refresh_from_db()
  23. self.assertEqual(self.profile.current_project, self.project)
  24. def test_it_checks_access(self):
  25. self.client.login(username="[email protected]", password="password")
  26. r = self.client.get(self.url)
  27. self.assertEqual(r.status_code, 404)
  28. def test_it_shows_green_check(self):
  29. self.check.last_ping = timezone.now()
  30. self.check.status = "up"
  31. self.check.save()
  32. self.client.login(username="[email protected]", password="password")
  33. r = self.client.get(self.url)
  34. self.assertContains(r, "icon-up")
  35. def test_it_shows_red_check(self):
  36. self.check.last_ping = timezone.now() - td(days=3)
  37. self.check.status = "up"
  38. self.check.save()
  39. self.client.login(username="[email protected]", password="password")
  40. r = self.client.get(self.url)
  41. self.assertContains(r, "icon-down")
  42. def test_it_shows_amber_check(self):
  43. self.check.last_ping = timezone.now() - td(days=1, minutes=30)
  44. self.check.status = "up"
  45. self.check.save()
  46. self.client.login(username="[email protected]", password="password")
  47. r = self.client.get(self.url)
  48. self.assertContains(r, "icon-grace")
  49. def test_it_hides_add_check_button(self):
  50. self.profile.check_limit = 0
  51. self.profile.save()
  52. self.client.login(username="[email protected]", password="password")
  53. r = self.client.get(self.url)
  54. self.assertContains(r, "Check limit reached", status_code=200)
  55. def test_it_saves_sort_field(self):
  56. self.client.login(username="[email protected]", password="password")
  57. self.client.get(self.url + "?sort=name")
  58. self.profile.refresh_from_db()
  59. self.assertEqual(self.profile.sort, "name")
  60. def test_it_ignores_bad_sort_value(self):
  61. self.client.login(username="[email protected]", password="password")
  62. self.client.get(self.url + "?sort=invalid")
  63. self.profile.refresh_from_db()
  64. self.assertEqual(self.profile.sort, "created")
  65. def test_it_shows_started_but_down_badge(self):
  66. self.check.last_start = timezone.now()
  67. self.check.tags = "foo"
  68. self.check.status = "down"
  69. self.check.save()
  70. self.client.login(username="[email protected]", password="password")
  71. r = self.client.get(self.url)
  72. self.assertContains(r, """<div class="btn btn-xs down ">foo</div>""")
  73. def test_it_shows_grace_badge(self):
  74. self.check.last_ping = timezone.now() - td(days=1, minutes=10)
  75. self.check.tags = "foo"
  76. self.check.status = "up"
  77. self.check.save()
  78. self.client.login(username="[email protected]", password="password")
  79. r = self.client.get(self.url)
  80. self.assertContains(r, """<div class="btn btn-xs grace ">foo</div>""")
  81. def test_it_shows_grace_started_badge(self):
  82. self.check.last_start = timezone.now()
  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>""")