Browse Source

refactor some tests to allow more flexible payloads

Peter Thomassen 6 years ago
parent
commit
898c122705

+ 4 - 4
api/desecapi/tests/base.py

@@ -83,16 +83,16 @@ class DesecAPIClient(APIClient):
             self.reverse('v1:rrset@', name=domain_name, subname=subname, type=type_)
         )
 
-    def put_rr_set(self, domain_name, subname, type_, **kwargs):
+    def put_rr_set(self, domain_name, subname, type_, data):
         return self.put(
             self.reverse('v1:rrset@', name=domain_name, subname=subname, type=type_),
-            kwargs
+            data
         )
 
-    def patch_rr_set(self, domain_name, subname, type_, **kwargs):
+    def patch_rr_set(self, domain_name, subname, type_, data):
         return self.patch(
             self.reverse('v1:rrset@', name=domain_name, subname=subname, type=type_),
-            kwargs
+            data
         )
 
     def delete_rr_set(self, domain_name, subname, type_):

+ 4 - 4
api/desecapi/tests/test_domains.py

@@ -91,7 +91,7 @@ class DomainOwnerTestCase1(DomainOwnerTestCase):
             self.assertStatus(response, status.HTTP_200_OK)
 
         response.data['name'] = self.random_domain_name()
-        response = self.client.put(url, json.dumps(response.data), content_type='application/json')
+        response = self.client.put(url, response.data, format='json')
         self.assertStatus(response, status.HTTP_400_BAD_REQUEST)
 
         with self.assertPdnsRequests(self.request_pdns_zone_retrieve_crypto_keys(name=self.my_domain.name)):
@@ -101,7 +101,7 @@ class DomainOwnerTestCase1(DomainOwnerTestCase):
 
     def test_update_other_domains(self):
         url = self.reverse('v1:domain-detail', name=self.other_domain.name)
-        response = self.client.put(url, json.dumps({}), content_type='application/json')
+        response = self.client.put(url, {}, format='json')
         self.assertStatus(response, status.HTTP_404_NOT_FOUND)
 
     def test_create_domains(self):
@@ -276,7 +276,7 @@ class LockedDomainOwnerTestCase1(LockedDomainOwnerTestCase):
         type_ = 'A'
         for subname in ['', '*', 'asdf', 'asdf.adsf.asdf']:
             data = {'records': ['1.2.3.4'], 'ttl': 60}
-            response = self.client.put_rr_set(self.my_domain.name, subname, type_, **data)
+            response = self.client.put_rr_set(self.my_domain.name, subname, type_, data)
             self.assertStatus(response, status.HTTP_403_FORBIDDEN)
 
             for patch_request in [
@@ -286,7 +286,7 @@ class LockedDomainOwnerTestCase1(LockedDomainOwnerTestCase):
                 {'ttl': 60},
                 {},
             ]:
-                response = self.client.patch_rr_set(self.my_domain.name, subname, type_, **patch_request)
+                response = self.client.patch_rr_set(self.my_domain.name, subname, type_, patch_request)
                 self.assertStatus(response, status.HTTP_403_FORBIDDEN)
 
             # Try DELETE

+ 1 - 2
api/desecapi/tests/test_dyndns12update.py

@@ -41,8 +41,7 @@ class DynDNS12UpdateTest(DynDomainOwnerTestCase):
             self.request_pdns_zone_update(self.my_domain.name),
             self.request_pdns_zone_axfr(self.my_domain.name),
         ):
-            response = self.client_token_authorized.patch_rr_set(
-                self.my_domain.name.lower(), subname='', type_='A', ttl=3600)
+            response = self.client_token_authorized.patch_rr_set(self.my_domain.name.lower(), '', 'A', {'ttl': 3600})
             self.assertStatus(response, status.HTTP_200_OK)
 
         response = self.assertDynDNS12Update(self.my_domain.name)

+ 17 - 13
api/desecapi/tests/test_rrsets.py

@@ -172,7 +172,8 @@ class AuthenticatedRRSetTestCase(AuthenticatedRRSetBaseTestCase):
     def test_update_my_rr_sets(self):
         for subname in self.SUBNAMES:
             with self.assertPdnsRequests(self.requests_desec_rr_sets_update(name=self.my_rr_set_domain.name)):
-                response = self.client.put_rr_set(self.my_rr_set_domain.name, subname, 'A', records=['2.2.3.4'], ttl=30)
+                data = {'records': ['2.2.3.4'], 'ttl': 30}
+                response = self.client.put_rr_set(self.my_rr_set_domain.name, subname, 'A', data)
                 self.assertStatus(response, status.HTTP_200_OK)
 
             response = self.client.get_rr_set(self.my_rr_set_domain.name, subname, 'A')
@@ -180,10 +181,10 @@ class AuthenticatedRRSetTestCase(AuthenticatedRRSetBaseTestCase):
             self.assertEqual(response.data['records'], ['2.2.3.4'])
             self.assertEqual(response.data['ttl'], 30)
 
-            response = self.client.put_rr_set(self.my_rr_set_domain.name, subname, 'A', records=['2.2.3.5'])
+            response = self.client.put_rr_set(self.my_rr_set_domain.name, subname, 'A', {'records': ['2.2.3.5']})
             self.assertStatus(response, status.HTTP_400_BAD_REQUEST)
 
