test_emails.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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/alert/", "alert"),
  19. ("/debug/mail/digest/", "digest"),
  20. ("/debug/mail/invalid-identity/", "invalid identity"),
  21. ("/debug/mail/invitation/", "invitation"),
  22. ("/debug/mail/report/", "report"),
  23. ("/debug/mail/mfa-added/", "mfa added"),
  24. ("/debug/mail/mfa-removed/", "mfa removed"),
  25. ("/debug/mail/recovery-codes-regenerated/", "recovery codes regenerated"),
  26. ("/debug/mail/password-changed/", "password changed"),
  27. ("/debug/mail/sso-linked", "sso linked"),
  28. ("/debug/mail/sso-unlinked", "sso unlinked"),
  29. ("/debug/mail/sso-unlinked/no-password", "sso unlinked without password"),
  30. )
  31. def read_txt_email_fixture(name: str) -> str:
  32. # "sso unlinked without password"
  33. # => "sso_unlinked_without_password.txt"
  34. filename = name.replace(" ", "_") + ".txt"
  35. with open(get_fixture_path("emails", filename)) as f:
  36. return f.read()
  37. def build_url(path: str, format: str = "html") -> str:
  38. return f"{path}?{urlencode({'format': format, 'seed': b'123'})}"
  39. class EmailTestCase(AcceptanceTestCase):
  40. def setUp(self):
  41. super().setUp()
  42. # This email address is required to match FIXTURES.
  43. self.user = self.create_user("foo@example.com")
  44. self.login_as(self.user)
  45. def test_emails(self):
  46. for url, name in EMAILS:
  47. # HTML output is captured as a snapshot
  48. self.browser.get(build_url(url, "html"))
  49. self.browser.wait_until("#preview")
  50. self.browser.snapshot(f"{name} email html")
  51. # Text output is asserted against static fixture files
  52. self.browser.get(build_url(url, "txt"))
  53. self.browser.wait_until("#preview")
  54. elem = self.browser.find_element(by=By.CSS_SELECTOR, value="#preview pre")
  55. text_src = elem.get_attribute("innerHTML")
  56. fixture_src = read_txt_email_fixture(name)
  57. assert fixture_src == text_src