dsdb: reset schema->{classes,attributes}_to_remove_size to 0
[Samba/gebeck_regimport.git] / lib / dnspython / tests / update.py
blob92ddb565fc1aece1f44a43679cfd2b529258ed50
1 # Copyright (C) 2003-2007, 2009-2011 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.
16 import unittest
18 import dns.update
19 import dns.rdata
20 import dns.rdataset
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')
39 update_text="""id 1
40 opcode UPDATE
41 rcode NOERROR
42 ;ZONE
43 example. IN SOA
44 ;PREREQ
45 foo ANY ANY
46 foo ANY A
47 bar 0 IN A 10.0.0.5
48 blaz2 NONE ANY
49 blaz2 NONE A
50 ;UPDATE
51 foo ANY A
52 foo 300 IN A 10.0.0.1
53 foo 300 IN A 10.0.0.2
54 bar 300 IN A 10.0.0.3
55 bar 0 NONE A 10.0.0.4
56 blaz ANY A
57 blaz2 ANY ANY
58 """
60 class UpdateTestCase(unittest.TestCase):
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)
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)
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)
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)
113 if __name__ == '__main__':
114 unittest.main()