test_organization_switch.py 3.6 KB

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