#31 API DELETE Tests
* adds tests for DELETE method of all major data types
This commit is contained in:
parent
e7dbea49cd
commit
3d446883c6
7
api/tests/v1/delete/__init__.py
Normal file
7
api/tests/v1/delete/__init__.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
"""
|
||||||
|
Author: Michel Peltriaux
|
||||||
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||||
|
Contact: michel.peltriaux@sgdnord.rlp.de
|
||||||
|
Created on: 28.01.22
|
||||||
|
|
||||||
|
"""
|
95
api/tests/v1/delete/test_api_delete.py
Normal file
95
api/tests/v1/delete/test_api_delete.py
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
"""
|
||||||
|
Author: Michel Peltriaux
|
||||||
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||||
|
Contact: michel.peltriaux@sgdnord.rlp.de
|
||||||
|
Created on: 28.01.22
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
|
from api.tests.v1.test_api_sharing import BaseAPIV1TestCase
|
||||||
|
|
||||||
|
|
||||||
|
class APIV1DeleteTestCase(BaseAPIV1TestCase):
|
||||||
|
@classmethod
|
||||||
|
def setUpTestData(cls):
|
||||||
|
super().setUpTestData()
|
||||||
|
|
||||||
|
def _run_delete_request(self, url):
|
||||||
|
response = self.client.delete(
|
||||||
|
url,
|
||||||
|
**self.header_data
|
||||||
|
)
|
||||||
|
return response
|
||||||
|
|
||||||
|
def _test_delete_object(self, obj, url):
|
||||||
|
""" Tests the API DELETE of a data object.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
url (str): The api delete url
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
obj.refresh_from_db()
|
||||||
|
_id = obj.id
|
||||||
|
self.assertIsNotNone(_id)
|
||||||
|
self.assertIsNone(obj.deleted)
|
||||||
|
|
||||||
|
response = self._run_delete_request(url)
|
||||||
|
content = json.loads(response.content)
|
||||||
|
|
||||||
|
self.assertEqual(response.status_code, 200, msg=response.content)
|
||||||
|
self.assertTrue(content.get("success", False), msg=response.content)
|
||||||
|
|
||||||
|
obj.refresh_from_db()
|
||||||
|
self.assertIsNotNone(obj.deleted)
|
||||||
|
self.assertEqual(obj.deleted.user, self.superuser)
|
||||||
|
|
||||||
|
def test_delete_intervention(self):
|
||||||
|
""" Tests api creation of bare minimum interventions
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
test_intervention = self.create_dummy_intervention()
|
||||||
|
test_intervention.share_with(self.superuser)
|
||||||
|
url = reverse("api:v1:intervention", args=(str(test_intervention.id),))
|
||||||
|
self._test_delete_object(test_intervention, url)
|
||||||
|
|
||||||
|
def test_delete_compensation(self):
|
||||||
|
""" Tests api creation of bare minimum interventions
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
test_comp = self.create_dummy_compensation()
|
||||||
|
test_comp.share_with(self.superuser)
|
||||||
|
url = reverse("api:v1:compensation", args=(str(test_comp.id),))
|
||||||
|
self._test_delete_object(test_comp, url)
|
||||||
|
|
||||||
|
def test_delete_eco_account(self):
|
||||||
|
""" Tests api creation of bare minimum interventions
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
test_acc = self.create_dummy_eco_account()
|
||||||
|
test_acc.share_with(self.superuser)
|
||||||
|
url = reverse("api:v1:ecoaccount", args=(str(test_acc.id),))
|
||||||
|
self._test_delete_object(test_acc, url)
|
||||||
|
|
||||||
|
def test_delete_ema(self):
|
||||||
|
""" Tests api creation of bare minimum interventions
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
test_ema = self.create_dummy_ema()
|
||||||
|
test_ema.share_with(self.superuser)
|
||||||
|
url = reverse("api:v1:ema", args=(str(test_ema.id),))
|
||||||
|
self._test_delete_object(test_ema, url)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user