Skip to content

Commit 5a137fe

Browse files
author
Aaron Sierra
committed
dns: nsone: Add API request checking
1 parent 3ce5376 commit 5a137fe

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

libcloud/test/dns/test_nsone.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
class NsOneTests(unittest.TestCase):
3636
def setUp(self):
3737
NsOneMockHttp.type = None
38+
NsOneMockHttp.history.clear()
3839
NsOneDNSDriver.connectionCls.conn_class = NsOneMockHttp
3940
self.driver = NsOneDNSDriver(*DNS_PARAMS_NSONE)
4041
self.example_zone = Zone(
@@ -72,6 +73,10 @@ def test_list_zones_empty(self):
7273
def test_list_zones_success(self):
7374
zones = self.driver.list_zones()
7475

76+
sent = NsOneMockHttp.history.pop()
77+
self.assertEqual(sent.method, "GET")
78+
self.assertEqual(sent.url, "/v1/zones")
79+
7580
self.assertEqual(len(zones), 2)
7681

7782
zone = zones[0]
@@ -100,6 +105,10 @@ def test_delete_zone_success(self):
100105
NsOneMockHttp.type = "DELETE_ZONE_SUCCESS"
101106
status = self.driver.delete_zone(zone=self.test_zone)
102107

108+
sent = NsOneMockHttp.history.pop()
109+
self.assertEqual(sent.method, "DELETE")
110+
self.assertEqual(sent.url, "/v1/zones/test.com")
111+
103112
self.assertTrue(status)
104113

105114
def test_get_zone_zone_does_not_exist(self):
@@ -115,6 +124,10 @@ def test_get_zone_success(self):
115124
NsOneMockHttp.type = "GET_ZONE_SUCCESS"
116125
zone = self.driver.get_zone(zone_id="example.com")
117126

127+
sent = NsOneMockHttp.history.pop()
128+
self.assertEqual(sent.method, "GET")
129+
self.assertEqual(sent.url, "/v1/zones/example.com")
130+
118131
self.assertEqual(zone.id, "example.com")
119132
self.assertEqual(zone.domain, "example.com")
120133
self.assertIsNone(zone.type),
@@ -124,6 +137,11 @@ def test_create_zone_success(self):
124137
NsOneMockHttp.type = "CREATE_ZONE_SUCCESS"
125138
zone = self.driver.create_zone(domain="newzone.com")
126139

140+
sent = NsOneMockHttp.history.pop()
141+
self.assertEqual(sent.method, "PUT")
142+
self.assertEqual(sent.url, "/v1/zones/newzone.com")
143+
self.assertEqual(sent.json["zone"], "newzone.com")
144+
127145
self.assertEqual(zone.id, "newzone.com")
128146
self.assertEqual(zone.domain, "newzone.com")
129147
self.assertIsNone(zone.type),
@@ -153,6 +171,12 @@ def test_get_record_success(self):
153171
NsOneMockHttp.type = "GET_RECORD_SUCCESS"
154172
record = self.driver.get_record(zone_id="example.com", record_id="A:www")
155173

174+
# [0] /v1/zones/example.com
175+
# [1] /v1/zones/example.com/www.example.com/A
176+
sent = NsOneMockHttp.history.pop()
177+
self.assertEqual(sent.method, "GET")
178+
self.assertEqual(sent.url, "/v1/zones/example.com/www.example.com/A")
179+
156180
self.assertEqual(record.id, "A:www")
157181
self.assertEqual(record.name, "www.example.com")
158182
self.assertEqual(record.data, ["1.1.1.1"])
@@ -177,6 +201,11 @@ def test_list_records_empty(self):
177201
def test_list_records_success(self):
178202
NsOneMockHttp.type = "LIST_RECORDS_SUCCESS"
179203
records = self.driver.list_records(zone=self.example_zone)
204+
205+
sent = NsOneMockHttp.history.pop()
206+
self.assertEqual(sent.method, "GET")
207+
self.assertEqual(sent.url, "/v1/zones/example.com")
208+
180209
self.assertEqual(len(records), 2)
181210

182211
arecord = records[1]
@@ -194,6 +223,15 @@ def test_create_record_success(self):
194223
self.test_record.data,
195224
self.test_record.extra,
196225
)
226+
227+
sent = NsOneMockHttp.history.pop()
228+
self.assertEqual(sent.method, "PUT")
229+
self.assertEqual(sent.url, "/v1/zones/test.com/test.com/A")
230+
self.assertEqual(sent.json["zone"], "test.com")
231+
self.assertEqual(sent.json["domain"], "test.com")
232+
self.assertEqual(sent.json["type"], "A")
233+
self.assertIn({"answer": ["127.0.0.1"]}, sent.json["answers"])
234+
197235
self.assertEqual(arecord.id, "A")
198236
self.assertEqual(arecord.name, "test.com")
199237
self.assertEqual(arecord.type, RecordType.A)
@@ -243,11 +281,16 @@ def test_delete_record_success(self):
243281
NsOneMockHttp.type = "DELETE_RECORD_SUCCESS"
244282
status = self.driver.delete_record(record=self.test_record)
245283

284+
sent = NsOneMockHttp.history.pop()
285+
self.assertEqual(sent.method, "DELETE")
286+
self.assertEqual(sent.url, "/v1/zones/test.com/test.com/A")
287+
246288
self.assertTrue(status)
247289

248290

249291
class NsOneMockHttp(MockHttp):
250292
fixtures = DNSFileFixtures("nsone")
293+
keep_history = True
251294

252295
def _v1_zones_EMPTY_ZONES_LIST(self, method, url, body, headers):
253296
body = self.fixtures.load("empty_zones_list.json")

0 commit comments

Comments
 (0)