test_accept_organization_invite.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from django.db.models import F
  2. from sentry.models.authprovider import AuthProvider
  3. from sentry.models.organization import Organization
  4. from sentry.testutils.cases import AcceptanceTestCase
  5. from sentry.testutils.silo import no_silo_test
  6. # When we want to set this @region_silo_test, we'll need to configure regions in order for invites to work.
  7. # See the accept_organization_invite.py#get_invite_state logic
  8. @no_silo_test
  9. class AcceptOrganizationInviteTest(AcceptanceTestCase):
  10. def setUp(self):
  11. super().setUp()
  12. self.user = self.create_user("foo@example.com")
  13. self.org = self.create_organization(name="Rowdy Tiger", owner=None)
  14. self.team = self.create_team(organization=self.org, name="Mariachi Band")
  15. self.member = self.create_member(
  16. user=None,
  17. email="bar@example.com",
  18. organization=self.org,
  19. role="owner",
  20. teams=[self.team],
  21. )
  22. def test_invite_simple(self):
  23. self.login_as(self.user)
  24. self.browser.get(self.member.get_invite_link().split("/", 3)[-1])
  25. self.browser.wait_until('[data-test-id="accept-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"]')