test_accept_organization_invite.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from django.db.models import F
  2. from sentry.models import AuthProvider, Organization
  3. from sentry.testutils.cases import AcceptanceTestCase
  4. from sentry.testutils.silo import control_silo_test
  5. # When we want to set this stable=True, we'll need to configure regions in order for invites to work.
  6. # See the accept_organization_invite.py#get_invite_state logic
  7. @control_silo_test
  8. class AcceptOrganizationInviteTest(AcceptanceTestCase):
  9. def setUp(self):
  10. super().setUp()
  11. self.user = self.create_user("foo@example.com")
  12. self.org = self.create_organization(name="Rowdy Tiger", owner=None)
  13. self.team = self.create_team(organization=self.org, name="Mariachi Band")
  14. self.member = self.create_member(
  15. user=None,
  16. email="bar@example.com",
  17. organization=self.org,
  18. role="owner",
  19. teams=[self.team],
  20. )
  21. def test_invite_simple(self):
  22. self.login_as(self.user)
  23. self.browser.get(self.member.get_invite_link().split("/", 3)[-1])
  24. self.browser.wait_until('[data-test-id="accept-invite"]')
  25. self.browser.snapshot(name="accept organization invite")
  26. assert self.browser.element_exists('[data-test-id="join-organization"]')
  27. def test_invite_not_authenticated(self):
  28. self.browser.get(self.member.get_invite_link().split("/", 3)[-1])
  29. self.browser.wait_until('[data-test-id="accept-invite"]')
  30. assert self.browser.element_exists('[data-test-id="create-account"]')
  31. def test_invite_2fa_enforced_org(self):
  32. self.org.update(flags=F("flags").bitor(Organization.flags.require_2fa))
  33. self.browser.get(self.member.get_invite_link().split("/", 3)[-1])
  34. self.browser.wait_until('[data-test-id="accept-invite"]')
  35. assert not self.browser.element_exists_by_test_id("2fa-warning")
  36. self.login_as(self.user)
  37. self.org.update(flags=F("flags").bitor(Organization.flags.require_2fa))
  38. self.browser.get(self.member.get_invite_link().split("/", 3)[-1])
  39. self.browser.wait_until('[data-test-id="accept-invite"]')
  40. assert self.browser.element_exists_by_test_id("2fa-warning")
  41. def test_invite_sso_org(self):
  42. AuthProvider.objects.create(organization_id=self.org.id, provider="google")
  43. self.browser.get(self.member.get_invite_link().split("/", 3)[-1])
  44. self.browser.wait_until('[data-test-id="accept-invite"]')
  45. assert self.browser.element_exists_by_test_id("action-info-sso")
  46. assert self.browser.element_exists('[data-test-id="sso-login"]')