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.

48 lines
1.6 KiB

6 years ago
  1. from datetime import timedelta as td
  2. from django.utils.timezone import now
  3. from hc.api.models import Check
  4. from hc.test import BaseTestCase
  5. class PauseTestCase(BaseTestCase):
  6. def setUp(self):
  7. super(PauseTestCase, self).setUp()
  8. self.check = Check(user=self.alice, status="up", project=self.project)
  9. self.check.save()
  10. self.url = "/checks/%s/pause/" % self.check.code
  11. def test_it_pauses(self):
  12. self.client.login(username="[email protected]", password="password")
  13. r = self.client.post(self.url)
  14. self.assertRedirects(r, "/checks/")
  15. self.check.refresh_from_db()
  16. self.assertEqual(self.check.status, "paused")
  17. def test_it_rejects_get(self):
  18. self.client.login(username="[email protected]", password="password")
  19. r = self.client.get(self.url)
  20. self.assertEqual(r.status_code, 405)
  21. def test_it_allows_cross_team_access(self):
  22. self.bobs_profile.current_team = None
  23. self.bobs_profile.save()
  24. self.client.login(username="[email protected]", password="password")
  25. r = self.client.post(self.url)
  26. self.assertRedirects(r, "/checks/")
  27. def test_it_clears_last_start_alert_after(self):
  28. self.check.last_start = now()
  29. self.check.alert_after = self.check.last_start + td(hours=1)
  30. self.check.save()
  31. self.client.login(username="[email protected]", password="password")
  32. self.client.post(self.url)
  33. self.check.refresh_from_db()
  34. self.assertEqual(self.check.last_start, None)
  35. self.assertEqual(self.check.alert_after, None)