test_emails.py 2.7 KB

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