test_organization_switch.py 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 (
  44. self.settings(SENTRY_SINGLE_ORGANIZATION=False),
  45. self.feature("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}/"