test_emails.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. from urllib.parse import urlencode
  2. from selenium.webdriver.common.by import By
  3. from sentry.testutils import AcceptanceTestCase
  4. from sentry.testutils.factories import get_fixture_path
  5. EMAILS = (
  6. ("/debug/mail/assigned/", "assigned"),
  7. ("/debug/mail/assigned/self/", "assigned self"),
  8. ("/debug/mail/note/", "note"),
  9. ("/debug/mail/regression/", "regression"),
  10. ("/debug/mail/regression/release/", "regression with version"),
  11. ("/debug/mail/new-release/", "release"),
  12. ("/debug/mail/resolved/", "resolved"),
  13. ("/debug/mail/resolved-in-release/", "resolved in release"),
  14. ("/debug/mail/resolved-in-release/upcoming/", "resolved in release upcoming"),
  15. ("/debug/mail/unassigned/", "unassigned"),
  16. ("/debug/mail/unable-to-fetch-commits/", "unable to fetch commits"),
  17. ("/debug/mail/unable-to-delete-repo/", "unable to delete repo"),
  18. ("/debug/mail/error-alert/", "alert"),
  19. # ("/debug/mail/performance-alert/", "performance"), # TODO(ceo) this is flaky
  20. ("/debug/mail/digest/", "digest"),
  21. ("/debug/mail/invalid-identity/", "invalid identity"),
  22. ("/debug/mail/invitation/", "invitation"),
  23. ("/debug/mail/report/", "report"),
  24. ("/debug/mail/mfa-added/", "mfa added"),
  25. ("/debug/mail/mfa-removed/", "mfa removed"),
  26. ("/debug/mail/recovery-codes-regenerated/", "recovery codes regenerated"),
  27. ("/debug/mail/password-changed/", "password changed"),
  28. ("/debug/mail/sso-linked", "sso linked"),
  29. ("/debug/mail/sso-unlinked", "sso unlinked"),
  30. ("/debug/mail/sso-unlinked/no-password", "sso unlinked without password"),
  31. )
  32. def read_txt_email_fixture(name: str) -> str:
  33. # "sso unlinked without password"
  34. # => "sso_unlinked_without_password.txt"
  35. filename = name.replace(" ", "_") + ".txt"
  36. with open(get_fixture_path("emails", filename)) as f:
  37. return f.read()
  38. def build_url(path: str, format: str = "html") -> str:
  39. return f"{path}?{urlencode({'format': format, 'seed': b'123'})}"
  40. class EmailTestCase(AcceptanceTestCase):
  41. def setUp(self):
  42. super().setUp()
  43. # This email address is required to match FIXTURES.
  44. self.user = self.create_user("foo@example.com")
  45. self.login_as(self.user)
  46. def test_emails(self):
  47. for url, name in EMAILS:
  48. # HTML output is captured as a snapshot
  49. self.browser.get(build_url(url, "html"))
  50. self.browser.wait_until("#preview")
  51. self.browser.snapshot(f"{name} email html")
  52. # Text output is asserted against static fixture files
  53. self.browser.get(build_url(url, "txt"))
  54. self.browser.wait_until("#preview")
  55. elem = self.browser.find_element(by=By.CSS_SELECTOR, value="#preview pre")
  56. text_src = elem.get_attribute("innerHTML")
  57. fixture_src = read_txt_email_fixture(name)
  58. assert fixture_src == text_src