test_service_hooks.py 1.2 KB

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