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.

57 lines
1.9 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="X" * 32)
  10. self.assertEqual(r.status_code, 200)
  11. self.assertEqual(r["Access-Control-Allow-Origin"], "*")
  12. check.refresh_from_db()
  13. self.assertEqual(check.status, "paused")
  14. def test_it_handles_options(self):
  15. check = Check(user=self.alice, status="up")
  16. check.save()
  17. r = self.client.options("/api/v1/checks/%s/pause" % check.code)
  18. self.assertEqual(r.status_code, 204)
  19. self.assertIn("POST", r["Access-Control-Allow-Methods"])
  20. def test_it_only_allows_post(self):
  21. url = "/api/v1/checks/1659718b-21ad-4ed1-8740-43afc6c41524/pause"
  22. r = self.client.get(url, HTTP_X_API_KEY="X" * 32)
  23. self.assertEqual(r.status_code, 405)
  24. def test_it_validates_ownership(self):
  25. check = Check(user=self.bob, status="up")
  26. check.save()
  27. url = "/api/v1/checks/%s/pause" % check.code
  28. r = self.client.post(url, "", content_type="application/json",
  29. HTTP_X_API_KEY="X" * 32)
  30. self.assertEqual(r.status_code, 403)
  31. def test_it_validates_uuid(self):
  32. url = "/api/v1/checks/not-uuid/pause"
  33. r = self.client.post(url, "", content_type="application/json",
  34. HTTP_X_API_KEY="X" * 32)
  35. self.assertEqual(r.status_code, 404)
  36. def test_it_handles_missing_check(self):
  37. url = "/api/v1/checks/07c2f548-9850-4b27-af5d-6c9dc157ec02/pause"
  38. r = self.client.post(url, "", content_type="application/json",
  39. HTTP_X_API_KEY="X" * 32)
  40. self.assertEqual(r.status_code, 404)