From 3d446883c660e485249dc10b00d5dc628c35c880 Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Fri, 28 Jan 2022 09:24:14 +0100 Subject: [PATCH] #31 API DELETE Tests * adds tests for DELETE method of all major data types --- api/tests/v1/delete/__init__.py | 7 ++ api/tests/v1/delete/test_api_delete.py | 95 ++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 api/tests/v1/delete/__init__.py create mode 100644 api/tests/v1/delete/test_api_delete.py diff --git a/api/tests/v1/delete/__init__.py b/api/tests/v1/delete/__init__.py new file mode 100644 index 00000000..3659b8cb --- /dev/null +++ b/api/tests/v1/delete/__init__.py @@ -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 + +""" diff --git a/api/tests/v1/delete/test_api_delete.py b/api/tests/v1/delete/test_api_delete.py new file mode 100644 index 00000000..1c5503b1 --- /dev/null +++ b/api/tests/v1/delete/test_api_delete.py @@ -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) +