diff --git a/src/dapla_metadata/variable_definitions/generated/.openapi-generator-ignore b/src/dapla_metadata/variable_definitions/generated/.openapi-generator-ignore index 0ad8f99..f5aaa46 100644 --- a/src/dapla_metadata/variable_definitions/generated/.openapi-generator-ignore +++ b/src/dapla_metadata/variable_definitions/generated/.openapi-generator-ignore @@ -1,4 +1,6 @@ # Ignore everything to make sure we don't get extra cruft ** -# Unignore the directory with source code -!vardef_client/ +# Unignore the directories with domain code +!vardef_client/api/ +!vardef_client/docs/ +!vardef_client/models/ diff --git a/src/dapla_metadata/variable_definitions/generated/.openapi-generator/FILES b/src/dapla_metadata/variable_definitions/generated/.openapi-generator/FILES index f39d924..c3ef681 100644 --- a/src/dapla_metadata/variable_definitions/generated/.openapi-generator/FILES +++ b/src/dapla_metadata/variable_definitions/generated/.openapi-generator/FILES @@ -1,4 +1,3 @@ -vardef_client/__init__.py vardef_client/api/__init__.py vardef_client/api/data_migration_api.py vardef_client/api/draft_variable_definitions_api.py @@ -6,10 +5,6 @@ vardef_client/api/patches_api.py vardef_client/api/public_api.py vardef_client/api/validity_periods_api.py vardef_client/api/variable_definitions_api.py -vardef_client/api_client.py -vardef_client/api_response.py -vardef_client/configuration.py -vardef_client/exceptions.py vardef_client/models/__init__.py vardef_client/models/complete_response.py vardef_client/models/contact.py @@ -26,5 +21,3 @@ vardef_client/models/supported_languages.py vardef_client/models/update_draft.py vardef_client/models/validity_period.py vardef_client/models/variable_status.py -vardef_client/py.typed -vardef_client/rest.py diff --git a/src/dapla_metadata/variable_definitions/generated/vardef_client/api/patches_api.py b/src/dapla_metadata/variable_definitions/generated/vardef_client/api/patches_api.py index 6a1e731..d87cdfb 100644 --- a/src/dapla_metadata/variable_definitions/generated/vardef_client/api/patches_api.py +++ b/src/dapla_metadata/variable_definitions/generated/vardef_client/api/patches_api.py @@ -113,6 +113,7 @@ def create_patch( _response_types_map: dict[str, str | None] = { "201": "CompleteResponse", + "404": "Problem", "400": "Problem", "405": "Problem", } @@ -200,6 +201,7 @@ def create_patch_with_http_info( _response_types_map: dict[str, str | None] = { "201": "CompleteResponse", + "404": "Problem", "400": "Problem", "405": "Problem", } @@ -287,6 +289,7 @@ def create_patch_without_preload_content( _response_types_map: dict[str, str | None] = { "201": "CompleteResponse", + "404": "Problem", "400": "Problem", "405": "Problem", } diff --git a/src/dapla_metadata/variable_definitions/generated/vardef_client/api/validity_periods_api.py b/src/dapla_metadata/variable_definitions/generated/vardef_client/api/validity_periods_api.py index ce6985f..3f265ce 100644 --- a/src/dapla_metadata/variable_definitions/generated/vardef_client/api/validity_periods_api.py +++ b/src/dapla_metadata/variable_definitions/generated/vardef_client/api/validity_periods_api.py @@ -105,6 +105,7 @@ def create_validity_period( _response_types_map: dict[str, str | None] = { "201": "CompleteResponse", + "404": "Problem", "400": "Problem", "405": "Problem", } @@ -183,6 +184,7 @@ def create_validity_period_with_http_info( _response_types_map: dict[str, str | None] = { "201": "CompleteResponse", + "404": "Problem", "400": "Problem", "405": "Problem", } @@ -261,6 +263,7 @@ def create_validity_period_without_preload_content( _response_types_map: dict[str, str | None] = { "201": "CompleteResponse", + "404": "Problem", "400": "Problem", "405": "Problem", } @@ -673,6 +676,7 @@ def list_validity_periods( _response_types_map: dict[str, str | None] = { "200": "List[CompleteResponse]", + "404": "Problem", } response_data = self.api_client.call_api( *_param, @@ -738,6 +742,7 @@ def list_validity_periods_with_http_info( _response_types_map: dict[str, str | None] = { "200": "List[CompleteResponse]", + "404": "Problem", } response_data = self.api_client.call_api( *_param, @@ -803,6 +808,7 @@ def list_validity_periods_without_preload_content( _response_types_map: dict[str, str | None] = { "200": "List[CompleteResponse]", + "404": "Problem", } response_data = self.api_client.call_api( *_param, @@ -845,6 +851,7 @@ def _list_validity_periods_serialize( _header_params["Accept"] = self.api_client.select_header_accept( [ "application/json", + "application/problem+json", ], ) diff --git a/src/dapla_metadata/variable_definitions/generated/vardef_client/models/variable_status.py b/src/dapla_metadata/variable_definitions/generated/vardef_client/models/variable_status.py index 0fdbe00..1323a87 100644 --- a/src/dapla_metadata/variable_definitions/generated/vardef_client/models/variable_status.py +++ b/src/dapla_metadata/variable_definitions/generated/vardef_client/models/variable_status.py @@ -26,7 +26,6 @@ class VariableStatus(str, Enum): DRAFT = "DRAFT" PUBLISHED_INTERNAL = "PUBLISHED_INTERNAL" PUBLISHED_EXTERNAL = "PUBLISHED_EXTERNAL" - DEPRECATED = "DEPRECATED" @classmethod def from_json(cls, json_str: str) -> Self: diff --git a/tests/utils/constants.py b/tests/utils/constants.py index 6fd1814..2959fb0 100644 --- a/tests/utils/constants.py +++ b/tests/utils/constants.py @@ -1,6 +1,7 @@ from datetime import date VARDEF_EXAMPLE_DEFINITION_ID = "wypvb3wd" +VARDEF_EXAMPLE_INVALID_ID = "invalid id" VARDEF_EXAMPLE_ACTIVE_GROUP = "dapla-felles-developers" VARDEF_EXAMPLE_DATE = date(1970, 1, 1) JUPYTERHUB_USER = "JUPYTERHUB_USER" diff --git a/tests/variable_definitions/conftest.py b/tests/variable_definitions/conftest.py index 9b4f87a..6e2aa3e 100644 --- a/tests/variable_definitions/conftest.py +++ b/tests/variable_definitions/conftest.py @@ -39,6 +39,7 @@ ) from dapla_metadata.variable_definitions.variable_definition import VariableDefinition from tests.utils.constants import VARDEF_EXAMPLE_DEFINITION_ID +from tests.utils.constants import VARDEF_EXAMPLE_INVALID_ID from tests.utils.microcks_testcontainer import MicrocksContainer @@ -90,14 +91,13 @@ def draft(language_string_type, contact) -> Draft: ) -@pytest.fixture -def variable_definition(language_string_type, contact, owner) -> VariableDefinition: +def sample_variable_definition() -> VariableDefinition: return VariableDefinition( id=VARDEF_EXAMPLE_DEFINITION_ID, patch_id=1, - name=language_string_type, + name=LanguageStringType(nb="test", nn="test", en="test"), short_name="var_test", - definition=language_string_type, + definition=LanguageStringType(nb="test", nn="test", en="test"), classification_reference="91", unit_types=["01"], subject_fields=["a", "b"], @@ -107,10 +107,13 @@ def variable_definition(language_string_type, contact, owner) -> VariableDefinit valid_from=date(2024, 11, 1), valid_until=None, external_reference_uri="http://www.example.com", - comment=language_string_type, + comment=LanguageStringType(nb="test", nn="test", en="test"), related_variable_definition_uris=["http://www.example.com"], - contact=contact, - owner=owner, + contact=Contact( + title=LanguageStringType(nb="test", nn="test", en="test"), + email="me@example.com", + ), + owner=Owner(team="my_team", groups=["my_team_developers"]), created_at=date(2024, 11, 1), created_by=Person(code="724", name="name"), last_updated_at=date(2024, 11, 1), @@ -118,6 +121,17 @@ def variable_definition(language_string_type, contact, owner) -> VariableDefinit ) +def unknown_variable_definition() -> VariableDefinition: + unknown = sample_variable_definition() + unknown.id = VARDEF_EXAMPLE_INVALID_ID + return unknown + + +@pytest.fixture +def variable_definition() -> VariableDefinition: + return sample_variable_definition() + + @pytest.fixture def update_draft(language_string_type, contact, owner) -> UpdateDraft: return UpdateDraft( diff --git a/tests/variable_definitions/resources/variable-definitions-0.1.yml b/tests/variable_definitions/resources/variable-definitions-0.1.yml index 6c017c0..857ecf2 100644 --- a/tests/variable_definitions/resources/variable-definitions-0.1.yml +++ b/tests/variable_definitions/resources/variable-definitions-0.1.yml @@ -155,7 +155,13 @@ paths: required: true schema: type: string - example: wypvb3wd + examples: + Date not specified: + value: wypvb3wd + Specific date: + value: wypvb3wd + Not found: + value: invalid id - name: Accept-Language in: header description: Render the variable definition in the given language. @@ -281,6 +287,8 @@ paths: examples: Validity periods: value: wypvb3wd + Not found: + value: invalid id - name: Accept-Language in: header description: Render the variable definition in the given language. @@ -463,10 +471,8 @@ paths: title: Constraint Violation status: 400 violations: - - field: myField - message: Invalid format - - field: otherField - message: must not be empty + - field: classificationReference + message: Code incorrect is not a valid classification id security: - keycloak_token: [] /variable-definitions: @@ -583,6 +589,61 @@ paths: application/json: schema: $ref: "#/components/schemas/Draft" + examples: + Create draft: + value: + name: + en: Country Background + nb: Landbakgrunn + nn: Landbakgrunn + short_name: landbak + definition: + en: "Country background is the person's own, the mother's or possibly\ + \ the father's country of birth. Persons without an immigrant\ + \ background always have Norway as country background. In cases\ + \ where the parents have different countries of birth the mother's\ + \ country of birth is chosen. If neither the person nor the\ + \ parents are born abroad, country background is chosen from\ + \ the first person born abroad in the order mother's mother,\ + \ mother's father, father's mother, father's father." + nb: "For personer født i utlandet, er dette (med noen få unntak)\ + \ eget fødeland. For personer født i Norge er det foreldrenes\ + \ fødeland. I de tilfeller der foreldrene har ulikt fødeland,\ + \ er det morens fødeland som blir valgt. Hvis ikke personen\ + \ selv eller noen av foreldrene er utenlandsfødt, hentes landbakgrunn\ + \ fra de første utenlandsfødte en treffer på i rekkefølgen mormor,\ + \ morfar, farmor eller farfar." + nn: "For personar fødd i utlandet, er dette (med nokre få unntak)\ + \ eige fødeland. For personar fødd i Noreg er det fødelandet\ + \ til foreldra. I dei tilfella der foreldra har ulikt fødeland,\ + \ er det fødelandet til mora som blir valt. Viss ikkje personen\ + \ sjølv eller nokon av foreldra er utenlandsfødt, blir henta\ + \ landsbakgrunn frå dei første utenlandsfødte ein treffar på\ + \ i rekkjefølgja mormor, morfar, farmor eller farfar." + classification_reference: "91" + unit_types: + - "01" + - "02" + subject_fields: + - he04 + contains_special_categories_of_personal_data: true + valid_from: 2003-01-01 + external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb + comment: + nb: Fra og med 1.1.2003 ble definisjon endret til også å trekke + inn besteforeldrenes fødeland. + nn: Fra og med 1.1.2003 ble definisjon endret til også å trekke + inn besteforeldrenes fødeland. + en: "As of 1 January 2003, the definition was changed to also\ + \ include the grandparents' country of birth." + related_variable_definition_uris: + - https://example.com/ + contact: + title: + en: Division for population statistics + nb: Seksjon for befolkningsstatistikk + nn: Seksjon for befolkningsstatistikk + email: s320@ssb.no required: true responses: "201": @@ -683,10 +744,8 @@ paths: title: Constraint Violation status: 400 violations: - - field: myField - message: Invalid format - - field: otherField - message: must not be empty + - field: classificationReference + message: Code incorrect is not a valid classification id "409": description: Short name is already in use by another variable definition. content: @@ -911,6 +970,8 @@ paths: examples: Delete: value: wypvb3wd + Not found: + value: invalid id - name: active_group in: query description: The group which the user currently represents. @@ -969,10 +1030,11 @@ paths: required: true schema: type: string - description: Unique identifier for the variable definition. examples: Update: value: wypvb3wd + Not found: + value: invalid id - name: active_group in: query description: The group which the user currently represents. @@ -987,6 +1049,13 @@ paths: application/json: schema: $ref: "#/components/schemas/UpdateDraft" + examples: + Update: + value: + classification_reference: "702" + Constraint violation: + value: + classification_reference: incorrect required: true responses: "200": @@ -1087,10 +1156,8 @@ paths: title: Constraint Violation status: 400 violations: - - field: myField - message: Invalid format - - field: otherField - message: must not be empty + - field: classificationReference + message: Code incorrect is not a valid classification id "404": description: Not found content: @@ -1148,6 +1215,8 @@ paths: examples: Patches: value: wypvb3wd + Not found: + value: invalid id responses: "200": description: Ok @@ -1248,6 +1317,8 @@ paths: examples: Create patch: value: wypvb3wd + Not found: + value: invalid id - name: valid_from in: query description: Valid from date for the specific validity period to be patched. @@ -1272,6 +1343,57 @@ paths: application/json: schema: $ref: "#/components/schemas/Patch" + examples: + Create patch: + value: + name: + en: Country Background + nb: Landbakgrunnen + nn: Landbakgrunnen + definition: + en: "Country background is the person's own, the mother's or possibly\ + \ the father's country of birth. Persons without an immigrant\ + \ background always have Norway as country background. In cases\ + \ where the parents have different countries of birth the mother's\ + \ country of birth is chosen. If neither the person nor the\ + \ parents are born abroad, country background is chosen from\ + \ the first person born abroad in the order mother's mother,\ + \ mother's father, father's mother, father's father." + nb: "For personer født i utlandet, er dette (med noen få unntak)\ + \ eget fødeland. For personer født i Norge er det foreldrenes\ + \ fødeland. I de tilfeller der foreldrene har ulikt fødeland,\ + \ er det morens fødeland som blir valgt. Hvis ikke personen\ + \ selv eller noen av foreldrene er utenlandsfødt, hentes landbakgrunn\ + \ fra de første utenlandsfødte en treffer på i rekkefølgen mormor,\ + \ morfar, farmor eller farfar." + nn: "For personar fødd i utlandet, er dette (med nokre få unntak)\ + \ eige fødeland. For personar fødd i Noreg er det fødelandet\ + \ til foreldra. I dei tilfella der foreldra har ulikt fødeland,\ + \ er det fødelandet til mora som blir valt. Viss ikkje personen\ + \ sjølv eller nokon av foreldra er utenlandsfødt, blir henta\ + \ landsbakgrunn frå dei første utenlandsfødte ein treffar på\ + \ i rekkjefølgja mormor, morfar, farmor eller farfar." + classification_reference: "91" + unit_types: + - "01" + - "05" + subject_fields: + - he04 + contains_special_categories_of_personal_data: false + valid_until: 2026-01-01 + external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb + comment: + en: Changes in unit types + nb: Endring i enhetstyper. + nn: Endring i enhetstyper. + related_variable_definition_uris: + - https://example.com/ + contact: + title: + en: Division for population statistics + nb: Seksjon for befolkningsstatistikk + nn: Seksjon for befolkningsstatistikk + email: s320@ssb.no required: true responses: "201": @@ -1351,6 +1473,19 @@ paths: last_updated_by: code: ano@ssb.no name: Ola Nordmann + "404": + description: Not found + content: + application/problem+json: + schema: + $ref: https://opensource.zalando.com/restful-api-guidelines/models/problem-1.0.1.yaml#/Problem + examples: + Not found: + value: + type: about:blank + status: 404 + detail: Not found + parameters: {} "400": description: Bad request. content: @@ -1372,10 +1507,8 @@ paths: title: Constraint Violation status: 400 violations: - - field: myField - message: Invalid format - - field: otherField - message: must not be empty + - field: classificationReference + message: Code incorrect is not a valid classification id "405": description: Not allowed for variable definitions with this status. content: @@ -1408,6 +1541,8 @@ paths: examples: Patch: value: wypvb3wd + Not found: + value: wypvb3wd - name: patch-id in: path description: ID of the patch to retrieve @@ -1418,6 +1553,8 @@ paths: examples: Patch: value: "1" + Not found: + value: "244" responses: "200": description: Ok @@ -1528,6 +1665,8 @@ paths: examples: Validity periods: value: wypvb3wd + Not found: + value: invalid id responses: "200": description: Ok @@ -1597,6 +1736,19 @@ paths: } ] + "404": + description: Not found + content: + application/problem+json: + schema: + $ref: https://opensource.zalando.com/restful-api-guidelines/models/problem-1.0.1.yaml#/Problem + examples: + Not found: + value: + type: about:blank + status: 404 + detail: Not found + parameters: {} security: - keycloak_token: [] post: @@ -1615,6 +1767,8 @@ paths: examples: Create validity period: value: wypvb3wd + Not found: + value: invalid id - name: active_group in: query description: The group which the user currently represents. @@ -1629,6 +1783,38 @@ paths: application/json: schema: $ref: "#/components/schemas/ValidityPeriod" + examples: + Create validity period: + value: + name: + en: Country Background + nb: Landbakgrunnen + nn: Landbakgrunnen + definition: + en: Country background is the mothers birth country. + nb: For personer født i utlandet er dette mors fødeland. + nn: For personar fødd i utlandet mors fødeland. + classification_reference: "91" + unit_types: + - "01" + - "05" + subject_fields: + - he04 + contains_special_categories_of_personal_data: false + valid_from: 2026-01-02 + external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb + comment: + en: Change in legislation triggers change of definition text. + nb: Endring i lovgiving utløser endring av definisjonstekst. + nn: Endring i lovgiving utløser endring av definisjonstekst. + related_variable_definition_uris: + - https://example.com/ + contact: + title: + en: Division for population statistics + nb: Seksjon for befolkningsstatistikk + nn: Seksjon for befolkningsstatistikk + email: s320@ssb.no required: true responses: "201": @@ -1708,6 +1894,19 @@ paths: last_updated_by: code: ano@ssb.no name: Ola Nordmann + "404": + description: Not found + content: + application/problem+json: + schema: + $ref: https://opensource.zalando.com/restful-api-guidelines/models/problem-1.0.1.yaml#/Problem + examples: + Not found: + value: + type: about:blank + status: 404 + detail: Not found + parameters: {} "400": description: Bad request. content: @@ -1729,10 +1928,8 @@ paths: title: Constraint Violation status: 400 violations: - - field: myField - message: Invalid format - - field: otherField - message: must not be empty + - field: classificationReference + message: Code incorrect is not a valid classification id "405": description: Not allowed for variable definitions with this status. content: @@ -2627,7 +2824,6 @@ components: - DRAFT - PUBLISHED_INTERNAL - PUBLISHED_EXTERNAL - - DEPRECATED securitySchemes: keycloak_token: type: http diff --git a/tests/variable_definitions/test_vardef.py b/tests/variable_definitions/test_vardef.py index df4630b..62177fb 100644 --- a/tests/variable_definitions/test_vardef.py +++ b/tests/variable_definitions/test_vardef.py @@ -1,3 +1,6 @@ +import functools +from collections.abc import Callable + import pytest from dapla_metadata._shared.config import DAPLA_GROUP_CONTEXT @@ -28,6 +31,9 @@ from tests.utils.constants import VARDEF_EXAMPLE_ACTIVE_GROUP from tests.utils.constants import VARDEF_EXAMPLE_DATE from tests.utils.constants import VARDEF_EXAMPLE_DEFINITION_ID +from tests.utils.constants import VARDEF_EXAMPLE_INVALID_ID +from tests.variable_definitions.conftest import sample_variable_definition +from tests.variable_definitions.conftest import unknown_variable_definition PATCH_ID = 2 @@ -56,12 +62,27 @@ def test_get_variable_definition(client_configuration: Configuration): assert landbak.classification_reference == "91" -def test_get_variable_definition_invalid_id(client_configuration: Configuration): +@pytest.mark.parametrize( + ("method"), + [ + functools.partial( + Vardef.get_variable_definition, + variable_definition_id=VARDEF_EXAMPLE_INVALID_ID, + ), + unknown_variable_definition().list_validity_periods, + unknown_variable_definition().list_patches, + functools.partial(sample_variable_definition().get_patch, patch_id=244), + ], +) +def test_not_found( + monkeypatch: pytest.MonkeyPatch, + client_configuration: Configuration, + method: Callable, +): + monkeypatch.setenv(DAPLA_GROUP_CONTEXT, VARDEF_EXAMPLE_ACTIVE_GROUP) VardefClient.set_config(client_configuration) with pytest.raises(VardefClientException) as e: - Vardef.get_variable_definition( - variable_definition_id="invalid id", - ) + method() assert e.value.status == NOT_FOUND_STATUS assert e.value.detail == "Not found" assert str(e.value) == "Status 404: Not found"