-
Notifications
You must be signed in to change notification settings - Fork 3
/
cassandranames-test.py
80 lines (64 loc) · 3.41 KB
/
cassandranames-test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import unittest
import cassandranames
from dnstypeconstants import *
# Running this *will destroy* data in Cassandra.
class TestCassandraNames(unittest.TestCase):
def setUp(self):
cassandranames.install_schema(drop_first=True, rf=1)
self.names = cassandranames.CassandraNames()
def test_names(self):
# Verify behavior on an initial, empty set.
data = self.names.lookup("pantheon.example.com")
self.assertEqual(data, {})
data = self.names.lookup("pantheon.example.com", A)
self.assertEqual(data, {})
# Add an "A" record.
self.names.insert("pantheon.example.com", A, "192.168.0.1")
# Verify that the "A" records appears in lookups.
data = self.names.lookup("pantheon.example.com")
self.assertEqual(data, {A: {"192.168.0.1": {"ttl": 900}}})
data = self.names.lookup("pantheon.example.com", A)
self.assertEqual(data, {A: {"192.168.0.1": {"ttl": 900}}})
data = self.names.lookup("pantheon.example.com", MX)
self.assertEqual(data, {})
# Add another "A" record, this time with an explicit TTL.
self.names.insert("pantheon.example.com", A, "192.168.0.2", 60)
# Verify that both "A" records appear in results.
data = self.names.lookup("pantheon.example.com")
a_records = {"192.168.0.1": {"ttl": 900}, "192.168.0.2": {"ttl": 60}}
self.assertEqual(data, {A: a_records})
data = self.names.lookup("pantheon.example.com", A)
self.assertEqual(data, {A: a_records})
data = self.names.lookup("pantheon.example.com", MX)
self.assertEqual(data, {})
# Add an MX record.
self.names.insert("pantheon.example.com", MX, "192.168.0.3", preference=10)
# Verify the MX record.
data = self.names.lookup("pantheon.example.com")
self.assertEqual(data, {A: a_records, MX: {"192.168.0.3": {"preference": 10, "ttl": 900}}})
data = self.names.lookup("pantheon.example.com", MX)
self.assertEqual(data, {MX: {"192.168.0.3": {"preference": 10, "ttl": 900}}})
# Delete the A record for 192.168.0.1.
self.names.remove("pantheon.example.com", A, "192.168.0.1")
# Verify the other "A" record and the "MX" record still exists.
data = self.names.lookup("pantheon.example.com", A)
self.assertEqual(data, {A: {"192.168.0.2": {"ttl": 60}}})
data = self.names.lookup("pantheon.example.com", MX)
self.assertEqual(data, {MX: {"192.168.0.3": {"preference": 10, "ttl": 900}}})
# Delete all "MX" records and verify the deletion.
self.names.remove("pantheon.example.com", MX)
data = self.names.lookup("pantheon.example.com", MX)
self.assertEqual(data, {})
data = self.names.lookup("pantheon.example.com", A)
self.assertEqual(data, {A: {"192.168.0.2": {"ttl": 60}}})
# Delete all records for the domain and verify deletion.
self.names.remove("pantheon.example.com")
data = self.names.lookup("pantheon.example.com")
self.assertEqual(data, {})
# Insert some other records, just for fun.
self.names.insert("pantheon.example.com", A, "10.0.0.1", 60)
self.names.insert("pantheon.example.com", A, "10.0.0.2", 60)
self.names.insert("pantheon.example.com", MX, "10.0.0.3", 60, 10)
self.names.insert("pantheon.example.com", MX, "10.0.0.4", 60, 20)
if __name__ == '__main__':
unittest.main()