2525 RecordDoesNotExistError ,
2626 RecordAlreadyExistsError ,
2727)
28- from libcloud .utils .py3 import httplib
28+ from libcloud .utils .py3 import httplib , parse_qs
2929from libcloud .test .secrets import DNS_PARAMS_DNSPOD
3030from libcloud .dns .drivers .dnspod import DNSPodDNSDriver
3131from libcloud .test .file_fixtures import DNSFileFixtures
3434class DNSPodDNSTests (unittest .TestCase ):
3535 def setUp (self ):
3636 DNSPodMockHttp .type = None
37+ DNSPodMockHttp .history .clear ()
3738 DNSPodDNSDriver .connectionCls .conn_class = DNSPodMockHttp
3839 self .driver = DNSPodDNSDriver (* DNS_PARAMS_DNSPOD )
3940 self .test_zone = Zone (
@@ -67,6 +68,10 @@ def test_list_zones_success(self):
6768 DNSPodMockHttp .type = "LIST_ZONES"
6869 zones = self .driver .list_zones ()
6970
71+ sent = DNSPodMockHttp .history .pop ()
72+ self .assertEqual (sent .method , "POST" )
73+ self .assertEqual (sent .url , "/Domain.List" )
74+
7075 self .assertEqual (len (zones ), 1 )
7176
7277 zone = zones [0 ]
@@ -89,6 +94,12 @@ def test_get_zone_success(self):
8994 DNSPodMockHttp .type = "GET_ZONE_SUCCESS"
9095 zone = self .driver .get_zone (zone_id = "6" )
9196
97+ sent = DNSPodMockHttp .history .pop ()
98+ self .assertEqual (sent .method , "POST" )
99+ self .assertEqual (sent .url , "/Domain.Info" )
100+ data = parse_qs (sent .body )
101+ self .assertIn ("6" , data ["domain_id" ])
102+
92103 self .assertEqual (zone .id , "6" )
93104 self .assertEqual (zone .domain , "dnspod.com" )
94105 self .assertIsNone (zone .type )
@@ -100,6 +111,12 @@ def test_delete_zone_success(self):
100111 zone = self .test_zone
101112 status = self .driver .delete_zone (zone = zone )
102113
114+ sent = DNSPodMockHttp .history .pop ()
115+ self .assertEqual (sent .method , "POST" )
116+ self .assertEqual (sent .url , "/Domain.Remove" )
117+ data = parse_qs (sent .body )
118+ self .assertIn (zone .id , data ["domain_id" ])
119+
103120 self .assertEqual (status , True )
104121
105122 def test_delete_zone_zone_does_not_exist (self ):
@@ -114,7 +131,13 @@ def test_delete_zone_zone_does_not_exist(self):
114131
115132 def test_create_zone_success (self ):
116133 DNSPodMockHttp .type = "CREATE_ZONE_SUCCESS"
117- zone = self .driver .create_zone (domain = "example.org" )
134+ zone = self .driver .create_zone (domain = "api2.com" )
135+
136+ sent = DNSPodMockHttp .history .pop ()
137+ self .assertEqual (sent .method , "POST" )
138+ self .assertEqual (sent .url , "/Domain.Create" )
139+ data = parse_qs (sent .body )
140+ self .assertIn ("api2.com" , data ["domain" ])
118141
119142 self .assertEqual (zone .id , "3" )
120143 self .assertEqual (zone .domain , "api2.com" )
@@ -135,6 +158,13 @@ def test_list_records_success(self):
135158 DNSPodMockHttp .type = "LIST_RECORDS_SUCCESS"
136159 zone = self .test_zone
137160 records = self .driver .list_records (zone = zone )
161+
162+ sent = DNSPodMockHttp .history .pop ()
163+ self .assertEqual (sent .method , "POST" )
164+ self .assertEqual (sent .url , "/Record.List" )
165+ data = parse_qs (sent .body )
166+ self .assertIn (zone .id , data ["domain_id" ])
167+
138168 first_record = records [0 ]
139169
140170 self .assertEqual (len (records ), 5 )
@@ -145,7 +175,14 @@ def test_list_records_success(self):
145175
146176 def test_get_record_success (self ):
147177 DNSPodMockHttp .type = "GET_RECORD_SUCCESS"
148- record = self .driver .get_record (zone_id = "31" , record_id = "31" )
178+ record = self .driver .get_record (zone_id = "6" , record_id = "50" )
179+
180+ sent = DNSPodMockHttp .history .pop ()
181+ self .assertEqual (sent .method , "POST" )
182+ self .assertEqual (sent .url , "/Record.Info" )
183+ body = parse_qs (sent .body )
184+ self .assertIn ("6" , body ["domain_id" ])
185+ self .assertIn ("50" , body ["record_id" ])
149186
150187 self .assertEqual (record .id , "50" )
151188 self .assertEqual (record .type , "A" )
@@ -178,6 +215,20 @@ def test_create_record_success(self):
178215 data = "96.126.115.73" ,
179216 extra = {"ttl" : 13 , "record_line" : "default" },
180217 )
218+
219+ # [0] /Record.Create
220+ # [1] /Record.Info
221+ sent = DNSPodMockHttp .history [0 ]
222+ self .assertEqual (sent .method , "POST" )
223+ self .assertEqual (sent .url , "/Record.Create" )
224+ data = parse_qs (sent .body )
225+ self .assertIn (self .test_zone .id , data ["domain_id" ])
226+ self .assertIn ("A" , data ["record_type" ])
227+ self .assertIn ("@" , data ["sub_domain" ])
228+ self .assertIn ("96.126.115.73" , data ["value" ])
229+ self .assertIn ("13" , data ["ttl" ])
230+ self .assertIn ("default" , data ["record_line" ])
231+
181232 self .assertEqual (record .id , "50" )
182233 self .assertEqual (record .name , "@" )
183234 self .assertEqual (record .data , "96.126.115.73" )
@@ -201,6 +252,7 @@ def test_create_record_already_exists_error(self):
201252
202253class DNSPodMockHttp (MockHttp ):
203254 fixtures = DNSFileFixtures ("dnspod" )
255+ keep_history = True
204256
205257 def _Domain_List_EMPTY_ZONES_LIST (self , method , url , body , headers ):
206258 body = self .fixtures .load ("empty_zones_list.json" )
0 commit comments