| 1 |
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license |
| 2 |
|
| 3 |
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. |
| 4 |
# |
| 5 |
# Permission to use, copy, modify, and distribute this software and its |
| 6 |
# documentation for any purpose with or without fee is hereby granted, |
| 7 |
# provided that the above copyright notice and this permission notice |
| 8 |
# appear in all copies. |
| 9 |
# |
| 10 |
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES |
| 11 |
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 12 |
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR |
| 13 |
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 14 |
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 15 |
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 16 |
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 17 |
|
| 18 |
import unittest |
| 19 |
|
| 20 |
import dns.rdataclass |
| 21 |
import dns.rdatatype |
| 22 |
|
| 23 |
|
| 24 |
class RdTypeAndClassTestCase(unittest.TestCase): |
| 25 |
# Classes |
| 26 |
|
| 27 |
def test_class_meta1(self): |
| 28 |
self.assertTrue(dns.rdataclass.is_metaclass(dns.rdataclass.ANY)) |
| 29 |
|
| 30 |
def test_class_meta2(self): |
| 31 |
self.assertFalse(dns.rdataclass.is_metaclass(dns.rdataclass.IN)) |
| 32 |
|
| 33 |
def test_class_bytext1(self): |
| 34 |
self.assertEqual(dns.rdataclass.from_text("IN"), dns.rdataclass.IN) |
| 35 |
|
| 36 |
def test_class_bytext2(self): |
| 37 |
self.assertEqual(dns.rdataclass.from_text("CLASS1"), dns.rdataclass.IN) |
| 38 |
|
| 39 |
def test_class_bytext_bounds1(self): |
| 40 |
self.assertEqual(dns.rdataclass.from_text("CLASS0"), 0) |
| 41 |
self.assertEqual(dns.rdataclass.from_text("CLASS65535"), 65535) |
| 42 |
|
| 43 |
def test_class_bytext_bounds2(self): |
| 44 |
def bad(): |
| 45 |
dns.rdataclass.from_text("CLASS65536") |
| 46 |
|
| 47 |
self.assertRaises(ValueError, bad) |
| 48 |
|
| 49 |
def test_class_bytext_unknown(self): |
| 50 |
def bad(): |
| 51 |
dns.rdataclass.from_text("XXX") |
| 52 |
|
| 53 |
self.assertRaises(dns.rdataclass.UnknownRdataclass, bad) |
| 54 |
|
| 55 |
def test_class_totext1(self): |
| 56 |
self.assertEqual(dns.rdataclass.to_text(dns.rdataclass.IN), "IN") |
| 57 |
|
| 58 |
def test_class_totext2(self): |
| 59 |
self.assertEqual(dns.rdataclass.to_text(999), "CLASS999") |
| 60 |
|
| 61 |
def test_class_totext_bounds1(self): |
| 62 |
def bad(): |
| 63 |
dns.rdataclass.to_text(-1) |
| 64 |
|
| 65 |
self.assertRaises(ValueError, bad) |
| 66 |
|
| 67 |
def test_class_totext_bounds2(self): |
| 68 |
def bad(): |
| 69 |
dns.rdataclass.to_text(65536) |
| 70 |
|
| 71 |
self.assertRaises(ValueError, bad) |
| 72 |
|
| 73 |
# Types |
| 74 |
|
| 75 |
def test_type_meta1(self): |
| 76 |
self.assertTrue(dns.rdatatype.is_metatype(dns.rdatatype.ANY)) |
| 77 |
|
| 78 |
def test_type_meta2(self): |
| 79 |
self.assertTrue(dns.rdatatype.is_metatype(dns.rdatatype.OPT)) |
| 80 |
|
| 81 |
def test_type_meta3(self): |
| 82 |
self.assertFalse(dns.rdatatype.is_metatype(dns.rdatatype.A)) |
| 83 |
|
| 84 |
def test_type_singleton1(self): |
| 85 |
self.assertTrue(dns.rdatatype.is_singleton(dns.rdatatype.SOA)) |
| 86 |
|
| 87 |
def test_type_singleton2(self): |
| 88 |
self.assertFalse(dns.rdatatype.is_singleton(dns.rdatatype.A)) |
| 89 |
|
| 90 |
def test_type_bytext1(self): |
| 91 |
self.assertEqual(dns.rdatatype.from_text("A"), dns.rdatatype.A) |
| 92 |
|
| 93 |
def test_type_bytext2(self): |
| 94 |
self.assertEqual(dns.rdatatype.from_text("TYPE1"), dns.rdatatype.A) |
| 95 |
|
| 96 |
def test_type_bytext_bounds1(self): |
| 97 |
self.assertEqual(dns.rdatatype.from_text("TYPE0"), 0) |
| 98 |
self.assertEqual(dns.rdatatype.from_text("TYPE65535"), 65535) |
| 99 |
|
| 100 |
def test_type_bytext_bounds2(self): |
| 101 |
def bad(): |
| 102 |
dns.rdatatype.from_text("TYPE65536") |
| 103 |
|
| 104 |
self.assertRaises(ValueError, bad) |
| 105 |
|
| 106 |
def test_type_bytext_unknown(self): |
| 107 |
def bad(): |
| 108 |
dns.rdatatype.from_text("XXX") |
| 109 |
|
| 110 |
self.assertRaises(dns.rdatatype.UnknownRdatatype, bad) |
| 111 |
|
| 112 |
def test_type_totext1(self): |
| 113 |
self.assertEqual(dns.rdatatype.to_text(dns.rdatatype.A), "A") |
| 114 |
|
| 115 |
def test_type_totext2(self): |
| 116 |
self.assertEqual(dns.rdatatype.to_text(999), "TYPE999") |
| 117 |
|
| 118 |
def test_type_totext_bounds1(self): |
| 119 |
def bad(): |
| 120 |
dns.rdatatype.to_text(-1) |
| 121 |
|
| 122 |
self.assertRaises(ValueError, bad) |
| 123 |
|
| 124 |
def test_type_totext_bounds2(self): |
| 125 |
def bad(): |
| 126 |
dns.rdatatype.to_text(65536) |
| 127 |
|
| 128 |
self.assertRaises(ValueError, bad) |
| 129 |
|
| 130 |
def test_type0_totext(self): |
| 131 |
self.assertEqual(dns.rdatatype.to_text(0), "TYPE0") |
| 132 |
|
| 133 |
|
| 134 |
if __name__ == "__main__": |
| 135 |
unittest.main() |