5
api/tests/v1/create/deduction_create_post_body.json
Normal file
5
api/tests/v1/create/deduction_create_post_body.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"eco_account": "CHANGE_BEFORE_RUN!!!",
|
||||
"surface": 500.0,
|
||||
"intervention": "CHANGE_BEFORE_RUN!!!"
|
||||
}
|
||||
@@ -45,7 +45,7 @@ class APIV1CreateTestCase(BaseAPIV1TestCase):
|
||||
self.assertIsNotNone(content.get("id", None), msg=response.content)
|
||||
|
||||
def test_create_intervention(self):
|
||||
""" Tests api creation of bare minimum interventions
|
||||
""" Tests api creation
|
||||
|
||||
Returns:
|
||||
|
||||
@@ -57,7 +57,7 @@ class APIV1CreateTestCase(BaseAPIV1TestCase):
|
||||
self._test_create_object(url, post_body)
|
||||
|
||||
def test_create_compensation(self):
|
||||
""" Tests api creation of bare minimum interventions
|
||||
""" Tests api creation
|
||||
|
||||
Returns:
|
||||
|
||||
@@ -80,7 +80,7 @@ class APIV1CreateTestCase(BaseAPIV1TestCase):
|
||||
self._test_create_object(url, post_body)
|
||||
|
||||
def test_create_eco_account(self):
|
||||
""" Tests api creation of bare minimum interventions
|
||||
""" Tests api creation
|
||||
|
||||
Returns:
|
||||
|
||||
@@ -92,7 +92,7 @@ class APIV1CreateTestCase(BaseAPIV1TestCase):
|
||||
self._test_create_object(url, post_body)
|
||||
|
||||
def test_create_ema(self):
|
||||
""" Tests api creation of bare minimum interventions
|
||||
""" Tests api creation
|
||||
|
||||
Returns:
|
||||
|
||||
@@ -103,3 +103,20 @@ class APIV1CreateTestCase(BaseAPIV1TestCase):
|
||||
post_body = json.load(fp=json_file)
|
||||
self._test_create_object(url, post_body)
|
||||
|
||||
def test_create_deduction(self):
|
||||
""" Tests api creation
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
self.intervention.share_with(self.superuser)
|
||||
self.eco_account.share_with(self.superuser)
|
||||
|
||||
url = reverse("api:v1:deduction")
|
||||
json_file_path = "api/tests/v1/create/deduction_create_post_body.json"
|
||||
with open(json_file_path) as json_file:
|
||||
post_body = json.load(fp=json_file)
|
||||
post_body["intervention"] = str(self.intervention.id)
|
||||
post_body["eco_account"] = str(self.eco_account.id)
|
||||
self._test_create_object(url, post_body)
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ Created on: 28.01.22
|
||||
|
||||
import json
|
||||
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.urls import reverse
|
||||
|
||||
from api.tests.v1.share.test_api_sharing import BaseAPIV1TestCase
|
||||
@@ -93,3 +94,25 @@ class APIV1DeleteTestCase(BaseAPIV1TestCase):
|
||||
url = reverse("api:v1:ema", args=(str(test_ema.id),))
|
||||
self._test_delete_object(test_ema, url)
|
||||
|
||||
def test_delete_deduction(self):
|
||||
""" Tests api creation of bare minimum interventions
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
test_deduction = self.create_dummy_deduction()
|
||||
test_deduction.intervention.share_with(self.superuser)
|
||||
url = reverse("api:v1:deduction", args=(str(test_deduction.id),))
|
||||
|
||||
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)
|
||||
|
||||
try:
|
||||
test_deduction.refresh_from_db()
|
||||
self.fail("Deduction is not deleted from db!")
|
||||
except ObjectDoesNotExist:
|
||||
pass
|
||||
|
||||
|
||||
@@ -38,6 +38,9 @@ class APIV1GetTestCase(BaseAPIV1TestCase):
|
||||
content = json.loads(response.content)
|
||||
geojson = content[str(obj.id)]
|
||||
self.assertEqual(response.status_code, 200, msg=response.content)
|
||||
return geojson
|
||||
|
||||
def _assert_geojson_format(self, geojson):
|
||||
try:
|
||||
geojson["type"]
|
||||
geojson["coordinates"]
|
||||
@@ -49,7 +52,6 @@ class APIV1GetTestCase(BaseAPIV1TestCase):
|
||||
props["modified_on"]
|
||||
except KeyError as e:
|
||||
self.fail(e)
|
||||
return geojson
|
||||
|
||||
def test_get_intervention(self):
|
||||
""" Tests api GET
|
||||
@@ -60,6 +62,7 @@ class APIV1GetTestCase(BaseAPIV1TestCase):
|
||||
self.intervention.share_with(self.superuser)
|
||||
url = reverse("api:v1:intervention", args=(str(self.intervention.id),))
|
||||
geojson = self._test_get_object(self.intervention, url)
|
||||
self._assert_geojson_format(geojson)
|
||||
try:
|
||||
props = geojson["properties"]
|
||||
props["responsible"]
|
||||
@@ -89,6 +92,7 @@ class APIV1GetTestCase(BaseAPIV1TestCase):
|
||||
|
||||
url = reverse("api:v1:compensation", args=(str(self.compensation.id),))
|
||||
geojson = self._test_get_object(self.compensation, url)
|
||||
self._assert_geojson_format(geojson)
|
||||
try:
|
||||
props = geojson["properties"]
|
||||
props["is_cef"]
|
||||
@@ -114,6 +118,7 @@ class APIV1GetTestCase(BaseAPIV1TestCase):
|
||||
|
||||
url = reverse("api:v1:ecoaccount", args=(str(self.eco_account.id),))
|
||||
geojson = self._test_get_object(self.eco_account, url)
|
||||
self._assert_geojson_format(geojson)
|
||||
try:
|
||||
props = geojson["properties"]
|
||||
props["deductable_surface"]
|
||||
@@ -142,6 +147,7 @@ class APIV1GetTestCase(BaseAPIV1TestCase):
|
||||
|
||||
url = reverse("api:v1:ema", args=(str(self.ema.id),))
|
||||
geojson = self._test_get_object(self.ema, url)
|
||||
self._assert_geojson_format(geojson)
|
||||
try:
|
||||
props = geojson["properties"]
|
||||
props["responsible"]
|
||||
@@ -155,3 +161,27 @@ class APIV1GetTestCase(BaseAPIV1TestCase):
|
||||
except KeyError as e:
|
||||
self.fail(e)
|
||||
|
||||
def test_get_deduction(self):
|
||||
""" Tests api GET
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
self.deduction.intervention.share_with(self.superuser)
|
||||
|
||||
url = reverse("api:v1:deduction", args=(str(self.deduction.id),))
|
||||
_json = self._test_get_object(self.deduction, url)
|
||||
try:
|
||||
_json["id"]
|
||||
_json["eco_account"]
|
||||
_json["eco_account"]["id"]
|
||||
_json["eco_account"]["identifier"]
|
||||
_json["eco_account"]["title"]
|
||||
_json["surface"]
|
||||
_json["intervention"]
|
||||
_json["intervention"]["id"]
|
||||
_json["intervention"]["identifier"]
|
||||
_json["intervention"]["title"]
|
||||
except KeyError as e:
|
||||
self.fail(e)
|
||||
|
||||
|
||||
5
api/tests/v1/update/deduction_update_put_body.json
Normal file
5
api/tests/v1/update/deduction_update_put_body.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"eco_account": "CHANGE_BEFORE_RUN!!!",
|
||||
"surface": 523400.0,
|
||||
"intervention": "CHANGE_BEFORE_RUN!!!"
|
||||
}
|
||||
@@ -161,3 +161,26 @@ class APIV1UpdateTestCase(BaseAPIV1TestCase):
|
||||
self.assertEqual(len(put_props["before_states"]), self.ema.before_states.count())
|
||||
self.assertEqual(len(put_props["after_states"]), self.ema.after_states.count())
|
||||
self.assertEqual(len(put_props["deadlines"]), self.ema.deadlines.count())
|
||||
|
||||
def test_update_deduction(self):
|
||||
""" Tests api update
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
self.deduction.intervention.share_with(self.superuser)
|
||||
self.deduction.account.share_with(self.superuser)
|
||||
|
||||
url = reverse("api:v1:deduction", args=(str(self.deduction.id),))
|
||||
json_file_path = "api/tests/v1/update/deduction_update_put_body.json"
|
||||
with open(json_file_path) as json_file:
|
||||
put_body = json.load(fp=json_file)
|
||||
put_body["intervention"] = str(self.deduction.intervention.id)
|
||||
put_body["eco_account"] = str(self.deduction.account.id)
|
||||
|
||||
self._test_update_object(url, put_body)
|
||||
self.deduction.refresh_from_db()
|
||||
|
||||
self.assertEqual(put_body["intervention"], str(self.deduction.intervention.id))
|
||||
self.assertEqual(put_body["eco_account"], str(self.deduction.account.id))
|
||||
self.assertEqual(put_body["surface"], self.deduction.surface)
|
||||
|
||||
Reference in New Issue
Block a user