test_organization_switch.py 3.5 KB

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