handle case address.parse can also parse an URL and return UrlAddress

This commit is contained in:
Son 2021-10-17 12:52:34 +02:00
parent 7bfdb821af
commit 283a6a530d
2 changed files with 9 additions and 0 deletions

View File

@ -1321,4 +1321,9 @@ def parse_full_address(full_address) -> (str, str):
full_address: EmailAddress = address.parse(full_address)
if full_address is None:
raise ValueError
# address.parse can also parse an URL and return UrlAddress
if type(full_address) is not EmailAddress:
raise ValueError
return full_address.display_name, full_address.address

View File

@ -3,6 +3,7 @@ import os
from email.message import EmailMessage
import arrow
import pytest
from app.config import MAX_ALERT_24H, EMAIL_DOMAIN, BOUNCE_EMAIL, ROOT_DIR
from app.db import Session
@ -134,6 +135,9 @@ def test_parse_full_address():
"abcd@gmail.com",
)
with pytest.raises(ValueError):
parse_full_address("https://ab.cd")
def test_send_email_with_rate_control(flask_client):
user = User.create(