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.

31 lines
1.1 KiB

  1. from hc.api.models import Check
  2. from hc.test import BaseTestCase
  3. class DeleteCheckTestCase(BaseTestCase):
  4. def setUp(self):
  5. super().setUp()
  6. self.check = Check.objects.create(project=self.project)
  7. self.url = f"/api/v1/checks/{self.check.code}"
  8. def test_it_works(self):
  9. r = self.client.delete(self.url, HTTP_X_API_KEY="X" * 32)
  10. self.assertEqual(r.status_code, 200)
  11. self.assertEqual(r["Access-Control-Allow-Origin"], "*")
  12. # It should be gone--
  13. self.assertFalse(Check.objects.filter(code=self.check.code).exists())
  14. def test_it_handles_missing_check(self):
  15. url = "/api/v1/checks/07c2f548-9850-4b27-af5d-6c9dc157ec02"
  16. r = self.client.delete(url, HTTP_X_API_KEY="X" * 32)
  17. self.assertEqual(r.status_code, 404)
  18. def test_it_handles_options(self):
  19. r = self.client.options(self.url)
  20. self.assertEqual(r.status_code, 204)
  21. self.assertIn("DELETE", r["Access-Control-Allow-Methods"])
  22. def test_it_handles_missing_api_key(self):
  23. r = self.client.delete(self.url)
  24. self.assertContains(r, "missing api key", status_code=401)