test_organization_switch.py 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 region_silo_test
  5. from sentry.utils.retries import TimedRetryPolicy
  6. @region_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_when_visible(
  33. selector='[data-test-id="page-filter-project-selector"]'
  34. )
  35. # Check if the automplete-list has shown up, if that fails we
  36. # want to retry this step.
  37. self.browser.wait_until('[data-test-id="autocomplete-list"]')
  38. def get_project_elements_from_project_selector_dropdown():
  39. selector = '[data-test-id="autocomplete-list"] [data-test-id="badge-display-name"]'
  40. self.browser.wait_until(selector)
  41. return self.browser.find_elements(by=By.CSS_SELECTOR, value=selector)
  42. transition_urls = [
  43. OrganizationSwitchTest.url_creator(page, self.organization.slug)
  44. for page in ["issues", "releases", "discover", "user-feedback"]
  45. ]
  46. with self.settings(SENTRY_SINGLE_ORGANIZATION=False), self.feature(
  47. "organizations:discover"
  48. ):
  49. for transition_url in transition_urls:
  50. navigate_to_issues_page(self.organization.slug)
  51. open_project_selector()
  52. primary_projects_elements = get_project_elements_from_project_selector_dropdown()
  53. OrganizationSwitchTest.expect_projects_element_text_to_match_projects_slug(
  54. primary_projects_elements, self.primary_projects
  55. )
  56. self.browser.get(transition_url)
  57. self.browser.wait_until_not('[data-test-id="loading-indicator"]')
  58. navigate_to_issues_page(self.secondary_organization.slug)
  59. open_project_selector()
  60. secondary_projects_elements = get_project_elements_from_project_selector_dropdown()
  61. OrganizationSwitchTest.expect_projects_element_text_to_match_projects_slug(
  62. secondary_projects_elements, self.secondary_projects
  63. )
  64. @staticmethod
  65. def expect_projects_element_text_to_match_projects_slug(elements, projects):
  66. assert len(elements) == len(projects)
  67. assert {e.text for e in elements} == {p.slug for p in projects}
  68. @staticmethod
  69. def url_creator(page_path, org_slug):
  70. return f"organizations/{org_slug}/{page_path}/"