diff --git a/api/tests/v1/create/compensation_create_post_body.json b/api/tests/v1/create/compensation_create_post_body.json index 865621a1..0eecc7c6 100644 --- a/api/tests/v1/create/compensation_create_post_body.json +++ b/api/tests/v1/create/compensation_create_post_body.json @@ -8,6 +8,7 @@ "is_coherence_keeping": false, "is_pik": false, "intervention": "MUST_BE_SET_IN_TEST", + "external_identifier": "LOREMIPSUM-123", "before_states": [ ], "after_states": [ diff --git a/api/tests/v1/create/ecoaccount_create_post_body.json b/api/tests/v1/create/ecoaccount_create_post_body.json index 7550d8cd..72f456f6 100644 --- a/api/tests/v1/create/ecoaccount_create_post_body.json +++ b/api/tests/v1/create/ecoaccount_create_post_body.json @@ -4,6 +4,7 @@ ], "properties": { "title": "Test_ecoaccount", + "external_identifier": "LOREMIPSUM-1234", "deductable_surface": 10000.0, "is_pik": false, "responsible": { diff --git a/api/tests/v1/create/ema_create_post_body.json b/api/tests/v1/create/ema_create_post_body.json index 8b826661..b8250864 100644 --- a/api/tests/v1/create/ema_create_post_body.json +++ b/api/tests/v1/create/ema_create_post_body.json @@ -4,6 +4,7 @@ ], "properties": { "title": "Test_ema", + "external_identifier": "LOREMIPSUM-1235", "is_pik": false, "responsible": { "conservation_office": null, diff --git a/api/tests/v1/create/intervention_create_post_body.json b/api/tests/v1/create/intervention_create_post_body.json index 30def080..955ecd51 100644 --- a/api/tests/v1/create/intervention_create_post_body.json +++ b/api/tests/v1/create/intervention_create_post_body.json @@ -4,6 +4,7 @@ ], "properties": { "title": "Test_intervention", + "external_identifier": "LOREMIPSUM-1236", "responsible": { "registration_office": null, "registration_file_number": null, diff --git a/api/tests/v1/create/test_api_create.py b/api/tests/v1/create/test_api_create.py index 63719839..87025611 100644 --- a/api/tests/v1/create/test_api_create.py +++ b/api/tests/v1/create/test_api_create.py @@ -9,6 +9,7 @@ import json from django.urls import reverse +from api.models import ExternalIdentifier from api.tests.v1.share.test_api_sharing import BaseAPIV1TestCase @@ -42,7 +43,22 @@ class APIV1CreateTestCase(BaseAPIV1TestCase): response = self._run_create_request(url, post_body) self.assertEqual(response.status_code, 200, msg=response.content) content = json.loads(response.content) - self.assertIsNotNone(content.get("id", None), msg=response.content) + _id = content.get("id", None) + self.assertIsNotNone(_id, msg=response.content) + return _id + + def _test_external_identifier_created(self, internal_id, external_id): + """ Tests whether an external identifier has been created + + Args: + internal_id (): + external_id (): + + Returns: + + """ + external_identifier = ExternalIdentifier.objects.get(internal_id=internal_id) + self.assertEqual(external_identifier.external_id, external_id) def test_create_intervention(self): """ Tests api creation @@ -54,7 +70,8 @@ class APIV1CreateTestCase(BaseAPIV1TestCase): json_file_path = "api/tests/v1/create/intervention_create_post_body.json" with open(json_file_path) as json_file: post_body = json.load(fp=json_file) - self._test_create_object(url, post_body) + internal_id = self._test_create_object(url, post_body) + self._test_external_identifier_created(internal_id, post_body["properties"]["external_identifier"]) def test_create_compensation(self): """ Tests api creation @@ -77,7 +94,8 @@ class APIV1CreateTestCase(BaseAPIV1TestCase): # Add the user to the shared users of the intervention and try again! Now everything should work as expected. self.intervention.users.add(self.superuser) - self._test_create_object(url, post_body) + internal_id = self._test_create_object(url, post_body) + self._test_external_identifier_created(internal_id, post_body["properties"]["external_identifier"]) def test_create_eco_account(self): """ Tests api creation @@ -89,7 +107,8 @@ class APIV1CreateTestCase(BaseAPIV1TestCase): json_file_path = "api/tests/v1/create/ecoaccount_create_post_body.json" with open(json_file_path) as json_file: post_body = json.load(fp=json_file) - self._test_create_object(url, post_body) + internal_id = self._test_create_object(url, post_body) + self._test_external_identifier_created(internal_id, post_body["properties"]["external_identifier"]) def test_create_ema(self): """ Tests api creation @@ -101,7 +120,8 @@ class APIV1CreateTestCase(BaseAPIV1TestCase): json_file_path = "api/tests/v1/create/ema_create_post_body.json" with open(json_file_path) as json_file: post_body = json.load(fp=json_file) - self._test_create_object(url, post_body) + internal_id = self._test_create_object(url, post_body) + self._test_external_identifier_created(internal_id, post_body["properties"]["external_identifier"]) def test_create_deduction(self): """ Tests api creation diff --git a/api/tests/v1/update/compensation_update_put_body.json b/api/tests/v1/update/compensation_update_put_body.json index 4ae91ac7..7c5886df 100644 --- a/api/tests/v1/update/compensation_update_put_body.json +++ b/api/tests/v1/update/compensation_update_put_body.json @@ -44,6 +44,7 @@ ], "properties": { "title": "TEST_compensation_CHANGED", + "external_identifier": "LOREMIPSUM-123_CHANGED", "is_cef": true, "is_coherence_keeping": true, "is_pik": true, diff --git a/api/tests/v1/update/ecoaccount_update_put_body.json b/api/tests/v1/update/ecoaccount_update_put_body.json index 2b8235cb..23025e90 100644 --- a/api/tests/v1/update/ecoaccount_update_put_body.json +++ b/api/tests/v1/update/ecoaccount_update_put_body.json @@ -44,6 +44,7 @@ ], "properties": { "title": "TEST_account_CHANGED", + "external_identifier": "LOREMIPSUM-1234_CHANGED", "deductable_surface": "100000.0", "is_pik": true, "responsible": { diff --git a/api/tests/v1/update/ema_update_put_body.json b/api/tests/v1/update/ema_update_put_body.json index 6c7adf68..6e24f804 100644 --- a/api/tests/v1/update/ema_update_put_body.json +++ b/api/tests/v1/update/ema_update_put_body.json @@ -44,6 +44,7 @@ ], "properties": { "title": "TEST_EMA_CHANGED", + "external_identifier": "LOREMIPSUM-1235_CHANGED", "responsible": { "conservation_office": null, "conservation_file_number": "TEST_CHANGED", diff --git a/api/tests/v1/update/intervention_update_put_body.json b/api/tests/v1/update/intervention_update_put_body.json index df1d6e64..63acc17f 100644 --- a/api/tests/v1/update/intervention_update_put_body.json +++ b/api/tests/v1/update/intervention_update_put_body.json @@ -44,6 +44,7 @@ ], "properties": { "title": "Test_intervention_CHANGED", + "external_identifier": "LOREMIPSUM-1236_CHANGED", "responsible": { "registration_office": null, "registration_file_number": "CHANGED",