2828class BuddyNSDNSTests (unittest .TestCase ):
2929 def setUp (self ):
3030 BuddyNSMockHttp .type = None
31+ BuddyNSMockHttp .history .clear ()
3132 BuddyNSDNSDriver .connectionCls .conn_class = BuddyNSMockHttp
3233 self .driver = BuddyNSDNSDriver (* DNS_PARAMS_BUDDYNS )
3334 self .test_zone = Zone (
@@ -43,12 +44,24 @@ def test_list_zones_empty(self):
4344 BuddyNSMockHttp .type = "EMPTY_ZONES_LIST"
4445 zones = self .driver .list_zones ()
4546
47+ reqs = BuddyNSMockHttp .history
48+ self .assertEqual (len (reqs ), 1 )
49+ sent = reqs .pop ()
50+ self .assertEqual (sent .method , "GET" )
51+ self .assertEqual (sent .url , "/api/v2/zone/" )
52+
4653 self .assertEqual (zones , [])
4754
4855 def test_list_zones_success (self ):
4956 BuddyNSMockHttp .type = "LIST_ZONES"
5057 zones = self .driver .list_zones ()
5158
59+ reqs = BuddyNSMockHttp .history
60+ self .assertEqual (len (reqs ), 1 )
61+ sent = reqs .pop ()
62+ self .assertEqual (sent .method , "GET" )
63+ self .assertEqual (sent .url , "/api/v2/zone/" )
64+
5265 self .assertEqual (len (zones ), 2 )
5366
5467 zone = zones [0 ]
@@ -73,12 +86,24 @@ def test_delete_zone_zone_does_not_exist(self):
7386 else :
7487 self .fail ("Exception was not thrown" )
7588
89+ reqs = BuddyNSMockHttp .history
90+ self .assertEqual (len (reqs ), 1 )
91+ sent = reqs .pop ()
92+ self .assertEqual (sent .method , "DELETE" )
93+ self .assertEqual (sent .url , f"/api/v2/zone/{ self .test_zone .domain } " )
94+
7695 def test_delete_zone_success (self ):
7796 BuddyNSMockHttp .type = "DELETE_ZONE_SUCCESS"
7897 status = self .driver .delete_zone (zone = self .test_zone )
7998
8099 self .assertTrue (status )
81100
101+ reqs = BuddyNSMockHttp .history
102+ self .assertEqual (len (reqs ), 1 )
103+ sent = reqs .pop ()
104+ self .assertEqual (sent .method , "DELETE" )
105+ self .assertEqual (sent .url , f"/api/v2/zone/{ self .test_zone .domain } " )
106+
82107 def test_get_zone_zone_does_not_exist (self ):
83108 BuddyNSMockHttp .type = "GET_ZONE_ZONE_DOES_NOT_EXIST"
84109 try :
@@ -88,10 +113,22 @@ def test_get_zone_zone_does_not_exist(self):
88113 else :
89114 self .fail ("Exception was not thrown" )
90115
116+ reqs = BuddyNSMockHttp .history
117+ self .assertEqual (len (reqs ), 1 )
118+ sent = reqs .pop ()
119+ self .assertEqual (sent .method , "GET" )
120+ self .assertEqual (sent .url , "/api/v2/zone/zonedoesnotexist.com" )
121+
91122 def test_get_zone_success (self ):
92123 BuddyNSMockHttp .type = "GET_ZONE_SUCCESS"
93124 zone = self .driver .get_zone (zone_id = "myexample.com" )
94125
126+ reqs = BuddyNSMockHttp .history
127+ self .assertEqual (len (reqs ), 1 )
128+ sent = reqs .pop ()
129+ self .assertEqual (sent .method , "GET" )
130+ self .assertEqual (sent .url , "/api/v2/zone/myexample.com" )
131+
95132 self .assertEqual (zone .id , "myexample.com" )
96133 self .assertEqual (zone .domain , "myexample.com" )
97134 self .assertIsNone (zone .type )
@@ -102,6 +139,13 @@ def test_create_zone_success(self):
102139 BuddyNSMockHttp .type = "CREATE_ZONE_SUCCESS"
103140 zone = self .driver .create_zone (domain = "microsoft.com" )
104141
142+ reqs = BuddyNSMockHttp .history
143+ self .assertEqual (len (reqs ), 1 )
144+ sent = reqs .pop ()
145+ self .assertEqual (sent .method , "POST" )
146+ self .assertEqual (sent .url , "/api/v2/zone/" )
147+ self .assertEqual (sent .json ["name" ], "microsoft.com" )
148+
105149 self .assertEqual (zone .id , "microsoft.com" )
106150 self .assertEqual (zone .domain , "microsoft.com" )
107151 self .assertIsNone (zone .type ),
@@ -117,9 +161,18 @@ def test_create_zone_zone_already_exists(self):
117161 else :
118162 self .fail ("Exception was not thrown" )
119163
164+ reqs = BuddyNSMockHttp .history
165+ self .assertEqual (len (reqs ), 1 )
166+ sent = reqs .pop ()
167+ self .assertEqual (sent .method , "POST" )
168+ self .assertEqual (sent .url , "/api/v2/zone/" )
169+ self .assertEqual (sent .json ["name" ], "newzone.com" )
170+ self .assertEqual (sent .json ["master" ], "13.0.0.1" )
171+
120172
121173class BuddyNSMockHttp (MockHttp ):
122174 fixtures = DNSFileFixtures ("buddyns" )
175+ keep_history = True
123176
124177 def _api_v2_zone_EMPTY_ZONES_LIST (self , method , url , body , headers ):
125178 body = self .fixtures .load ("empty_zones_list.json" )
0 commit comments