Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 52b24c6

Browse files
Added a few more tests to improve code coverage (#163)
1 parent 6bc4589 commit 52b24c6

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

‎tests/mocked-dns-answers.json‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
"type": "A",
130130
"class": "IN"
131131
},
132-
"answer": []
132+
"answer": ["127.0.0.1"]
133133
},
134134
{
135135
"query": {
@@ -139,6 +139,30 @@
139139
},
140140
"answer": []
141141
},
142+
{
143+
"query": {
144+
"name": "ipv6only.joshdata.me",
145+
"type": "MX",
146+
"class": "IN"
147+
},
148+
"answer": []
149+
},
150+
{
151+
"query": {
152+
"name": "ipv6only.joshdata.me",
153+
"type": "A",
154+
"class": "IN"
155+
},
156+
"answer": []
157+
},
158+
{
159+
"query": {
160+
"name": "ipv6only.joshdata.me",
161+
"type": "AAAA",
162+
"class": "IN"
163+
},
164+
"answer": ["::1"]
165+
},
142166
{
143167
"query": {
144168
"name": "mail.example",

‎tests/test_deliverability.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def test_deliverability_found(domain: str, expected_response: str) -> None:
3535
# No MX or A/AAAA records, but some other DNS records must
3636
# exist such that the response is NOANSWER instead of NXDOMAIN.
3737
('justtxt.joshdata.me', 'The domain name {domain} does not accept email'),
38+
('ipv6only.joshdata.me', 'The domain name {domain} does not accept email'),
3839
],
3940
)
4041
def test_deliverability_fails(domain: str, error: str) -> None:
@@ -65,6 +66,11 @@ def test_deliverability_dns_timeout() -> None:
6566
assert response.get("unknown-deliverability") == "timeout"
6667

6768

69+
def test_timeout_and_resolver() -> None:
70+
with pytest.raises(ValueError, match="It's not valid to pass both timeout and dns_resolver."):
71+
validate_email_deliverability('timeout.com', 'timeout.com', timeout=1, dns_resolver=RESOLVER)
72+
73+
6874
@pytest.mark.network
6975
def test_caching_dns_resolver() -> None:
7076
class TestCache:

‎tests/test_main.py‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import typing
12
import pytest
23

34
from email_validator import validate_email, EmailSyntaxError
@@ -16,6 +17,14 @@ def test_dict_accessor() -> None:
1617
assert valid_email.as_dict()["original"] == input_email
1718

1819

20+
def test_dict_accessor_with_domain_address() -> None:
21+
input_email = "me@[127.0.0.1]"
22+
valid_email = validate_email(input_email, check_deliverability=False, allow_domain_literal=True)
23+
assert valid_email.domain == "[127.0.0.1]"
24+
assert isinstance(valid_email.as_dict(), dict)
25+
assert valid_email.as_dict()["domain_address"] == '"IPv4Address(\'127.0.0.1\')"'
26+
27+
1928
def test_main_single_good_input(monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]) -> None:
2029
import json
2130
test_email = "google@google.com"
@@ -65,3 +74,21 @@ def test_deprecation() -> None:
6574
valid_email = validate_email(input_email, check_deliverability=False)
6675
with pytest.deprecated_call():
6776
assert valid_email.email is not None
77+
78+
79+
@pytest.mark.parametrize('invalid_email', [
80+
None,
81+
12345,
82+
[],
83+
{},
84+
lambda x: x,
85+
])
86+
def test_invalid_type(invalid_email: typing.Any) -> None:
87+
with pytest.raises(TypeError, match="email must be str or bytes"):
88+
validate_email(invalid_email, check_deliverability=False)
89+
90+
91+
def test_invalid_ascii() -> None:
92+
invalid_email = b'\xd0\xba\xd0\xb2\xd1\x96\xd1\x82\xd0\xbe\xd1\x87\xd0\xba\xd0\xb0@\xd0\xbf\xd0\xbe\xd1\x88\xd1\x82\xd0\xb0.test'
93+
with pytest.raises(EmailSyntaxError, match="The email address is not valid ASCII."):
94+
validate_email(invalid_email, check_deliverability=False)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /