1 # Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc.
3 # Permission to use, copy, modify, and distribute this software and its
4 # documentation for any purpose with or without fee is hereby granted,
5 # provided that the above copyright notice and this permission notice
6 # appear in all copies.
8 # THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
9 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
11 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
14 # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 goodhex
= '0001 2800 0001 0005 0007 0000' \
23 '076578616d706c6500 0006 0001' \
24 '03666f6fc00c 00ff 00ff 00000000 0000' \
25 'c019 0001 00ff 00000000 0000' \
26 '03626172c00c 0001 0001 00000000 0004 0a000005' \
27 '05626c617a32c00c 00ff 00fe 00000000 0000' \
28 'c049 0001 00fe 00000000 0000' \
29 'c019 0001 00ff 00000000 0000' \
30 'c019 0001 0001 0000012c 0004 0a000001' \
31 'c019 0001 0001 0000012c 0004 0a000002' \
32 'c035 0001 0001 0000012c 0004 0a000003' \
33 'c035 0001 00fe 00000000 0004 0a000004' \
34 '04626c617ac00c 0001 00ff 00000000 0000' \
35 'c049 00ff 00ff 00000000 0000'
37 goodwire
= goodhex
.replace(' ', '').decode('hex_codec')
60 class UpdateTestCase(unittest
.TestCase
):
62 def test_to_wire1(self
):
63 update
= dns
.update
.Update('example')
66 update
.present('foo', 'a')
67 update
.present('bar', 'a', '10.0.0.5')
68 update
.absent('blaz2')
69 update
.absent('blaz2', 'a')
70 update
.replace('foo', 300, 'a', '10.0.0.1', '10.0.0.2')
71 update
.add('bar', 300, 'a', '10.0.0.3')
72 update
.delete('bar', 'a', '10.0.0.4')
73 update
.delete('blaz','a')
74 update
.delete('blaz2')
75 self
.failUnless(update
.to_wire() == goodwire
)
77 def test_to_wire2(self
):
78 update
= dns
.update
.Update('example')
81 update
.present('foo', 'a')
82 update
.present('bar', 'a', '10.0.0.5')
83 update
.absent('blaz2')
84 update
.absent('blaz2', 'a')
85 update
.replace('foo', 300, 'a', '10.0.0.1', '10.0.0.2')
86 update
.add('bar', 300, dns
.rdata
.from_text(1, 1, '10.0.0.3'))
87 update
.delete('bar', 'a', '10.0.0.4')
88 update
.delete('blaz','a')
89 update
.delete('blaz2')
90 self
.failUnless(update
.to_wire() == goodwire
)
92 def test_to_wire3(self
):
93 update
= dns
.update
.Update('example')
96 update
.present('foo', 'a')
97 update
.present('bar', 'a', '10.0.0.5')
98 update
.absent('blaz2')
99 update
.absent('blaz2', 'a')
100 update
.replace('foo', 300, 'a', '10.0.0.1', '10.0.0.2')
101 update
.add('bar', dns
.rdataset
.from_text(1, 1, 300, '10.0.0.3'))
102 update
.delete('bar', 'a', '10.0.0.4')
103 update
.delete('blaz','a')
104 update
.delete('blaz2')
105 self
.failUnless(update
.to_wire() == goodwire
)
107 def test_from_text1(self
):
108 update
= dns
.message
.from_text(update_text
)
109 w
= update
.to_wire(origin
=dns
.name
.from_text('example'),
111 self
.failUnless(w
== goodwire
)
113 if __name__
== '__main__':