Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump mypy from 1.8.0 to 1.9.0 #4495

Merged
merged 2 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions emails/tests/views_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1990,6 +1990,36 @@ def test_reply_requires_premium_test(rf, forwarded, content_type, caplog):
pytest.fail(message)


def get_text_and_html_content(msg: EmailMessage) -> tuple[str, str]:
"""
Return the plain text and HTML content of an email message.

This replaces the legacy function msg.get_payload(). Another
option is get_body(), which will return the first match.
"""
text_content: str | None = None
html_content: str | None = None
for part in msg.walk():
content_type = part.get_content_type()
if content_type == "text/plain":
if text_content is None:
text_content = part.get_content()
else:
raise Exception("Second plain text section found.")
elif content_type == "text/html":
if html_content is None:
html_content = part.get_content()
else:
raise Exception("Second HTML section found.")
elif content_type.startswith("multipart/"):
pass
else:
raise ValueError(f"Unexpected content type {content_type}")
assert text_content is not None, "Plain text not found"
assert html_content is not None, "HTML not found"
return text_content, html_content


@pytest.mark.django_db
def test_build_reply_requires_premium_email_first_time_includes_forward_text():
# First create a valid reply record from an external sender to a free Relay user
Expand Down Expand Up @@ -2032,9 +2062,7 @@ def test_build_reply_requires_premium_email_first_time_includes_forward_text():
assert msg["From"] == expected_From
assert msg["To"] == relay_address.full_address

text_part, html_part = msg.get_payload()
text_content = text_part.get_payload()
html_content = html_part.get_payload()
text_content, html_content = get_text_and_html_content(msg)
assert "sent this reply" in text_content
assert "sent this reply" in html_content

Expand Down Expand Up @@ -2086,9 +2114,7 @@ def test_build_reply_requires_premium_email_after_forward():
assert msg["From"] == expected_From
assert msg["To"] == relay_address.full_address

text_part, html_part = msg.get_payload()
text_content = text_part.get_payload()
html_content = html_part.get_payload()
text_content, html_content = get_text_and_html_content(msg)
assert "Your reply was not sent" in text_content
assert "Your reply was not sent" in html_content

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ botocore-stubs==1.34.59
django-stubs==4.2.6
djangorestframework-stubs==3.14.4
mypy-boto3-ses==1.34.0
mypy==1.8.0
mypy==1.9.0
types-pyOpenSSL==24.0.0.20240228
types-requests==2.31.0.20240310