test_organization_switch.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. from selenium.common.exceptions import TimeoutException
  2. from selenium.webdriver.common.by import By
  3. from sentry.testutils.cases import AcceptanceTestCase, SnubaTestCase
  4. from sentry.testutils.silo import no_silo_test
  5. from sentry.utils.retries import TimedRetryPolicy
  6. @no_silo_test
  7. class OrganizationSwitchTest(AcceptanceTestCase, SnubaTestCase):
  8. def setUp(self):
  9. super().setUp()
  10. self.primary_projects = [
  11. self.create_project(organization=self.organization, teams=[self.team], name=name)
  12. for name in ["Bengal", "Sumatra", "Siberian"]
  13. ]
  14. self.secondary_organization = self.create_organization(owner=self.user, name="Banana Duck")
  15. self.secondary_team = self.create_team(
  16. organization=self.secondary_organization, name="Second", members=[self.user]
  17. )
  18. self.secondary_projects = [
  19. self.create_project(
  20. organization=self.secondary_organization, teams=[self.secondary_team], name=name
  21. )
  22. for name in ["Gone Goose", "Peaceful Platypus"]
  23. ]
  24. self.login_as(self.user)
  25. def test_organization_switches(self):
  26. def navigate_to_issues_page(org_slug):
  27. issues_url = OrganizationSwitchTest.url_creator("issues", org_slug)
  28. self.browser.get(issues_url)
  29. self.browser.wait_until_not('[data-test-id="loading-indicator"]')
  30. @TimedRetryPolicy.wrap(timeout=20, exceptions=(TimeoutException,))
  31. def open_project_selector():
  32. self.browser.click(selector='[data-test-id="page-filter-project-selector"]')
  33. def get_project_elements_from_project_selector_dropdown():
  34. selector = '[data-test-id="menu-list-item-label"]'
  35. self.browser.wait_until(selector)
  36. return self.browser.find_elements(by=By.CSS_SELECTOR, value=selector)
  37. transition_urls = [
  38. OrganizationSwitchTest.url_creator(page, self.organization.slug)
  39. for page in ["issues", "releases", "discover", "user-feedback"]
  40. ]
  41. with self.settings(SENTRY_SINGLE_ORGANIZATION=False), self.feature(
  42. "organizations:discover"
  43. ):
  44. for transition_url in transition_urls:
  45. navigate_to_issues_page(self.organization.slug)
  46. open_project_selector()
  47. primary_projects_elements = get_project_elements_from_project_selector_dropdown()
  48. OrganizationSwitchTest.expect_projects_element_text_to_match_projects_slug(
  49. primary_projects_elements, self.primary_projects
  50. )
  51. self.browser.get(transition_url)
  52. self.browser.wait_until_not('[data-test-id="loading-indicator"]')
  53. navigate_to_issues_page(self.secondary_organization.slug)
  54. open_project_selector()
  55. secondary_projects_elements = get_project_elements_from_project_selector_dropdown()
  56. OrganizationSwitchTest.expect_projects_element_text_to_match_projects_slug(
  57. secondary_projects_elements, self.secondary_projects
  58. )
  59. @staticmethod
  60. def expect_projects_element_text_to_match_projects_slug(elements, projects):
  61. assert len(elements) == len(projects)
  62. assert {e.text for e in elements} == {p.slug for p in projects}
  63. @staticmethod
  64. def url_creator(page_path, org_slug):
  65. return f"organizations/{org_slug}/{page_path}/"