source: trunk/server/lib/dnspython/tests/update.py

Last change on this file was 745, checked in by Silvan Scherrer, 13 years ago

Samba Server: updated trunk to 3.6.0

File size: 3.9 KB
Line 
1# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc.
2#
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.
7#
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.
15
16import unittest
17
18import dns.update
19import dns.rdata
20import dns.rdataset
21
22goodhex = '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'
36
37goodwire = goodhex.replace(' ', '').decode('hex_codec')
38
39update_text="""id 1
40opcode UPDATE
41rcode NOERROR
42;ZONE
43example. IN SOA
44;PREREQ
45foo ANY ANY
46foo ANY A
47bar 0 IN A 10.0.0.5
48blaz2 NONE ANY
49blaz2 NONE A
50;UPDATE
51foo ANY A
52foo 300 IN A 10.0.0.1
53foo 300 IN A 10.0.0.2
54bar 300 IN A 10.0.0.3
55bar 0 NONE A 10.0.0.4
56blaz ANY A
57blaz2 ANY ANY
58"""
59
60class UpdateTestCase(unittest.TestCase):
61
62 def test_to_wire1(self):
63 update = dns.update.Update('example')
64 update.id = 1
65 update.present('foo')
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)
76
77 def test_to_wire2(self):
78 update = dns.update.Update('example')
79 update.id = 1
80 update.present('foo')
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)
91
92 def test_to_wire3(self):
93 update = dns.update.Update('example')
94 update.id = 1
95 update.present('foo')
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)
106
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'),
110 want_shuffle=False)
111 self.failUnless(w == goodwire)
112
113if __name__ == '__main__':
114 unittest.main()
Note: See TracBrowser for help on using the repository browser.