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.
21 class RdTypeAndClassTestCase(unittest
.TestCase
):
25 def test_class_meta1(self
):
26 self
.failUnless(dns
.rdataclass
.is_metaclass(dns
.rdataclass
.ANY
))
28 def test_class_meta2(self
):
29 self
.failUnless(not dns
.rdataclass
.is_metaclass(dns
.rdataclass
.IN
))
31 def test_class_bytext1(self
):
32 self
.failUnless(dns
.rdataclass
.from_text('IN') == dns
.rdataclass
.IN
)
34 def test_class_bytext2(self
):
35 self
.failUnless(dns
.rdataclass
.from_text('CLASS1') ==
38 def test_class_bytext_bounds1(self
):
39 self
.failUnless(dns
.rdataclass
.from_text('CLASS0') == 0)
40 self
.failUnless(dns
.rdataclass
.from_text('CLASS65535') == 65535)
42 def test_class_bytext_bounds2(self
):
44 junk
= dns
.rdataclass
.from_text('CLASS65536')
45 self
.failUnlessRaises(ValueError, bad
)
47 def test_class_bytext_unknown(self
):
49 junk
= dns
.rdataclass
.from_text('XXX')
50 self
.failUnlessRaises(dns
.rdataclass
.UnknownRdataclass
, bad
)
52 def test_class_totext1(self
):
53 self
.failUnless(dns
.rdataclass
.to_text(dns
.rdataclass
.IN
) == 'IN')
55 def test_class_totext1(self
):
56 self
.failUnless(dns
.rdataclass
.to_text(999) == 'CLASS999')
58 def test_class_totext_bounds1(self
):
60 junk
= dns
.rdataclass
.to_text(-1)
61 self
.failUnlessRaises(ValueError, bad
)
63 def test_class_totext_bounds2(self
):
65 junk
= dns
.rdataclass
.to_text(65536)
66 self
.failUnlessRaises(ValueError, bad
)
70 def test_type_meta1(self
):
71 self
.failUnless(dns
.rdatatype
.is_metatype(dns
.rdatatype
.ANY
))
73 def test_type_meta2(self
):
74 self
.failUnless(dns
.rdatatype
.is_metatype(dns
.rdatatype
.OPT
))
76 def test_type_meta3(self
):
77 self
.failUnless(not dns
.rdatatype
.is_metatype(dns
.rdatatype
.A
))
79 def test_type_singleton1(self
):
80 self
.failUnless(dns
.rdatatype
.is_singleton(dns
.rdatatype
.SOA
))
82 def test_type_singleton2(self
):
83 self
.failUnless(not dns
.rdatatype
.is_singleton(dns
.rdatatype
.A
))
85 def test_type_bytext1(self
):
86 self
.failUnless(dns
.rdatatype
.from_text('A') == dns
.rdatatype
.A
)
88 def test_type_bytext2(self
):
89 self
.failUnless(dns
.rdatatype
.from_text('TYPE1') ==
92 def test_type_bytext_bounds1(self
):
93 self
.failUnless(dns
.rdatatype
.from_text('TYPE0') == 0)
94 self
.failUnless(dns
.rdatatype
.from_text('TYPE65535') == 65535)
96 def test_type_bytext_bounds2(self
):
98 junk
= dns
.rdatatype
.from_text('TYPE65536')
99 self
.failUnlessRaises(ValueError, bad
)
101 def test_type_bytext_unknown(self
):
103 junk
= dns
.rdatatype
.from_text('XXX')
104 self
.failUnlessRaises(dns
.rdatatype
.UnknownRdatatype
, bad
)
106 def test_type_totext1(self
):
107 self
.failUnless(dns
.rdatatype
.to_text(dns
.rdatatype
.A
) == 'A')
109 def test_type_totext1(self
):
110 self
.failUnless(dns
.rdatatype
.to_text(999) == 'TYPE999')
112 def test_type_totext_bounds1(self
):
114 junk
= dns
.rdatatype
.to_text(-1)
115 self
.failUnlessRaises(ValueError, bad
)
117 def test_type_totext_bounds2(self
):
119 junk
= dns
.rdatatype
.to_text(65536)
120 self
.failUnlessRaises(ValueError, bad
)
122 if __name__
== '__main__':