test_service_hooks.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. from django.test.client import RequestFactory
  2. from django.urls import reverse
  3. from fixtures.apidocs_test_case import APIDocsTestCase
  4. from sentry.testutils.silo import region_silo_test
  5. @region_silo_test
  6. class ProjectServiceHooksDocs(APIDocsTestCase):
  7. def setUp(self):
  8. self.create_service_hook(project=self.project, events=("event.created",))
  9. self.create_service_hook(project=self.project, events=("event.alert",))
  10. self.url = reverse(
  11. "sentry-api-0-service-hooks",
  12. kwargs={"organization_slug": self.organization.slug, "project_slug": self.project.slug},
  13. )
  14. self.login_as(user=self.user)
  15. def test_get(self):
  16. with self.feature("projects:servicehooks"):
  17. response = self.client.get(self.url)
  18. request = RequestFactory().get(self.url)
  19. self.validate_schema(request, response)
  20. def test_post(self):
  21. data = {"url": "https://example.com/other-sentry-hook", "events": ["event.created"]}
  22. with self.feature("projects:servicehooks"):
  23. response = self.client.post(self.url, data)
  24. request = RequestFactory().post(self.url, data)
  25. self.validate_schema(request, response)