forked from softlayer/softlayer-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdns_tests.py
More file actions
138 lines (106 loc) · 5.2 KB
/
dns_tests.py
File metadata and controls
138 lines (106 loc) · 5.2 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
"""
SoftLayer.tests.managers.dns_tests
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:license: MIT, see LICENSE for more details.
"""
import SoftLayer
from SoftLayer import fixtures
from SoftLayer import testing
class DNSTests(testing.TestCase):
def set_up(self):
self.dns_client = SoftLayer.DNSManager(self.client)
def test_list_zones(self):
zones = self.dns_client.list_zones()
self.assertEqual(zones, fixtures.SoftLayer_Account.getDomains)
def test_get_zone(self):
# match, with defaults
res = self.dns_client.get_zone(12345)
self.assertEqual(res, fixtures.SoftLayer_Dns_Domain.getObject)
self.assert_called_with('SoftLayer_Dns_Domain', 'getObject',
identifier=12345,
mask='mask[resourceRecords]')
def test_get_zone_without_records(self):
self.dns_client.get_zone(12345, records=False)
self.assert_called_with('SoftLayer_Dns_Domain', 'getObject',
identifier=12345,
mask=None)
def test_resolve_zone_name(self):
res = self.dns_client._get_zone_id_from_name('example.com')
self.assertEqual([12345], res)
_filter = {"domains": {"name": {"operation": "_= example.com"}}}
self.assert_called_with('SoftLayer_Account', 'getDomains',
filter=_filter)
def test_resolve_zone_name_no_matches(self):
mock = self.set_mock('SoftLayer_Account', 'getDomains')
mock.return_value = []
res = self.dns_client._get_zone_id_from_name('example.com')
self.assertEqual([], res)
_filter = {"domains": {"name": {"operation": "_= example.com"}}}
self.assert_called_with('SoftLayer_Account', 'getDomains',
filter=_filter)
def test_create_zone(self):
res = self.dns_client.create_zone('example.com', serial='2014110201')
args = ({'serial': '2014110201',
'name': 'example.com',
'resourceRecords': {}},)
self.assert_called_with('SoftLayer_Dns_Domain', 'createObject',
args=args)
self.assertEqual(res, {'name': 'example.com'})
def test_delete_zone(self):
self.dns_client.delete_zone(1)
self.assert_called_with('SoftLayer_Dns_Domain', 'deleteObject',
identifier=1)
def test_edit_zone(self):
self.dns_client.edit_zone('example.com')
self.assert_called_with('SoftLayer_Dns_Domain', 'editObject',
args=('example.com',))
def test_create_record(self):
res = self.dns_client.create_record(1, 'test', 'TXT', 'testing',
ttl=1200)
self.assert_called_with('SoftLayer_Dns_Domain_ResourceRecord',
'createObject',
args=({
'domainId': 1,
'ttl': 1200,
'host': 'test',
'type': 'TXT',
'data': 'testing'
},))
self.assertEqual(res, {'name': 'example.com'})
def test_delete_record(self):
self.dns_client.delete_record(1)
self.assert_called_with('SoftLayer_Dns_Domain_ResourceRecord',
'deleteObject',
identifier=1)
def test_edit_record(self):
self.dns_client.edit_record({'id': 1, 'name': 'test', 'ttl': '1800'})
self.assert_called_with('SoftLayer_Dns_Domain_ResourceRecord',
'editObject',
args=({'id': 1,
'name': 'test',
'ttl': '1800'},),
identifier=1)
def test_dump_zone(self):
self.dns_client.dump_zone(1)
self.assert_called_with('SoftLayer_Dns_Domain', 'getZoneFileContents',
identifier=1)
def test_get_record(self):
# maybe valid domain, but no records matching
mock = self.set_mock('SoftLayer_Dns_Domain', 'getResourceRecords')
mock.return_value = []
self.assertEqual(self.dns_client.get_records(12345), [])
mock.reset_mock()
records = fixtures.SoftLayer_Dns_Domain.getResourceRecords
mock.return_value = [records[0]]
self.dns_client.get_records(12345,
record_type='a',
host='hostname',
data='a',
ttl='86400')
_filter = {'resourceRecords': {'type': {'operation': '_= a'},
'host': {'operation': '_= hostname'},
'data': {'operation': '_= a'},
'ttl': {'operation': 86400}}}
self.assert_called_with('SoftLayer_Dns_Domain', 'getResourceRecords',
identifier=12345,
filter=_filter)