2022-01-28 12:30:09 +01:00
|
|
|
"""
|
|
|
|
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.share.test_api_sharing import BaseAPIV1TestCase
|
|
|
|
|
|
|
|
|
|
|
|
class APIV1GetTestCase(BaseAPIV1TestCase):
|
|
|
|
@classmethod
|
|
|
|
def setUpTestData(cls):
|
|
|
|
super().setUpTestData()
|
|
|
|
|
|
|
|
def _run_get_request(self, url):
|
|
|
|
response = self.client.get(
|
|
|
|
url,
|
|
|
|
**self.header_data
|
|
|
|
)
|
|
|
|
return response
|
|
|
|
|
|
|
|
def _test_get_object(self, obj, url):
|
|
|
|
""" Tests the API GET of a data object.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
url (str): The api get url
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
|
|
|
response = self._run_get_request(url)
|
|
|
|
content = json.loads(response.content)
|
2022-02-16 11:38:24 +01:00
|
|
|
self.assertIn("rpp", content)
|
|
|
|
self.assertIn("p", content)
|
|
|
|
self.assertIn("next", content)
|
|
|
|
self.assertIn("results", content)
|
|
|
|
paginated_content = content["results"]
|
|
|
|
geojson = paginated_content[str(obj.id)]
|
2022-01-28 12:30:09 +01:00
|
|
|
self.assertEqual(response.status_code, 200, msg=response.content)
|
2022-01-28 16:21:23 +01:00
|
|
|
return geojson
|
|
|
|
|
|
|
|
def _assert_geojson_format(self, geojson):
|
2022-01-28 12:30:09 +01:00
|
|
|
try:
|
|
|
|
geojson["type"]
|
|
|
|
geojson["coordinates"]
|
|
|
|
props = geojson["properties"]
|
|
|
|
props["id"]
|
|
|
|
props["identifier"]
|
|
|
|
props["title"]
|
|
|
|
props["created_on"]
|
|
|
|
props["modified_on"]
|
|
|
|
except KeyError as e:
|
|
|
|
self.fail(e)
|
|
|
|
|
|
|
|
def test_get_intervention(self):
|
|
|
|
""" Tests api GET
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
|
|
|
self.intervention.share_with(self.superuser)
|
|
|
|
url = reverse("api:v1:intervention", args=(str(self.intervention.id),))
|
|
|
|
geojson = self._test_get_object(self.intervention, url)
|
2022-01-28 16:21:23 +01:00
|
|
|
self._assert_geojson_format(geojson)
|
2022-01-28 12:30:09 +01:00
|
|
|
try:
|
|
|
|
props = geojson["properties"]
|
|
|
|
props["responsible"]
|
|
|
|
props["responsible"]["registration_office"]
|
|
|
|
props["responsible"]["registration_file_number"]
|
|
|
|
props["responsible"]["conservation_office"]
|
|
|
|
props["responsible"]["conservation_file_number"]
|
|
|
|
props["legal"]["registration_date"]
|
|
|
|
props["legal"]["binding_date"]
|
|
|
|
props["legal"]["process_type"]
|
|
|
|
props["legal"]["laws"]
|
|
|
|
props["compensations"]
|
|
|
|
props["payments"]
|
|
|
|
props["deductions"]
|
|
|
|
except KeyError as e:
|
|
|
|
self.fail(e)
|
|
|
|
|
|
|
|
def test_get_compensation(self):
|
|
|
|
""" Tests api GET
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
|
|
|
self.intervention.share_with(self.superuser)
|
|
|
|
self.compensation.intervention = self.intervention
|
|
|
|
self.compensation.save()
|
|
|
|
|
|
|
|
url = reverse("api:v1:compensation", args=(str(self.compensation.id),))
|
|
|
|
geojson = self._test_get_object(self.compensation, url)
|
2022-01-28 16:21:23 +01:00
|
|
|
self._assert_geojson_format(geojson)
|
2022-01-28 12:30:09 +01:00
|
|
|
try:
|
|
|
|
props = geojson["properties"]
|
|
|
|
props["is_cef"]
|
|
|
|
props["is_coherence_keeping"]
|
|
|
|
props["intervention"]
|
|
|
|
props["intervention"]["id"]
|
|
|
|
props["intervention"]["identifier"]
|
|
|
|
props["intervention"]["title"]
|
|
|
|
props["before_states"]
|
|
|
|
props["after_states"]
|
|
|
|
props["actions"]
|
|
|
|
props["deadlines"]
|
|
|
|
except KeyError as e:
|
|
|
|
self.fail(e)
|
|
|
|
|
|
|
|
def test_get_eco_account(self):
|
|
|
|
""" Tests api GET
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
|
|
|
self.eco_account.share_with(self.superuser)
|
|
|
|
|
|
|
|
url = reverse("api:v1:ecoaccount", args=(str(self.eco_account.id),))
|
|
|
|
geojson = self._test_get_object(self.eco_account, url)
|
2022-01-28 16:21:23 +01:00
|
|
|
self._assert_geojson_format(geojson)
|
2022-01-28 12:30:09 +01:00
|
|
|
try:
|
|
|
|
props = geojson["properties"]
|
|
|
|
props["deductable_surface"]
|
|
|
|
props["deductable_surface_available"]
|
|
|
|
props["responsible"]
|
|
|
|
props["responsible"]["conservation_office"]
|
|
|
|
props["responsible"]["conservation_file_number"]
|
|
|
|
props["responsible"]["handler"]
|
|
|
|
props["legal"]
|
|
|
|
props["legal"]["agreement_date"]
|
|
|
|
props["before_states"]
|
|
|
|
props["after_states"]
|
|
|
|
props["actions"]
|
|
|
|
props["deadlines"]
|
|
|
|
props["deductions"]
|
|
|
|
except KeyError as e:
|
|
|
|
self.fail(e)
|
|
|
|
|
|
|
|
def test_get_ema(self):
|
|
|
|
""" Tests api GET
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
|
|
|
self.ema.share_with(self.superuser)
|
|
|
|
|
|
|
|
url = reverse("api:v1:ema", args=(str(self.ema.id),))
|
|
|
|
geojson = self._test_get_object(self.ema, url)
|
2022-01-28 16:21:23 +01:00
|
|
|
self._assert_geojson_format(geojson)
|
2022-01-28 12:30:09 +01:00
|
|
|
try:
|
|
|
|
props = geojson["properties"]
|
|
|
|
props["responsible"]
|
|
|
|
props["responsible"]["conservation_office"]
|
|
|
|
props["responsible"]["conservation_file_number"]
|
|
|
|
props["responsible"]["handler"]
|
|
|
|
props["before_states"]
|
|
|
|
props["after_states"]
|
|
|
|
props["actions"]
|
|
|
|
props["deadlines"]
|
|
|
|
except KeyError as e:
|
|
|
|
self.fail(e)
|
|
|
|
|
2022-01-28 16:21:23 +01:00
|
|
|
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)
|
|
|
|
|