test_project_servicehooks.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from sentry.models import ServiceHook
  2. from sentry.testutils import AcceptanceTestCase
  3. from sentry.testutils.silo import region_silo_test
  4. @region_silo_test
  5. class ProjectServiceHooksTest(AcceptanceTestCase):
  6. def setUp(self):
  7. super().setUp()
  8. self.user = self.create_user("foo@example.com")
  9. self.org = self.create_organization(name="Rowdy Tiger", owner=None)
  10. self.team = self.create_team(organization=self.org, name="Mariachi Band")
  11. self.project = self.create_project(organization=self.org, teams=[self.team], name="Bengal")
  12. self.create_member(user=self.user, organization=self.org, role="owner", teams=[self.team])
  13. self.login_as(self.user)
  14. self.list_hooks_path = f"/settings/{self.org.slug}/projects/{self.project.slug}/hooks/"
  15. self.new_hook_path = f"/settings/{self.org.slug}/projects/{self.project.slug}/hooks/new/"
  16. def test_simple(self):
  17. with self.feature("projects:servicehooks"):
  18. self.browser.get(self.list_hooks_path)
  19. self.browser.wait_until_not('[data-test-id="loading-indicator"]')
  20. self.browser.snapshot("project settings - service hooks - empty list")
  21. # click "New"
  22. self.browser.click('[data-test-id="new-service-hook"]')
  23. self.browser.wait_until_not('[data-test-id="loading-indicator"]')
  24. assert self.browser.current_url == f"{self.browser.live_server_url}{self.new_hook_path}"
  25. self.browser.snapshot("project settings - service hooks - create")
  26. self.browser.element('input[name="url"]').send_keys("https://example.com/hook")
  27. # click "Save Changes"
  28. self.browser.click('form [data-test-id="form-submit"]')
  29. self.browser.wait_until_not('[data-test-id="loading-indicator"]')
  30. assert (
  31. self.browser.current_url == f"{self.browser.live_server_url}{self.list_hooks_path}"
  32. )
  33. self.browser.snapshot("project settings - service hooks - list with entries")
  34. hook = ServiceHook.objects.get(project_id=self.project.id)
  35. assert hook.url == "https://example.com/hook"
  36. assert not hook.events
  37. # hopefully click the first service hook
  38. self.browser.click('[data-test-id="project-service-hook"]')
  39. self.browser.wait_until_not('[data-test-id="loading-indicator"]')
  40. assert self.browser.current_url == "{}{}".format(
  41. self.browser.live_server_url,
  42. f"/settings/{self.org.slug}/projects/{self.project.slug}/hooks/{hook.guid}/",
  43. )
  44. self.browser.snapshot("project settings - service hooks - details")