From 044039d0656bd3b35522fb830821ea215a1c2793 Mon Sep 17 00:00:00 2001 From: Joshua Tauberer Date: Wed, 22 Nov 2023 16:35:00 -0500 Subject: [PATCH] Improve code coverage with a domain that returns NOANSWER instead of NXDOMAIN --- tests/mocked-dns-answers.json | 24 ++++++++++++++++++++++++ tests/test_deliverability.py | 7 ++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/tests/mocked-dns-answers.json b/tests/mocked-dns-answers.json index 7e43747..19e443c 100644 --- a/tests/mocked-dns-answers.json +++ b/tests/mocked-dns-answers.json @@ -60,6 +60,30 @@ "\"v=spf1 -all\"" ] }, + { + "query": { + "name": "justtxt.joshdata.me", + "type": "MX", + "class": "IN" + }, + "answer": [] + }, + { + "query": { + "name": "justtxt.joshdata.me", + "type": "A", + "class": "IN" + }, + "answer": [] + }, + { + "query": { + "name": "justtxt.joshdata.me", + "type": "AAAA", + "class": "IN" + }, + "answer": [] + }, { "query": { "name": "mail.example", diff --git a/tests/test_deliverability.py b/tests/test_deliverability.py index 7431668..5c52c10 100644 --- a/tests/test_deliverability.py +++ b/tests/test_deliverability.py @@ -21,7 +21,7 @@ def test_deliverability_found(): def test_deliverability_fails(): - # No MX record. + # Domain does not exist. domain = 'xkxufoekjvjfjeodlfmdfjcu.com' with pytest.raises(EmailUndeliverableError, match=f'The domain name {domain} does not exist'): validate_email_deliverability(domain, domain, dns_resolver=RESOLVER) @@ -36,6 +36,11 @@ def test_deliverability_fails(): with pytest.raises(EmailUndeliverableError, match=f'The domain name {domain} does not send email'): validate_email_deliverability(domain, domain, dns_resolver=RESOLVER) + # No MX or A/AAAA records, but some other DNS records must + # exist such that the response is NOANSWER instead of NXDOMAIN. + domain = 'justtxt.joshdata.me' + with pytest.raises(EmailUndeliverableError, match=f'The domain name {domain} does not accept email'): + validate_email_deliverability(domain, domain, dns_resolver=RESOLVER) @pytest.mark.parametrize( 'email_input',