test_project_servicehooks.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. from sentry.sentry_apps.models.servicehook import ServiceHook
  2. from sentry.testutils.cases import AcceptanceTestCase
  3. from sentry.testutils.silo import no_silo_test
  4. @no_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. # click "New"
  21. self.browser.click('[data-test-id="new-service-hook"]')
  22. self.browser.wait_until_not('[data-test-id="loading-indicator"]')
  23. assert self.browser.current_url == f"{self.browser.live_server_url}{self.new_hook_path}"
  24. self.browser.element('input[name="url"]').send_keys("https://example.com/hook")
  25. # click "Save Changes"
  26. self.browser.click('form [data-test-id="form-submit"]')
  27. self.browser.wait_until_not('[data-test-id="loading-indicator"]')
  28. assert (
  29. self.browser.current_url == f"{self.browser.live_server_url}{self.list_hooks_path}"
  30. )
  31. hook = ServiceHook.objects.get(project_id=self.project.id)
  32. assert hook.url == "https://example.com/hook"
  33. assert not hook.events
  34. # hopefully click the first service hook
  35. self.browser.click('[data-test-id="project-service-hook"]')
  36. self.browser.wait_until_not('[data-test-id="loading-indicator"]')
  37. assert self.browser.current_url == "{}{}".format(
  38. self.browser.live_server_url,
  39. f"/settings/{self.org.slug}/projects/{self.project.slug}/hooks/{hook.guid}/",
  40. )