summaryrefslogtreecommitdiff
path: root/tests/test_rdata.py
diff options
context:
space:
mode:
authorBrian Wellington <bwelling@xbill.org>2020-04-02 11:04:08 -0700
committerBrian Wellington <bwelling@xbill.org>2020-04-02 11:04:08 -0700
commit50752b18d423ef0755a4a08cd8ca531698c1165e (patch)
tree190b752378c7bb0656d67a406c87548edbebdf54 /tests/test_rdata.py
parent84c65c7b30c7bf1fd52fdd5307900e71e479f3f9 (diff)
downloaddnspython-50752b18d423ef0755a4a08cd8ca531698c1165e.tar.gz
Add dns.rdata.Rdata.replace()
Now that Rdata instances are immutable, there needs to be a way to make a new Rdata based on an existing one. replace() creates a clone of the current Rdata, overriding fields with the specified parameters.
Diffstat (limited to 'tests/test_rdata.py')
-rw-r--r--tests/test_rdata.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/test_rdata.py b/tests/test_rdata.py
index 7c2c6a5..aed8804 100644
--- a/tests/test_rdata.py
+++ b/tests/test_rdata.py
@@ -47,5 +47,22 @@ class RdataTestCase(unittest.TestCase):
dns.rdata.register_type(tests.ttxt_module, TTXTTWO, 'TTXTTWO')
self.assertRaises(dns.rdata.RdatatypeExists, bad)
+ def test_replace(self):
+ a1 = dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, "1.2.3.4")
+ a2 = dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, "2.3.4.5")
+ self.assertEqual(a1.replace(address="2.3.4.5"), a2)
+
+ mx = dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.MX,
+ "10 foo.example")
+ name = dns.name.from_text("bar.example")
+ self.assertEqual(mx.replace(preference=20).preference, 20)
+ self.assertEqual(mx.replace(preference=20).exchange, mx.exchange)
+ self.assertEqual(mx.replace(exchange=name).exchange, name)
+ self.assertEqual(mx.replace(exchange=name).preference, mx.preference)
+
+ for invalid_parameter in ("rdclass", "rdtype", "foo", "__class__"):
+ with self.assertRaises(AttributeError):
+ mx.replace(invalid_parameter=1)
+
if __name__ == '__main__':
unittest.main()