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.8 KiB

  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.objects.create(project=self.project, status="up")
  9. self.url = "/checks/%s/pause/" % self.check.code
  10. self.redirect_url = "/checks/%s/details/" % 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, self.redirect_url)
  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.client.login(username="[email protected]", password="password")
  23. r = self.client.post(self.url)
  24. self.assertRedirects(r, self.redirect_url)
  25. def test_it_clears_last_start_alert_after(self):
  26. self.check.last_start = now()
  27. self.check.alert_after = self.check.last_start + td(hours=1)
  28. self.check.save()
  29. self.client.login(username="[email protected]", password="password")
  30. self.client.post(self.url)
  31. self.check.refresh_from_db()
  32. self.assertEqual(self.check.last_start, None)
  33. self.assertEqual(self.check.alert_after, None)
  34. def test_it_does_not_redirect_ajax(self):
  35. self.client.login(username="[email protected]", password="password")
  36. r = self.client.post(self.url, HTTP_X_REQUESTED_WITH="XMLHttpRequest")
  37. self.assertEqual(r.status_code, 200)