1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
From: Colin Watson <cjwatson@debian.org>
Date: Sun, 13 Jul 2025 17:24:59 +0200
Subject: Don't fail tests when example.org DNS changes
The IP addresses for this domain change from time to time, and are
currently round-robin which makes these tests even more awkward. Just
check that the results are well-formed rather than testing the actual
values.
Forwarded: https://code.launchpad.net/~cjwatson/py3dns/+git/py3dns/+merge/488798
Bug-Debian: https://bugs.debian.org/1108799
Last-Update: 2025-07-13
---
DNS/tests/test_base.py | 41 +++++++++++++++++++----------------------
1 file changed, 19 insertions(+), 22 deletions(-)
diff --git a/DNS/tests/test_base.py b/DNS/tests/test_base.py
index 166ea69..763ec07 100644
--- a/DNS/tests/test_base.py
+++ b/DNS/tests/test_base.py
@@ -35,25 +35,25 @@ class TestBase(unittest.TestCase):
a_response = dnsobj.qry(qtype='A', resulttype='text', timeout=1)
self.assertTrue(a_response.answers)
# is the result vaguely ipv4 like?
- self.assertEqual(a_response.answers[0]['data'].count('.'), 3)
- self.assertEqual(a_response.answers[0]['data'],'93.184.215.14')
+ self.assertIsInstance(a_response.answers[0]['data'], str)
+ ipaddress.IPv4Address(a_response.answers[0]['data'])
# Default result type for .qry object is an ipaddress object
ad_response = dnsobj.qry(qtype='A', timeout=1)
self.assertTrue(ad_response.answers)
- self.assertEqual(ad_response.answers[0]['data'],ipaddress.IPv4Address('93.184.215.14'))
+ self.assertIsInstance(ad_response.answers[0]['data'], ipaddress.IPv4Address)
ab_response = dnsobj.qry(qtype='A', resulttype='binary', timeout=1)
self.assertTrue(ab_response.answers)
# is the result ipv4 binary like?
- self.assertEqual(len(ab_response.answers[0]['data']), 4)
- for b in ab_response.answers[0]['data']:
- assertIsByte(b)
- self.assertEqual(ab_response.answers[0]['data'],b']\xb8\xd7\x0e')
+ self.assertIsInstance(ab_response.answers[0]['data'], bytes)
+ ipaddress.IPv4Address(a_response.answers[0]['data'])
ai_response = dnsobj.qry(qtype='A', resulttype='integer', timeout=1)
self.assertTrue(ai_response.answers)
- self.assertEqual(ai_response.answers[0]['data'],1572394766)
+ # IPv4 decimal
+ self.assertIsInstance(ai_response.answers[0]['data'], int)
+ ipaddress.IPv4Address(a_response.answers[0]['data'])
def testDnsRequestAAAA(self):
@@ -62,25 +62,24 @@ class TestBase(unittest.TestCase):
aaaa_response = dnsobj.qry(qtype='AAAA', resulttype='text', timeout=1)
self.assertTrue(aaaa_response.answers)
# does the result look like an ipv6 address?
- self.assertTrue(':' in aaaa_response.answers[0]['data'])
- self.assertEqual(aaaa_response.answers[0]['data'],'2606:2800:21f:cb07:6820:80da:af6b:8b2c')
+ self.assertIsInstance(aaaa_response.answers[0]['data'], str)
+ ipaddress.IPv6Address(aaaa_response.answers[0]['data'])
# default is returning ipaddress object
aaaad_response = dnsobj.qry(qtype='AAAA', timeout=1)
self.assertTrue(aaaad_response.answers)
- self.assertEqual(aaaad_response.answers[0]['data'],ipaddress.IPv6Address('2606:2800:21f:cb07:6820:80da:af6b:8b2c'))
+ self.assertIsInstance(aaaad_response.answers[0]['data'], ipaddress.IPv6Address)
aaaab_response = dnsobj.qry(qtype='AAAA', resulttype='binary', timeout=1)
self.assertTrue(aaaab_response.answers)
# is it ipv6 looking?
- self.assertEqual(len(aaaab_response.answers[0]['data']) , 16)
- for b in aaaab_response.answers[0]['data']:
- assertIsByte(b)
- self.assertEqual(aaaab_response.answers[0]['data'],b'&\x06(\x00\x02\x1f\xcb\x07h \x80\xda\xafk\x8b,')
+ self.assertIsInstance(aaaab_response.answers[0]['data'], bytes)
+ ipaddress.IPv6Address(aaaab_response.answers[0]['data'])
# IPv6 decimal
aaaai_response = dnsobj.qry(qtype='AAAA', resulttype='integer', timeout=1)
self.assertTrue(aaaai_response.answers)
- self.assertEqual(aaaai_response.answers[0]['data'], 50542628918019563700009922510424083244)
+ self.assertIsInstance(aaaai_response.answers[0]['data'], int)
+ ipaddress.IPv6Address(aaaai_response.answers[0]['data'])
def testDnsRequestEmptyMX(self):
dnsobj = DNS.DnsRequest('mail.kitterman.org')
@@ -169,8 +168,8 @@ class TestBase(unittest.TestCase):
ad_response = dnsob.req(qtype='A', timeout=1)
self.assertTrue(ad_response.answers)
# is the result vaguely ipv4 like?
- self.assertEqual(ad_response.answers[0]['data'].count('.'), 3)
- self.assertEqual(ad_response.answers[0]['data'],'93.184.215.14')
+ self.assertIsInstance(ad_response.answers[0]['data'], str)
+ ipaddress.IPv4Address(ad_response.answers[0]['data'])
def testDnsRequestAAAAD(self):
dnsob = DNS.DnsRequest('example.org')
@@ -179,10 +178,8 @@ class TestBase(unittest.TestCase):
aaaad_response = dnsob.req(qtype='AAAA', timeout=1)
self.assertTrue(aaaad_response.answers)
# does the result look like a binary ipv6 address?
- self.assertEqual(len(aaaad_response.answers[0]['data']) , 16)
- for b in aaaad_response.answers[0]['data']:
- assertIsByte(b)
- self.assertEqual(aaaad_response.answers[0]['data'],b'&\x06(\x00\x02\x1f\xcb\x07h \x80\xda\xafk\x8b,')
+ self.assertIsInstance(aaaad_response.answers[0]['data'], bytes)
+ ipaddress.IPv6Address(aaaad_response.answers[0]['data'])
def testDnsRequestEmptyMXD(self):
dnsob = DNS.DnsRequest('mail.kitterman.org')
|