-            response = self.client.put_rr_set(self.my_rr_set_domain.name, subname, 'A', ttl=37)
+            response = self.client.put_rr_set(self.my_rr_set_domain.name, subname, 'A', {'ttl': 37})
             self.assertStatus(response, status.HTTP_400_BAD_REQUEST)
 
     def test_partially_update_my_rr_sets(self):
@@ -196,7 +197,7 @@ class AuthenticatedRRSetTestCase(AuthenticatedRRSetBaseTestCase):
                 {'ttl': 37},
             ]:
                 with self.assertPdnsRequests(self.requests_desec_rr_sets_update(name=self.my_rr_set_domain.name)):
-                    response = self.client.patch_rr_set(self.my_rr_set_domain.name, subname, 'A', **data)
+                    response = self.client.patch_rr_set(self.my_rr_set_domain.name, subname, 'A', data)
                     self.assertStatus(response, status.HTTP_200_OK)
 
                 response = self.client.get_rr_set(self.my_rr_set_domain.name, subname, 'A')
@@ -205,18 +206,19 @@ class AuthenticatedRRSetTestCase(AuthenticatedRRSetBaseTestCase):
                 self.assertEqual(response.data['records'], current_rr_set['records'])
                 self.assertEqual(response.data['ttl'], current_rr_set['ttl'])
 
-            response = self.client.patch_rr_set(self.my_rr_set_domain.name, subname, 'A')
+            response = self.client.patch_rr_set(self.my_rr_set_domain.name, subname, 'A', {})
             self.assertStatus(response, status.HTTP_200_OK)
 
     def test_partially_update_other_rr_sets(self):
+        data = {'records': ['3.2.3.4'], 'ttl': 334}
         for subname in self.SUBNAMES:
-            response = self.client.patch_rr_set(self.other_rr_set_domain.name, subname=subname,
-                                                type_='A', records=['3.2.3.4'], ttl=334)
+            response = self.client.patch_rr_set(self.other_rr_set_domain.name, subname, 'A', data)
             self.assertStatus(response, status.HTTP_404_NOT_FOUND)
 
     def test_update_other_rr_sets(self):
+        data = {'ttl': 305}
         for subname in self.SUBNAMES:
-            response = self.client.patch_rr_set(self.other_rr_set_domain.name, subname=subname, type_='A', ttl=305)
+            response = self.client.patch_rr_set(self.other_rr_set_domain.name, subname, 'A', data)
             self.assertStatus(response, status.HTTP_404_NOT_FOUND)
 
     def test_update_essential_properties(self):
@@ -267,17 +269,18 @@ class AuthenticatedRRSetTestCase(AuthenticatedRRSetBaseTestCase):
         self.assertStatus(response, status.HTTP_404_NOT_FOUND)
 
     def test_delete_my_rr_sets_with_patch(self):
+        data = {'records': []}
         for subname in self.SUBNAMES:
             with self.assertPdnsRequests(self.requests_desec_rr_sets_update(name=self.my_rr_set_domain.name)):
-                response = self.client.patch_rr_set(self.my_rr_set_domain.name, subname=subname, type_='A', records=[])
+                response = self.client.patch_rr_set(self.my_rr_set_domain.name, subname, 'A', data)
                 self.assertStatus(response, status.HTTP_204_NO_CONTENT)
 
             # Deletion is only idempotent via DELETE. For PATCH/PUT, the view raises 404 if the instance does not
             # exist. By that time, the view has not parsed the payload yet and does not know it is a deletion.
-            response = self.client.patch_rr_set(self.my_rr_set_domain.name, subname=subname, type_='A', records=[])
+            response = self.client.patch_rr_set(self.my_rr_set_domain.name, subname, 'A', data)
             self.assertStatus(response, status.HTTP_404_NOT_FOUND)
 
-            response = self.client.get_rr_set(self.my_rr_set_domain.name, subname=subname, type_='A')
+            response = self.client.get_rr_set(self.my_rr_set_domain.name, subname, 'A')
             self.assertStatus(response, status.HTTP_404_NOT_FOUND)
 
     def test_delete_my_rr_sets_with_delete(self):
@@ -293,13 +296,14 @@ class AuthenticatedRRSetTestCase(AuthenticatedRRSetBaseTestCase):
             self.assertStatus(response, status.HTTP_404_NOT_FOUND)
 
     def test_delete_other_rr_sets(self):
+        data = {'records': []}
         for subname in self.SUBNAMES:
             # Try PATCH empty
-            response = self.client.patch_rr_set(self.other_rr_set_domain.name, subname=subname, type_='A', records=[])
+            response = self.client.patch_rr_set(self.other_rr_set_domain.name, subname, 'A', data)
             self.assertStatus(response, status.HTTP_404_NOT_FOUND)
 
             # Try DELETE
-            response = self.client.delete_rr_set(self.other_rr_set_domain.name, subname=subname, type_='A')
+            response = self.client.delete_rr_set(self.other_rr_set_domain.name, subname, 'A')
             self.assertStatus(response, status.HTTP_404_NOT_FOUND)
 
             # Make sure it actually is still there