Skip to content

Commit 0740bff

Browse files
author
Aaron Sierra
committed
gandi_live: Add API request checking
1 parent a818886 commit 0740bff

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

libcloud/test/dns/test_gandi_live.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class GandiLiveTests(unittest.TestCase):
3838
def setUp(self):
3939
GandiLiveDNSDriver.connectionCls.conn_class = GandiLiveMockHttp
4040
GandiLiveMockHttp.type = None
41+
GandiLiveMockHttp.history.clear()
4142
self.driver = GandiLiveDNSDriver(*DNS_GANDI_LIVE)
4243
self.test_zone = Zone(
4344
id="example.com",
@@ -76,6 +77,11 @@ def setUp(self):
7677

7778
def test_list_zones(self):
7879
zones = self.driver.list_zones()
80+
81+
sent = GandiLiveMockHttp.history.pop()
82+
self.assertEqual(sent.method, 'GET')
83+
self.assertEqual(sent.url, '/api/v5/domains')
84+
7985
self.assertEqual(len(zones), 2)
8086
zone = zones[0]
8187
self.assertEqual(zone.id, "example.com")
@@ -90,25 +96,59 @@ def test_list_zones(self):
9096

9197
def test_create_zone(self):
9298
zone = self.driver.create_zone("example.org", extra={"name": "Example"})
99+
100+
# [0] /api/v5/domains (create)
101+
# [1] /api/v5/domains/example.org (modify)
102+
sent = GandiLiveMockHttp.history.pop(0)
103+
self.assertEqual(sent.method, "POST")
104+
self.assertEqual(sent.url, "/api/v5/zones")
105+
self.assertEqual(sent.json["name"], "Example")
106+
sent = GandiLiveMockHttp.history.pop()
107+
self.assertEqual(sent.method, "PATCH")
108+
self.assertEqual(sent.url, "/api/v5/domains/example.org")
109+
self.assertEqual(sent.json["zone_uuid"], "54321")
110+
93111
self.assertEqual(zone.id, "example.org")
94112
self.assertEqual(zone.domain, "example.org")
95113
self.assertEqual(zone.extra["zone_uuid"], "54321")
96114

97115
def test_create_zone_without_name(self):
98116
zone = self.driver.create_zone("example.org")
117+
118+
# [0] /api/v5/domains (create)
119+
# [1] /api/v5/domains/example.org (modify)
120+
sent = GandiLiveMockHttp.history.pop(0)
121+
self.assertEqual(sent.method, "POST")
122+
self.assertEqual(sent.url, "/api/v5/zones")
123+
self.assertEqual(sent.json["name"], "example.org zone")
124+
sent = GandiLiveMockHttp.history.pop()
125+
self.assertEqual(sent.method, "PATCH")
126+
self.assertEqual(sent.url, "/api/v5/domains/example.org")
127+
self.assertEqual(sent.json["zone_uuid"], "54321")
128+
99129
self.assertEqual(zone.id, "example.org")
100130
self.assertEqual(zone.domain, "example.org")
101131
self.assertEqual(zone.extra["zone_uuid"], "54321")
102132

103133
def test_get_zone(self):
104134
zone = self.driver.get_zone("example.com")
135+
136+
sent = GandiLiveMockHttp.history.pop(0)
137+
self.assertEqual(sent.method, "GET")
138+
self.assertEqual(sent.url, "/api/v5/domains/example.com")
139+
105140
self.assertEqual(zone.id, "example.com")
106141
self.assertEqual(zone.type, "master")
107142
self.assertEqual(zone.domain, "example.com")
108143
self.assertIsNone(zone.ttl)
109144

110145
def test_list_records(self):
111146
records = self.driver.list_records(self.test_zone)
147+
148+
sent = GandiLiveMockHttp.history.pop()
149+
self.assertEqual(sent.method, "GET")
150+
self.assertEqual(sent.url, "/api/v5/domains/example.com/records")
151+
112152
self.assertEqual(len(records), 3)
113153
record = records[0]
114154
self.assertEqual(record.id, "A:@")
@@ -128,6 +168,13 @@ def test_list_records(self):
128168

129169
def test_get_record(self):
130170
record = self.driver.get_record(self.test_zone.id, "A:bob")
171+
172+
# [0] /api/v5/domains/example.com/records/bob/A
173+
# [1] /api/v5/domains/example.com
174+
sent = GandiLiveMockHttp.history.pop(0)
175+
self.assertEqual(sent.method, "GET")
176+
self.assertEqual(sent.url, "/api/v5/domains/example.com/records/bob/A")
177+
131178
self.assertEqual(record.id, "A:bob")
132179
self.assertEqual(record.name, "bob")
133180
self.assertEqual(record.type, RecordType.A)
@@ -137,6 +184,15 @@ def test_create_record(self):
137184
record = self.driver.create_record(
138185
"alice", self.test_zone, "AAAA", "::1", extra={"ttl": 400}
139186
)
187+
188+
sent = GandiLiveMockHttp.history.pop()
189+
self.assertEqual(sent.method, "POST")
190+
self.assertEqual(sent.url, "/api/v5/domains/example.com/records")
191+
self.assertEqual(sent.json["rrset_name"], "alice")
192+
self.assertEqual(sent.json["rrset_type"], "AAAA")
193+
self.assertIn("::1", sent.json["rrset_values"])
194+
self.assertEqual(sent.json["rrset_ttl"], 400)
195+
140196
self.assertEqual(record.id, "AAAA:alice")
141197
self.assertEqual(record.name, "alice")
142198
self.assertEqual(record.type, RecordType.AAAA)
@@ -168,13 +224,25 @@ def test_update_record(self):
168224
record = self.driver.update_record(
169225
self.test_record, "bob", RecordType.A, "192.168.0.2", {"ttl": 500}
170226
)
227+
228+
sent = GandiLiveMockHttp.history.pop()
229+
self.assertEqual(sent.method, "PUT")
230+
self.assertEqual(sent.url, "/api/v5/domains/example.com/records/bob/A")
231+
self.assertIn("192.168.0.2", sent.json["rrset_values"])
232+
self.assertEqual(sent.json["rrset_ttl"], 500)
233+
171234
self.assertEqual(record.id, "A:bob")
172235
self.assertEqual(record.name, "bob")
173236
self.assertEqual(record.type, RecordType.A)
174237
self.assertEqual(record.data, "192.168.0.2")
175238

176239
def test_delete_record(self):
177240
success = self.driver.delete_record(self.test_record)
241+
242+
sent = GandiLiveMockHttp.history.pop()
243+
self.assertEqual(sent.method, "DELETE")
244+
self.assertEqual(sent.url, "/api/v5/domains/example.com/records/bob/A")
245+
178246
self.assertTrue(success)
179247

180248
def test_export_bind(self):
@@ -259,6 +327,7 @@ def test_ex_delete_gandi_zone(self):
259327

260328
class GandiLiveMockHttp(BaseGandiLiveMockHttp):
261329
fixtures = DNSFileFixtures("gandi_live")
330+
keep_history = True
262331

263332
def _json_api_v5_domains_get(self, method, url, body, headers):
264333
body = self.fixtures.load("list_zones.json")

0 commit comments

Comments
 (0)