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

  1. from hc.api.models import Check
  2. from hc.test import BaseTestCase
  3. class PauseTestCase(BaseTestCase):
  4. def test_it_works(self):
  5. check = Check(user=self.alice, status="up")
  6. check.save()
  7. url = "/api/v1/checks/%s/pause" % check.code
  8. r = self.client.post(url, "", content_type="application/json",
  9. HTTP_X_API_KEY="abc")
  10. self.assertEqual(r.status_code, 200)
  11. check.refresh_from_db()
  12. self.assertEqual(check.status, "paused")
  13. def test_it_only_allows_post(self):
  14. url = "/api/v1/checks/1659718b-21ad-4ed1-8740-43afc6c41524/pause"
  15. r = self.client.get(url, HTTP_X_API_KEY="abc")
  16. self.assertEqual(r.status_code, 405)
  17. def test_it_validates_ownership(self):
  18. check = Check(user=self.bob, status="up")
  19. check.save()
  20. url = "/api/v1/checks/%s/pause" % check.code
  21. r = self.client.post(url, "", content_type="application/json",
  22. HTTP_X_API_KEY="abc")
  23. self.assertEqual(r.status_code, 403)
  24. def test_it_validates_uuid(self):
  25. url = "/api/v1/checks/not-uuid/pause"
  26. r = self.client.post(url, "", content_type="application/json",
  27. HTTP_X_API_KEY="abc")
  28. self.assertEqual(r.status_code, 404)
  29. def test_it_handles_missing_check(self):
  30. url = "/api/v1/checks/07c2f548-9850-4b27-af5d-6c9dc157ec02/pause"
  31. r = self.client.post(url, "", content_type="application/json",
  32. HTTP_X_API_KEY="abc")
  33. self.assertEqual(r.status_code, 404)