test_organization_switch.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import pytest
  2. from selenium.common.exceptions import TimeoutException
  3. from selenium.webdriver.common.by import By
  4. from sentry.testutils.cases import AcceptanceTestCase, SnubaTestCase
  5. from sentry.testutils.silo import no_silo_test
  6. from sentry.utils.retries import TimedRetryPolicy
  7. pytestmark = pytest.mark.sentry_metrics
  8. @no_silo_test
  9. class OrganizationSwitchTest(AcceptanceTestCase, SnubaTestCase):
  10. def setUp(self):
  11. super().setUp()
  12. self.primary_projects = [
  13. self.create_project(organization=self.organization, teams=[self.team], name=name)
  14. for name in ["Bengal", "Sumatra", "Siberian"]
  15. ]
  16. self.secondary_organization = self.create_organization(owner=self.user, name="Banana Duck")
  17. self.secondary_team = self.create_team(
  18. organization=self.secondary_organization, name="Second", members=[self.user]
  19. )
  20. self.secondary_projects = [
  21. self.create_project(
  22. organization=self.secondary_organization, teams=[self.secondary_team], name=name
  23. )
  24. for name in ["Gone Goose", "Peaceful Platypus"]
  25. ]
  26. self.login_as(self.user)
  27. def test_organization_switches(self):
  28. def navigate_to_issues_page(org_slug):
  29. issues_url = OrganizationSwitchTest.url_creator("issues", org_slug)
  30. self.browser.get(issues_url)
  31. self.browser.wait_until_not('[data-test-id="loading-indicator"]')
  32. @TimedRetryPolicy.wrap(timeout=20, exceptions=(TimeoutException,))
  33. def open_project_selector():
  34. self.browser.click(selector='[data-test-id="page-filter-project-selector"]')
  35. def get_project_elements_from_project_selector_dropdown():
  36. selector = '[data-test-id="menu-list-item-label"]'
  37. self.browser.wait_until(selector)
  38. return self.browser.find_elements(by=By.CSS_SELECTOR, value=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}/"