Ship name corpus lookup/spin, nickname suggestions, significance UX, site-ideas SMTP, and remove the Logo concepts page and assets.
61 lines
2.1 KiB
Python
61 lines
2.1 KiB
Python
"""Tests for site-idea email helper."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from stork.mail import mailto_url, send_idea_email, smtp_configured
|
|
|
|
|
|
def test_mailto_fallback_when_smtp_unset(monkeypatch) -> None:
|
|
monkeypatch.delenv("STORK_SMTP_HOST", raising=False)
|
|
monkeypatch.delenv("STORK_SMTP_USER", raising=False)
|
|
monkeypatch.delenv("STORK_SMTP_PASSWORD", raising=False)
|
|
monkeypatch.setenv("STORK_IDEAS_TO", "idobkin@gmail.com")
|
|
assert smtp_configured() is False
|
|
result = send_idea_email(idea="Add dark stickers", from_name="Ira", board_id="b_x")
|
|
assert result["sent"] is False
|
|
assert result["via"] == "mailto"
|
|
assert "mailto:idobkin@gmail.com" in str(result["mailto"])
|
|
assert "Add%20dark%20stickers" in str(result["mailto"]) or "dark" in str(result["mailto"])
|
|
|
|
|
|
def test_smtp_send(monkeypatch) -> None:
|
|
monkeypatch.setenv("STORK_SMTP_HOST", "mail.levkine.ca")
|
|
monkeypatch.setenv("STORK_SMTP_PORT", "587")
|
|
monkeypatch.setenv("STORK_SMTP_USER", "alerts@levkine.ca")
|
|
monkeypatch.setenv("STORK_SMTP_PASSWORD", "secret")
|
|
monkeypatch.setenv("STORK_IDEAS_TO", "idobkin@gmail.com")
|
|
|
|
class FakeSMTP:
|
|
def __init__(self, *args, **kwargs) -> None:
|
|
self.sent = None
|
|
|
|
def __enter__(self):
|
|
return self
|
|
|
|
def __exit__(self, *args) -> None:
|
|
return None
|
|
|
|
def ehlo(self) -> None:
|
|
return None
|
|
|
|
def starttls(self, context=None) -> None:
|
|
return None
|
|
|
|
def login(self, user, password) -> None:
|
|
assert user == "alerts@levkine.ca"
|
|
assert password == "secret"
|
|
|
|
def send_message(self, msg) -> None:
|
|
self.sent = msg
|
|
|
|
monkeypatch.setattr("stork.mail.smtplib.SMTP", FakeSMTP)
|
|
result = send_idea_email(idea="Bigger help dialog", from_name="Ilia", board_url="https://stork.levkin.ca/b/x")
|
|
assert result["sent"] is True
|
|
assert result["via"] == "smtp"
|
|
|
|
|
|
def test_mailto_url_encodes() -> None:
|
|
url = mailto_url(subject="Hi", body="Line one\nLine two", to="ilia@levkine.ca")
|
|
assert url.startswith("mailto:ilia@levkine.ca?")
|
|
assert "subject=Hi" in url
|