diff --git a/noxfile.py b/noxfile.py index ef342272..9cdf95a4 100644 --- a/noxfile.py +++ b/noxfile.py @@ -73,20 +73,16 @@ def mypy(session: nox.Session) -> None: def tests(session: nox.Session) -> None: """Run the test suite.""" install_with_uv(session, groups=["test"]) - try: - session.run( - "coverage", - "run", - "--parallel", - "-m", - "pytest", - "-o", - "pythonpath=", - *session.posargs, - ) - finally: - if session.interactive: - session.notify("coverage", posargs=[]) + session.run( + "coverage", + "run", + "--parallel", + "-m", + "pytest", + "-o", + "pythonpath=", + *session.posargs, + ) @nox.session(python=python_versions[-1], default=False) diff --git a/src/dapla_metadata/variable_definitions/_generated/.openapi-generator/FILES b/src/dapla_metadata/variable_definitions/_generated/.openapi-generator/FILES index 2cf6c5d9..f14b1f2a 100644 --- a/src/dapla_metadata/variable_definitions/_generated/.openapi-generator/FILES +++ b/src/dapla_metadata/variable_definitions/_generated/.openapi-generator/FILES @@ -11,7 +11,6 @@ vardef_client/models/contact.py vardef_client/models/create_draft.py vardef_client/models/create_patch.py vardef_client/models/create_validity_period.py -vardef_client/models/get_vardok_vardef_mapping_by_id200_response.py vardef_client/models/klass_reference.py vardef_client/models/language_string_type.py vardef_client/models/list_variable_definitions200_response_inner.py diff --git a/src/dapla_metadata/variable_definitions/_generated/vardef_client/__init__.py b/src/dapla_metadata/variable_definitions/_generated/vardef_client/__init__.py index 668268cf..62d6d9e9 100644 --- a/src/dapla_metadata/variable_definitions/_generated/vardef_client/__init__.py +++ b/src/dapla_metadata/variable_definitions/_generated/vardef_client/__init__.py @@ -37,7 +37,6 @@ "CreateDraft", "CreatePatch", "CreateValidityPeriod", - "GetVardokVardefMappingById200Response", "KlassReference", "LanguageStringType", "ListVariableDefinitions200ResponseInner", @@ -80,9 +79,6 @@ from .models.create_draft import CreateDraft as CreateDraft from .models.create_patch import CreatePatch as CreatePatch from .models.create_validity_period import CreateValidityPeriod as CreateValidityPeriod -from .models.get_vardok_vardef_mapping_by_id200_response import ( - GetVardokVardefMappingById200Response as GetVardokVardefMappingById200Response, -) from .models.klass_reference import KlassReference as KlassReference from .models.language_string_type import LanguageStringType as LanguageStringType from .models.list_variable_definitions200_response_inner import ( diff --git a/src/dapla_metadata/variable_definitions/_generated/vardef_client/api/data_migration_api.py b/src/dapla_metadata/variable_definitions/_generated/vardef_client/api/data_migration_api.py index d7c61dd2..614dd27f 100644 --- a/src/dapla_metadata/variable_definitions/_generated/vardef_client/api/data_migration_api.py +++ b/src/dapla_metadata/variable_definitions/_generated/vardef_client/api/data_migration_api.py @@ -22,9 +22,7 @@ from ..api_client import RequestSerialized from ..api_response import ApiResponse from ..models.complete_view import CompleteView -from ..models.get_vardok_vardef_mapping_by_id200_response import ( - GetVardokVardefMappingById200Response, -) +from ..models.vardok_id_response import VardokIdResponse from ..models.vardok_vardef_id_pair_response import VardokVardefIdPairResponse from ..rest import RESTResponseType @@ -283,8 +281,11 @@ def _create_variable_definition_from_var_dok_serialize( ) @validate_call - def get_vardok_vardef_mapping( + def get_vardef_by_vardok_id( self, + vardok_id: Annotated[ + str, Field(strict=True, description="The ID of the definition in Vardok.") + ], _request_timeout: None | Annotated[StrictFloat, Field(gt=0)] | tuple[ @@ -294,11 +295,13 @@ def get_vardok_vardef_mapping( _content_type: StrictStr | None = None, _headers: dict[StrictStr, Any] | None = None, _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0, - ) -> list[VardokVardefIdPairResponse]: - """Get a list of all vardok and vardef id mappings + ) -> CompleteView: + """Get a variable definition by vardok id. - Get a list of all vardok and vardef id mappings + Get a variable definition by vardok id. + :param vardok_id: The ID of the definition in Vardok. (required) + :type vardok_id: str :param _request_timeout: timeout setting for this request. If one number provided, it will be total request timeout. It can also be a pair (tuple) of @@ -320,7 +323,8 @@ def get_vardok_vardef_mapping( :type _host_index: int, optional :return: Returns the result object. """ - _param = self._get_vardok_vardef_mapping_serialize( + _param = self._get_vardef_by_vardok_id_serialize( + vardok_id=vardok_id, _request_auth=_request_auth, _content_type=_content_type, _headers=_headers, @@ -328,7 +332,8 @@ def get_vardok_vardef_mapping( ) _response_types_map: dict[str, str | None] = { - "200": "List[VardokVardefIdPairResponse]", + "404": "Problem", + "200": "CompleteView", } response_data = self.api_client.call_api( *_param, _request_timeout=_request_timeout @@ -340,8 +345,11 @@ def get_vardok_vardef_mapping( ).data @validate_call - def get_vardok_vardef_mapping_with_http_info( + def get_vardef_by_vardok_id_with_http_info( self, + vardok_id: Annotated[ + str, Field(strict=True, description="The ID of the definition in Vardok.") + ], _request_timeout: None | Annotated[StrictFloat, Field(gt=0)] | tuple[ @@ -351,11 +359,13 @@ def get_vardok_vardef_mapping_with_http_info( _content_type: StrictStr | None = None, _headers: dict[StrictStr, Any] | None = None, _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0, - ) -> ApiResponse[list[VardokVardefIdPairResponse]]: - """Get a list of all vardok and vardef id mappings + ) -> ApiResponse[CompleteView]: + """Get a variable definition by vardok id. - Get a list of all vardok and vardef id mappings + Get a variable definition by vardok id. + :param vardok_id: The ID of the definition in Vardok. (required) + :type vardok_id: str :param _request_timeout: timeout setting for this request. If one number provided, it will be total request timeout. It can also be a pair (tuple) of @@ -377,7 +387,8 @@ def get_vardok_vardef_mapping_with_http_info( :type _host_index: int, optional :return: Returns the result object. """ - _param = self._get_vardok_vardef_mapping_serialize( + _param = self._get_vardef_by_vardok_id_serialize( + vardok_id=vardok_id, _request_auth=_request_auth, _content_type=_content_type, _headers=_headers, @@ -385,7 +396,8 @@ def get_vardok_vardef_mapping_with_http_info( ) _response_types_map: dict[str, str | None] = { - "200": "List[VardokVardefIdPairResponse]", + "404": "Problem", + "200": "CompleteView", } response_data = self.api_client.call_api( *_param, _request_timeout=_request_timeout @@ -397,8 +409,11 @@ def get_vardok_vardef_mapping_with_http_info( ) @validate_call - def get_vardok_vardef_mapping_without_preload_content( + def get_vardef_by_vardok_id_without_preload_content( self, + vardok_id: Annotated[ + str, Field(strict=True, description="The ID of the definition in Vardok.") + ], _request_timeout: None | Annotated[StrictFloat, Field(gt=0)] | tuple[ @@ -409,10 +424,12 @@ def get_vardok_vardef_mapping_without_preload_content( _headers: dict[StrictStr, Any] | None = None, _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0, ) -> RESTResponseType: - """Get a list of all vardok and vardef id mappings + """Get a variable definition by vardok id. - Get a list of all vardok and vardef id mappings + Get a variable definition by vardok id. + :param vardok_id: The ID of the definition in Vardok. (required) + :type vardok_id: str :param _request_timeout: timeout setting for this request. If one number provided, it will be total request timeout. It can also be a pair (tuple) of @@ -434,7 +451,8 @@ def get_vardok_vardef_mapping_without_preload_content( :type _host_index: int, optional :return: Returns the result object. """ - _param = self._get_vardok_vardef_mapping_serialize( + _param = self._get_vardef_by_vardok_id_serialize( + vardok_id=vardok_id, _request_auth=_request_auth, _content_type=_content_type, _headers=_headers, @@ -442,15 +460,17 @@ def get_vardok_vardef_mapping_without_preload_content( ) _response_types_map: dict[str, str | None] = { - "200": "List[VardokVardefIdPairResponse]", + "404": "Problem", + "200": "CompleteView", } response_data = self.api_client.call_api( *_param, _request_timeout=_request_timeout ) return response_data.response - def _get_vardok_vardef_mapping_serialize( + def _get_vardef_by_vardok_id_serialize( self, + vardok_id, _request_auth, _content_type, _headers, @@ -470,6 +490,8 @@ def _get_vardok_vardef_mapping_serialize( _body_params: bytes | None = None # process the path parameters + if vardok_id is not None: + _path_params["vardok-id"] = vardok_id # process the query parameters # process the header parameters # process the form parameters @@ -478,7 +500,7 @@ def _get_vardok_vardef_mapping_serialize( # set the HTTP header `Accept` if "Accept" not in _header_params: _header_params["Accept"] = self.api_client.select_header_accept( - ["application/json"] + ["application/problem+json", "application/json"] ) # authentication setting @@ -486,7 +508,7 @@ def _get_vardok_vardef_mapping_serialize( return self.api_client.param_serialize( method="GET", - resource_path="/vardok-migration", + resource_path="/vardok-migration/{vardok-id}", path_params=_path_params, query_params=_query_params, header_params=_header_params, @@ -500,11 +522,14 @@ def _get_vardok_vardef_mapping_serialize( ) @validate_call - def get_vardok_vardef_mapping_by_id( + def get_vardok_by_vardef_id( self, - id: Annotated[ - StrictStr, - Field(description="The ID of the definition in Vardok or Vardef."), + vardef_id: Annotated[ + str, + Field( + strict=True, + description="The ID of a variable definition which has been migrated.", + ), ], _request_timeout: None | Annotated[StrictFloat, Field(gt=0)] @@ -515,13 +540,13 @@ def get_vardok_vardef_mapping_by_id( _content_type: StrictStr | None = None, _headers: dict[StrictStr, Any] | None = None, _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0, - ) -> GetVardokVardefMappingById200Response: - """Get one variable definition by vardok id or get the vardok id by vardef id. + ) -> VardokIdResponse: + """Get a vardok id by vardef id. - Get one variable definition by vardok id or get the vardok id by vardef id. + Get a vardok id by vardef id. - :param id: The ID of the definition in Vardok or Vardef. (required) - :type id: str + :param vardef_id: The ID of a variable definition which has been migrated. (required) + :type vardef_id: str :param _request_timeout: timeout setting for this request. If one number provided, it will be total request timeout. It can also be a pair (tuple) of @@ -543,8 +568,8 @@ def get_vardok_vardef_mapping_by_id( :type _host_index: int, optional :return: Returns the result object. """ - _param = self._get_vardok_vardef_mapping_by_id_serialize( - id=id, + _param = self._get_vardok_by_vardef_id_serialize( + vardef_id=vardef_id, _request_auth=_request_auth, _content_type=_content_type, _headers=_headers, @@ -552,7 +577,8 @@ def get_vardok_vardef_mapping_by_id( ) _response_types_map: dict[str, str | None] = { - "200": "GetVardokVardefMappingById200Response", + "404": "Problem", + "200": "VardokIdResponse", } response_data = self.api_client.call_api( *_param, _request_timeout=_request_timeout @@ -564,11 +590,14 @@ def get_vardok_vardef_mapping_by_id( ).data @validate_call - def get_vardok_vardef_mapping_by_id_with_http_info( + def get_vardok_by_vardef_id_with_http_info( self, - id: Annotated[ - StrictStr, - Field(description="The ID of the definition in Vardok or Vardef."), + vardef_id: Annotated[ + str, + Field( + strict=True, + description="The ID of a variable definition which has been migrated.", + ), ], _request_timeout: None | Annotated[StrictFloat, Field(gt=0)] @@ -579,13 +608,13 @@ def get_vardok_vardef_mapping_by_id_with_http_info( _content_type: StrictStr | None = None, _headers: dict[StrictStr, Any] | None = None, _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0, - ) -> ApiResponse[GetVardokVardefMappingById200Response]: - """Get one variable definition by vardok id or get the vardok id by vardef id. + ) -> ApiResponse[VardokIdResponse]: + """Get a vardok id by vardef id. - Get one variable definition by vardok id or get the vardok id by vardef id. + Get a vardok id by vardef id. - :param id: The ID of the definition in Vardok or Vardef. (required) - :type id: str + :param vardef_id: The ID of a variable definition which has been migrated. (required) + :type vardef_id: str :param _request_timeout: timeout setting for this request. If one number provided, it will be total request timeout. It can also be a pair (tuple) of @@ -607,8 +636,8 @@ def get_vardok_vardef_mapping_by_id_with_http_info( :type _host_index: int, optional :return: Returns the result object. """ - _param = self._get_vardok_vardef_mapping_by_id_serialize( - id=id, + _param = self._get_vardok_by_vardef_id_serialize( + vardef_id=vardef_id, _request_auth=_request_auth, _content_type=_content_type, _headers=_headers, @@ -616,7 +645,8 @@ def get_vardok_vardef_mapping_by_id_with_http_info( ) _response_types_map: dict[str, str | None] = { - "200": "GetVardokVardefMappingById200Response", + "404": "Problem", + "200": "VardokIdResponse", } response_data = self.api_client.call_api( *_param, _request_timeout=_request_timeout @@ -628,11 +658,14 @@ def get_vardok_vardef_mapping_by_id_with_http_info( ) @validate_call - def get_vardok_vardef_mapping_by_id_without_preload_content( + def get_vardok_by_vardef_id_without_preload_content( self, - id: Annotated[ - StrictStr, - Field(description="The ID of the definition in Vardok or Vardef."), + vardef_id: Annotated[ + str, + Field( + strict=True, + description="The ID of a variable definition which has been migrated.", + ), ], _request_timeout: None | Annotated[StrictFloat, Field(gt=0)] @@ -644,12 +677,12 @@ def get_vardok_vardef_mapping_by_id_without_preload_content( _headers: dict[StrictStr, Any] | None = None, _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0, ) -> RESTResponseType: - """Get one variable definition by vardok id or get the vardok id by vardef id. + """Get a vardok id by vardef id. - Get one variable definition by vardok id or get the vardok id by vardef id. + Get a vardok id by vardef id. - :param id: The ID of the definition in Vardok or Vardef. (required) - :type id: str + :param vardef_id: The ID of a variable definition which has been migrated. (required) + :type vardef_id: str :param _request_timeout: timeout setting for this request. If one number provided, it will be total request timeout. It can also be a pair (tuple) of @@ -671,8 +704,8 @@ def get_vardok_vardef_mapping_by_id_without_preload_content( :type _host_index: int, optional :return: Returns the result object. """ - _param = self._get_vardok_vardef_mapping_by_id_serialize( - id=id, + _param = self._get_vardok_by_vardef_id_serialize( + vardef_id=vardef_id, _request_auth=_request_auth, _content_type=_content_type, _headers=_headers, @@ -680,16 +713,236 @@ def get_vardok_vardef_mapping_by_id_without_preload_content( ) _response_types_map: dict[str, str | None] = { - "200": "GetVardokVardefMappingById200Response", + "404": "Problem", + "200": "VardokIdResponse", } response_data = self.api_client.call_api( *_param, _request_timeout=_request_timeout ) return response_data.response - def _get_vardok_vardef_mapping_by_id_serialize( + def _get_vardok_by_vardef_id_serialize( + self, + vardef_id, + _request_auth, + _content_type, + _headers, + _host_index, + ) -> RequestSerialized: + _host = None + + _collection_formats: dict[str, str] = {} + + _path_params: dict[str, str] = {} + _query_params: list[tuple[str, str]] = [] + _header_params: dict[str, str | None] = _headers or {} + _form_params: list[tuple[str, str]] = [] + _files: dict[ + str, str | bytes | list[str] | list[bytes] | list[tuple[str, bytes]] + ] = {} + _body_params: bytes | None = None + + # process the path parameters + if vardef_id is not None: + _path_params["vardef-id"] = vardef_id + # process the query parameters + # process the header parameters + # process the form parameters + # process the body parameter + + # set the HTTP header `Accept` + if "Accept" not in _header_params: + _header_params["Accept"] = self.api_client.select_header_accept( + ["application/problem+json", "application/json"] + ) + + # authentication setting + _auth_settings: list[str] = ["labid_token"] + + return self.api_client.param_serialize( + method="GET", + resource_path="/vardok-migration/{vardef-id}", + path_params=_path_params, + query_params=_query_params, + header_params=_header_params, + body=_body_params, + post_params=_form_params, + files=_files, + auth_settings=_auth_settings, + collection_formats=_collection_formats, + _host=_host, + _request_auth=_request_auth, + ) + + @validate_call + def list_vardok_vardef_mappings( + self, + _request_timeout: None + | Annotated[StrictFloat, Field(gt=0)] + | tuple[ + Annotated[StrictFloat, Field(gt=0)], Annotated[StrictFloat, Field(gt=0)] + ] = None, + _request_auth: dict[StrictStr, Any] | None = None, + _content_type: StrictStr | None = None, + _headers: dict[StrictStr, Any] | None = None, + _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0, + ) -> list[VardokVardefIdPairResponse]: + """Get a list of all vardok and vardef id mappings + + Get a list of all vardok and vardef id mappings + + :param _request_timeout: timeout setting for this request. If one + number provided, it will be total request + timeout. It can also be a pair (tuple) of + (connection, read) timeouts. + :type _request_timeout: int, tuple(int, int), optional + :param _request_auth: set to override the auth_settings for an a single + request; this effectively ignores the + authentication in the spec for a single request. + :type _request_auth: dict, optional + :param _content_type: force content-type for the request. + :type _content_type: str, Optional + :param _headers: set to override the headers for a single + request; this effectively ignores the headers + in the spec for a single request. + :type _headers: dict, optional + :param _host_index: set to override the host_index for a single + request; this effectively ignores the host_index + in the spec for a single request. + :type _host_index: int, optional + :return: Returns the result object. + """ + _param = self._list_vardok_vardef_mappings_serialize( + _request_auth=_request_auth, + _content_type=_content_type, + _headers=_headers, + _host_index=_host_index, + ) + + _response_types_map: dict[str, str | None] = { + "200": "List[VardokVardefIdPairResponse]", + } + response_data = self.api_client.call_api( + *_param, _request_timeout=_request_timeout + ) + response_data.read() + return self.api_client.response_deserialize( + response_data=response_data, + response_types_map=_response_types_map, + ).data + + @validate_call + def list_vardok_vardef_mappings_with_http_info( + self, + _request_timeout: None + | Annotated[StrictFloat, Field(gt=0)] + | tuple[ + Annotated[StrictFloat, Field(gt=0)], Annotated[StrictFloat, Field(gt=0)] + ] = None, + _request_auth: dict[StrictStr, Any] | None = None, + _content_type: StrictStr | None = None, + _headers: dict[StrictStr, Any] | None = None, + _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0, + ) -> ApiResponse[list[VardokVardefIdPairResponse]]: + """Get a list of all vardok and vardef id mappings + + Get a list of all vardok and vardef id mappings + + :param _request_timeout: timeout setting for this request. If one + number provided, it will be total request + timeout. It can also be a pair (tuple) of + (connection, read) timeouts. + :type _request_timeout: int, tuple(int, int), optional + :param _request_auth: set to override the auth_settings for an a single + request; this effectively ignores the + authentication in the spec for a single request. + :type _request_auth: dict, optional + :param _content_type: force content-type for the request. + :type _content_type: str, Optional + :param _headers: set to override the headers for a single + request; this effectively ignores the headers + in the spec for a single request. + :type _headers: dict, optional + :param _host_index: set to override the host_index for a single + request; this effectively ignores the host_index + in the spec for a single request. + :type _host_index: int, optional + :return: Returns the result object. + """ + _param = self._list_vardok_vardef_mappings_serialize( + _request_auth=_request_auth, + _content_type=_content_type, + _headers=_headers, + _host_index=_host_index, + ) + + _response_types_map: dict[str, str | None] = { + "200": "List[VardokVardefIdPairResponse]", + } + response_data = self.api_client.call_api( + *_param, _request_timeout=_request_timeout + ) + response_data.read() + return self.api_client.response_deserialize( + response_data=response_data, + response_types_map=_response_types_map, + ) + + @validate_call + def list_vardok_vardef_mappings_without_preload_content( + self, + _request_timeout: None + | Annotated[StrictFloat, Field(gt=0)] + | tuple[ + Annotated[StrictFloat, Field(gt=0)], Annotated[StrictFloat, Field(gt=0)] + ] = None, + _request_auth: dict[StrictStr, Any] | None = None, + _content_type: StrictStr | None = None, + _headers: dict[StrictStr, Any] | None = None, + _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0, + ) -> RESTResponseType: + """Get a list of all vardok and vardef id mappings + + Get a list of all vardok and vardef id mappings + + :param _request_timeout: timeout setting for this request. If one + number provided, it will be total request + timeout. It can also be a pair (tuple) of + (connection, read) timeouts. + :type _request_timeout: int, tuple(int, int), optional + :param _request_auth: set to override the auth_settings for an a single + request; this effectively ignores the + authentication in the spec for a single request. + :type _request_auth: dict, optional + :param _content_type: force content-type for the request. + :type _content_type: str, Optional + :param _headers: set to override the headers for a single + request; this effectively ignores the headers + in the spec for a single request. + :type _headers: dict, optional + :param _host_index: set to override the host_index for a single + request; this effectively ignores the host_index + in the spec for a single request. + :type _host_index: int, optional + :return: Returns the result object. + """ + _param = self._list_vardok_vardef_mappings_serialize( + _request_auth=_request_auth, + _content_type=_content_type, + _headers=_headers, + _host_index=_host_index, + ) + + _response_types_map: dict[str, str | None] = { + "200": "List[VardokVardefIdPairResponse]", + } + response_data = self.api_client.call_api( + *_param, _request_timeout=_request_timeout + ) + return response_data.response + + def _list_vardok_vardef_mappings_serialize( self, - id, _request_auth, _content_type, _headers, @@ -709,8 +962,6 @@ def _get_vardok_vardef_mapping_by_id_serialize( _body_params: bytes | None = None # process the path parameters - if id is not None: - _path_params["id"] = id # process the query parameters # process the header parameters # process the form parameters @@ -727,7 +978,7 @@ def _get_vardok_vardef_mapping_by_id_serialize( return self.api_client.param_serialize( method="GET", - resource_path="/vardok-migration/{id}", + resource_path="/vardok-migration", path_params=_path_params, query_params=_query_params, header_params=_header_params, diff --git a/src/dapla_metadata/variable_definitions/_generated/vardef_client/models/__init__.py b/src/dapla_metadata/variable_definitions/_generated/vardef_client/models/__init__.py index 39174228..105ed4c8 100644 --- a/src/dapla_metadata/variable_definitions/_generated/vardef_client/models/__init__.py +++ b/src/dapla_metadata/variable_definitions/_generated/vardef_client/models/__init__.py @@ -19,9 +19,6 @@ from ..models.create_draft import CreateDraft from ..models.create_patch import CreatePatch from ..models.create_validity_period import CreateValidityPeriod -from ..models.get_vardok_vardef_mapping_by_id200_response import ( - GetVardokVardefMappingById200Response, -) from ..models.klass_reference import KlassReference from ..models.language_string_type import LanguageStringType from ..models.list_variable_definitions200_response_inner import ( diff --git a/src/dapla_metadata/variable_definitions/_generated/vardef_client/models/get_vardok_vardef_mapping_by_id200_response.py b/src/dapla_metadata/variable_definitions/_generated/vardef_client/models/get_vardok_vardef_mapping_by_id200_response.py deleted file mode 100644 index cb30d626..00000000 --- a/src/dapla_metadata/variable_definitions/_generated/vardef_client/models/get_vardok_vardef_mapping_by_id200_response.py +++ /dev/null @@ -1,158 +0,0 @@ -"""Internal Variable Definitions Administration API - -## Introduction Variable Definitions are centralized definitions of concrete variables which are typically present in multiple datasets. Variable Definitions support standardization of data and metadata and facilitate sharing and joining of data by clarifying when variables have an identical definition. ## Maintenance of Variable Definitions This API allows for creation, maintenance and access of Variable Definitions. ### Ownership Creation and maintenance of variables may only be performed by Statistics Norway employees representing a specific Dapla team, who are defined as the owners of a given Variable Definition. The team an owner represents must be specified when making a request through the `active_group` query parameter. All maintenance is to be performed by the owners, with no intervention from administrators. ### Status All Variable Definitions have an associated status. The possible values for status are `DRAFT`, `PUBLISHED_INTERNAL` and `PUBLISHED_EXTERNAL`. #### Draft When a Variable Definition is created it is assigned the status `DRAFT`. Under this status the Variable Definition is: - Only visible to Statistics Norway employees. - Mutable (it may be changed directly without need for versioning). - Not suitable to refer to from other systems. This status may be changed to `PUBLISHED_INTERNAL` or `PUBLISHED_EXTERNAL` with a direct update. #### Published Internal Under this status the Variable Definition is: - Only visible to Statistics Norway employees. - Immutable (all changes are versioned). - Suitable to refer to in internal systems for statistics production. - Not suitable to refer to for external use (for example in Statistikkbanken). This status may be changed to `PUBLISHED_EXTERNAL` by creating a Patch version. #### Published External Under this status the Variable Definition is: - Visible to the general public. - Immutable (all changes are versioned). - Suitable to refer to from any system. This status may not be changed as it would break immutability. If a Variable Definition is no longer relevant then its period of validity should be ended by specifying a `valid_until` date in a Patch version. ### Immutability Variable Definitions are immutable. This means that any changes must be performed in a strict versioning system. Consumers can avoid being exposed to breaking changes by specifying a `date_of_validity` when they request a Variable Definition. #### Patches Patches are for changes which do not affect the fundamental meaning of the Variable Definition. #### Validity Periods Validity Periods are versions with a period defined by a `valid_from` date and optionally a `valid_until` date. If the fundamental meaning of a Variable Definition is to be changed, it should be done by creating a new Validity Period. - -The version of the OpenAPI document: 0.1 -Contact: metadata@ssb.no -Generated by OpenAPI Generator (https://openapi-generator.tech) - -Do not edit the class manually. -""" - -from __future__ import annotations - -import json -import pprint -from typing import Any - -from pydantic import BaseModel -from pydantic import ConfigDict -from pydantic import ValidationError -from pydantic import field_validator -from typing_extensions import Self - -from ..models.complete_view import CompleteView -from ..models.vardok_id_response import VardokIdResponse - -GETVARDOKVARDEFMAPPINGBYID200RESPONSE_ONE_OF_SCHEMAS = [ - "CompleteView", - "VardokIdResponse", -] - - -class GetVardokVardefMappingById200Response(BaseModel): - """GetVardokVardefMappingById200Response""" - - # data type: CompleteView - oneof_schema_1_validator: CompleteView | None = None - # data type: VardokIdResponse - oneof_schema_2_validator: VardokIdResponse | None = None - actual_instance: CompleteView | VardokIdResponse | None = None - one_of_schemas: set[str] = {"CompleteView", "VardokIdResponse"} - - model_config = ConfigDict( - validate_assignment=True, - protected_namespaces=(), - ) - - def __init__(self, *args, **kwargs) -> None: - if args: - if len(args) > 1: - raise ValueError( - "If a position argument is used, only 1 is allowed to set `actual_instance`" - ) - if kwargs: - raise ValueError( - "If a position argument is used, keyword arguments cannot be used." - ) - super().__init__(actual_instance=args[0]) - else: - super().__init__(**kwargs) - - @field_validator("actual_instance") - def actual_instance_must_validate_oneof(cls, v): - instance = GetVardokVardefMappingById200Response.model_construct() - error_messages = [] - match = 0 - # validate data type: CompleteView - if not isinstance(v, CompleteView): - error_messages.append( - f"Error! Input type `{type(v)}` is not `CompleteView`" - ) - else: - match += 1 - # validate data type: VardokIdResponse - if not isinstance(v, VardokIdResponse): - error_messages.append( - f"Error! Input type `{type(v)}` is not `VardokIdResponse`" - ) - else: - match += 1 - if match > 1: - # more than 1 match - raise ValueError( - "Multiple matches found when setting `actual_instance` in GetVardokVardefMappingById200Response with oneOf schemas: CompleteView, VardokIdResponse. Details: " - + ", ".join(error_messages) - ) - if match == 0: - # no match - raise ValueError( - "No match found when setting `actual_instance` in GetVardokVardefMappingById200Response with oneOf schemas: CompleteView, VardokIdResponse. Details: " - + ", ".join(error_messages) - ) - return v - - @classmethod - def from_dict(cls, obj: str | dict[str, Any]) -> Self: - return cls.from_json(json.dumps(obj)) - - @classmethod - def from_json(cls, json_str: str) -> Self: - """Returns the object represented by the json string""" - instance = cls.model_construct() - error_messages = [] - match = 0 - - # deserialize data into CompleteView - try: - instance.actual_instance = CompleteView.from_json(json_str) - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # deserialize data into VardokIdResponse - try: - instance.actual_instance = VardokIdResponse.from_json(json_str) - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - - if match > 1: - # more than 1 match - raise ValueError( - "Multiple matches found when deserializing the JSON string into GetVardokVardefMappingById200Response with oneOf schemas: CompleteView, VardokIdResponse. Details: " - + ", ".join(error_messages) - ) - if match == 0: - # no match - raise ValueError( - "No match found when deserializing the JSON string into GetVardokVardefMappingById200Response with oneOf schemas: CompleteView, VardokIdResponse. Details: " - + ", ".join(error_messages) - ) - return instance - - def to_json(self) -> str: - """Returns the JSON representation of the actual instance""" - if self.actual_instance is None: - return "null" - - if hasattr(self.actual_instance, "to_json") and callable( - self.actual_instance.to_json - ): - return self.actual_instance.to_json() - return json.dumps(self.actual_instance) - - def to_dict(self) -> dict[str, Any] | CompleteView | VardokIdResponse | None: - """Returns the dict representation of the actual instance""" - if self.actual_instance is None: - return None - - if hasattr(self.actual_instance, "to_dict") and callable( - self.actual_instance.to_dict - ): - return self.actual_instance.to_dict() - # primitive type - return self.actual_instance - - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) diff --git a/src/dapla_metadata/variable_definitions/vardef.py b/src/dapla_metadata/variable_definitions/vardef.py index 756d3be4..2b21764e 100644 --- a/src/dapla_metadata/variable_definitions/vardef.py +++ b/src/dapla_metadata/variable_definitions/vardef.py @@ -1,7 +1,9 @@ import logging +import re from datetime import date from os import PathLike from pathlib import Path +from typing import TYPE_CHECKING from typing import cast from dapla_metadata.variable_definitions._generated.vardef_client.api.data_migration_api import ( @@ -13,18 +15,12 @@ from dapla_metadata.variable_definitions._generated.vardef_client.api.variable_definitions_api import ( VariableDefinitionsApi, ) -from dapla_metadata.variable_definitions._generated.vardef_client.models.complete_view import ( - CompleteView, -) from dapla_metadata.variable_definitions._generated.vardef_client.models.create_draft import ( CreateDraft, ) from dapla_metadata.variable_definitions._generated.vardef_client.models.supported_languages import ( SupportedLanguages, ) -from dapla_metadata.variable_definitions._generated.vardef_client.models.vardok_id_response import ( - VardokIdResponse, -) from dapla_metadata.variable_definitions._utils._client import VardefClient from dapla_metadata.variable_definitions._utils.sort_variable_definitions import ( MAP_SORT_OPTIONS, @@ -51,6 +47,11 @@ from dapla_metadata.variable_definitions.vardok_vardef_id_pair import VardokVardefIdPair from dapla_metadata.variable_definitions.variable_definition import VariableDefinition +if TYPE_CHECKING: + from dapla_metadata.variable_definitions._generated.vardef_client.models.complete_view import ( + CompleteView, + ) + logger = logging.getLogger(__name__) @@ -201,7 +202,7 @@ def list_vardok_vardef_mapping(cls) -> list[VardokVardefIdPair]: VardokVardefIdPair.from_model(definition) for definition in DataMigrationApi( VardefClient.get_client(), - ).get_vardok_vardef_mapping() + ).list_vardok_vardef_mappings() ] @classmethod @@ -221,17 +222,15 @@ def get_variable_definition_by_vardok_id( Raises: TypeError: If the incorrect type is returned. """ - raw_response = DataMigrationApi( - VardefClient.get_client() - ).get_vardok_vardef_mapping_by_id( - vardok_id, + if not re.match(r"\d{1,5}", vardok_id): + msg = f"Value {vardok_id} does not match the required format." + raise ValueError(msg) + return VariableDefinition.from_model( + DataMigrationApi(VardefClient.get_client()).get_vardef_by_vardok_id( + vardok_id, + ) ) - if isinstance(raw_response.actual_instance, CompleteView): - return VariableDefinition.from_model(raw_response.actual_instance) - msg = "Unexpected response type" - raise TypeError(msg) - @classmethod @vardef_exception_handler def get_vardok_id_by_short_name( @@ -248,17 +247,12 @@ def get_vardok_id_by_short_name( """ variable_definition = cls.get_variable_definition_by_shortname(short_name) - raw_response = DataMigrationApi( - VardefClient.get_client() - ).get_vardok_vardef_mapping_by_id( - variable_definition.id, + return VardokId.from_model( + DataMigrationApi(VardefClient.get_client()).get_vardok_by_vardef_id( + variable_definition.id, + ) ) - if isinstance(raw_response.actual_instance, VardokIdResponse): - return VardokId.from_model(raw_response.actual_instance) - msg = "Unexpected response type" - raise TypeError(msg) - @classmethod @vardef_exception_handler def list_variable_definitions( diff --git a/tests/variable_definitions/resources/openapi/variable-definitions-internal.yml b/tests/variable_definitions/resources/openapi/variable-definitions-internal.yml index 82aa70f1..346f46b3 100644 --- a/tests/variable_definitions/resources/openapi/variable-definitions-internal.yml +++ b/tests/variable_definitions/resources/openapi/variable-definitions-internal.yml @@ -87,7 +87,7 @@ paths: - Data Migration summary: Get a list of all vardok and vardef id mappings description: Get a list of all vardok and vardef id mappings - operationId: getVardokVardefMapping + operationId: listVardokVardefMappings responses: "200": description: OK response @@ -102,40 +102,98 @@ paths: value: |- [ { - "vardok_id": "25", - "vardef_id": "A1699WWE" + "vardok_id": "1607", + "vardef_id": "wypvb3wd" } ] security: - labid_token: [] - /vardok-migration/{id}: + /vardok-migration/{vardef-id}: get: tags: - Data Migration - summary: Get one variable definition by vardok id or get the vardok id by vardef - id. - description: Get one variable definition by vardok id or get the vardok id by - vardef id. - operationId: getVardokVardefMappingById + summary: Get a vardok id by vardef id. + description: Get a vardok id by vardef id. + operationId: getVardokByVardefId parameters: - - name: id + - name: vardef-id in: path - description: The ID of the definition in Vardok or Vardef. + description: The ID of a variable definition which has been migrated. required: true schema: + pattern: "[-a-zA-Z0-9_]{8}" + type: string + examples: + Vardef id: + value: wypvb3wd + Not found: + value: Xy9_7-Az + responses: + "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: {} + "200": + description: OK response + content: + application/json: + schema: + $ref: "#/components/schemas/VardokIdResponse" + examples: + Vardef id: + value: + vardok_id: "1607" + security: + - labid_token: [] + /vardok-migration/{vardok-id}: + get: + tags: + - Data Migration + summary: Get a variable definition by vardok id. + description: Get a variable definition by vardok id. + operationId: getVardefByVardokId + parameters: + - name: vardok-id + in: path + description: The ID of the definition in Vardok. + required: true + schema: + pattern: "\\d{1,5}" type: string examples: Vardok id: value: "1607" + Not found: + value: "9999" responses: + "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: {} "200": description: OK response content: application/json: schema: - oneOf: - - $ref: "#/components/schemas/CompleteView" - - $ref: "#/components/schemas/VardokIdResponse" + $ref: "#/components/schemas/CompleteView" examples: Vardok id: value: @@ -178,6 +236,7 @@ paths: - he04 contains_special_categories_of_personal_data: true variable_status: DRAFT + measurement_type: "01" valid_from: 2003-01-01 external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb comment: @@ -203,12 +262,8 @@ paths: created_by: ano@ssb.no last_updated_at: 2024-06-11T08:15:19.038Z last_updated_by: ano@ssb.no - Vardef id: - value: - vardok_id: "25" security: - labid_token: [] - /vardok-migration/{vardok-id}: post: tags: - Data Migration @@ -274,6 +329,7 @@ paths: - he04 contains_special_categories_of_personal_data: true variable_status: DRAFT + measurement_type: "01" valid_from: 2003-01-01 external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb comment: @@ -343,12 +399,6 @@ paths: examples: Date not specified: value: nb - Specific date: - value: nb - Rendered: - value: nb - Not found: - value: nb - name: date_of_validity in: query description: List only variable definitions which are valid on this date. @@ -420,7 +470,7 @@ paths: "subject_fields": ["he04"], "contains_special_categories_of_personal_data": true, "variable_status": "DRAFT", - "measurement_type": null, + "measurement_type": "01", "valid_from": "2003-01-01", "valid_until": null, "external_reference_uri": "https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb", @@ -473,7 +523,7 @@ paths: "subject_fields": ["he04"], "contains_special_categories_of_personal_data": true, "variable_status": "DRAFT", - "measurement_type": null, + "measurement_type": "01", "valid_from": "2003-01-01", "valid_until": null, "external_reference_uri": "https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb", @@ -530,7 +580,11 @@ paths: ], "contains_special_categories_of_personal_data": true, "variable_status": "PUBLISHED_INTERNAL", - "measurement_type": null, + "measurement_type": { + "reference_uri": "https://www.ssb.no/klass/klassifikasjoner/303", + "code": "01", + "title": "Andel" + }, "valid_from": "2003-01-01", "valid_until": null, "external_reference_uri": "https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb", @@ -605,6 +659,7 @@ paths: subject_fields: - he04 contains_special_categories_of_personal_data: true + measurement_type: "01" valid_from: 2003-01-01 external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb comment: @@ -671,6 +726,7 @@ paths: - he04 contains_special_categories_of_personal_data: true variable_status: DRAFT + measurement_type: "01" valid_from: 2003-01-01 external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb comment: @@ -752,12 +808,6 @@ paths: examples: Date not specified: value: nb - Specific date: - value: nb - Rendered: - value: nb - Not found: - value: nb - name: variable-definition-id in: path description: Unique identifier for the variable definition. @@ -851,6 +901,7 @@ paths: - he04 contains_special_categories_of_personal_data: true variable_status: DRAFT + measurement_type: "01" valid_from: 2003-01-01 external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb comment: @@ -917,6 +968,7 @@ paths: - he04 contains_special_categories_of_personal_data: true variable_status: DRAFT + measurement_type: "01" valid_from: 2003-01-01 external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb comment: @@ -965,6 +1017,10 @@ paths: title: Innvandrere contains_special_categories_of_personal_data: true variable_status: PUBLISHED_INTERNAL + measurement_type: + reference_uri: https://www.ssb.no/klass/klassifikasjoner/303 + code: "01" + title: Andel valid_from: 2003-01-01 external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb comment: Fra og med 1.1.2003 ble definisjon endret til også å @@ -1130,6 +1186,7 @@ paths: - he04 contains_special_categories_of_personal_data: true variable_status: DRAFT + measurement_type: "01" valid_from: 2003-01-01 external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb comment: @@ -1269,7 +1326,7 @@ paths: "subject_fields": ["he04"], "contains_special_categories_of_personal_data": true, "variable_status": "DRAFT", - "measurement_type": null, + "measurement_type": "01", "valid_from": "2003-01-01", "valid_until": null, "external_reference_uri": "https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb", @@ -1385,6 +1442,7 @@ paths: subject_fields: - he04 contains_special_categories_of_personal_data: false + measurement_type: "01" valid_until: 2026-01-01 external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb comment: @@ -1448,6 +1506,7 @@ paths: - he04 contains_special_categories_of_personal_data: true variable_status: PUBLISHED_INTERNAL + measurement_type: "01" valid_from: 2003-01-01 external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb comment: @@ -1604,6 +1663,7 @@ paths: - he04 contains_special_categories_of_personal_data: true variable_status: DRAFT + measurement_type: "01" valid_from: 2003-01-01 external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb comment: @@ -1695,7 +1755,7 @@ paths: "subject_fields": ["he04"], "contains_special_categories_of_personal_data": true, "variable_status": "DRAFT", - "measurement_type": null, + "measurement_type": "01", "valid_from": "2003-01-01", "valid_until": null, "external_reference_uri": "https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb", @@ -1782,6 +1842,7 @@ paths: subject_fields: - he04 contains_special_categories_of_personal_data: false + measurement_type: "01" valid_from: 2026-01-02 external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb comment: @@ -1845,6 +1906,7 @@ paths: - he04 contains_special_categories_of_personal_data: true variable_status: DRAFT + measurement_type: "01" valid_from: 2003-01-01 external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb comment: @@ -2167,7 +2229,7 @@ components: subject_fields: - he04 contains_special_categories_of_personal_data: true - measurement_type: null + measurement_type: "01" valid_from: 2003-01-01 external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb comment: @@ -2300,7 +2362,7 @@ components: subject_fields: - he04 contains_special_categories_of_personal_data: false - measurement_type: null + measurement_type: "01" valid_until: 2026-01-01 external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb comment: @@ -2406,7 +2468,7 @@ components: subject_fields: - he04 contains_special_categories_of_personal_data: false - measurement_type: null + measurement_type: "01" valid_from: 2026-01-02 external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb comment: @@ -2625,7 +2687,10 @@ components: title: Innvandrere contains_special_categories_of_personal_data: true variable_status: PUBLISHED_INTERNAL - measurement_type: null + measurement_type: + reference_uri: https://www.ssb.no/klass/klassifikasjoner/303 + code: "01" + title: Andel valid_from: 2003-01-01 valid_until: null external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb @@ -2781,7 +2846,7 @@ components: subject_fields: - he04 contains_special_categories_of_personal_data: true - measurement_type: null + measurement_type: "01" valid_from: 2003-01-01 external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb comment: diff --git a/tests/variable_definitions/test_vardef.py b/tests/variable_definitions/test_vardef.py index f8b218fe..28611f5e 100644 --- a/tests/variable_definitions/test_vardef.py +++ b/tests/variable_definitions/test_vardef.py @@ -1,5 +1,6 @@ import functools from collections.abc import Callable +from dataclasses import dataclass from http import HTTPStatus from pathlib import Path from types import SimpleNamespace @@ -22,12 +23,6 @@ from dapla_metadata.variable_definitions._generated.vardef_client.models.create_draft import ( CreateDraft, ) -from dapla_metadata.variable_definitions._generated.vardef_client.models.get_vardok_vardef_mapping_by_id200_response import ( - GetVardokVardefMappingById200Response, -) -from dapla_metadata.variable_definitions._generated.vardef_client.models.vardok_id_response import ( - VardokIdResponse, -) from dapla_metadata.variable_definitions._generated.vardef_client.models.vardok_vardef_id_pair_response import ( VardokVardefIdPairResponse, ) @@ -357,63 +352,60 @@ def test_list_vardok_vardef_mappings( vardok_vardef_mapping, VardokVardefIdPairResponse, ) - assert vardok_vardef_mapping.vardef_id == "A1699WWE" - assert vardok_vardef_mapping.vardok_id == "25" + assert vardok_vardef_mapping.vardef_id == "wypvb3wd" + assert vardok_vardef_mapping.vardok_id == "1607" -def test_empty_list_vardok_vardef_mappings( +def test_get_variable_by_vardok_id( client_configuration: Configuration, ): VardefClient.set_config(client_configuration) - with patch( - "dapla_metadata.variable_definitions._generated.vardef_client.api.data_migration_api.DataMigrationApi.get_vardok_vardef_mapping", - return_value=[], - ): - result = Vardef.list_vardok_vardef_mapping() - assert len(result) == 0 + vardok_vardef_mapping = Vardef.get_variable_definition_by_vardok_id("1607") + assert isinstance(vardok_vardef_mapping, VariableDefinition) + assert vardok_vardef_mapping.short_name == "landbak" -def test_get_variable_by_vardok_id( + +def test_get_variable_by_unknown_vardok_id( client_configuration: Configuration, ): VardefClient.set_config(client_configuration) - vardok_vardef_mapping = Vardef.get_variable_definition_by_vardok_id("1607") - assert isinstance(vardok_vardef_mapping, VariableDefinition) - assert vardok_vardef_mapping.short_name == "landbak" + with pytest.raises(VardefClientError) as e: + Vardef.get_variable_definition_by_vardok_id("9999") + assert e.value.status == HTTPStatus.NOT_FOUND def test_get_variable_by_vardok_id_but_supplying_vardef_id( client_configuration: Configuration, ): VardefClient.set_config(client_configuration) - - response_data = VardokIdResponse(vardok_id="wypvb3wd") - wrapped_response = GetVardokVardefMappingById200Response( - actual_instance=response_data - ) with ( - patch( - "dapla_metadata.variable_definitions._generated.vardef_client.api.data_migration_api.DataMigrationApi.get_vardok_vardef_mapping_by_id", - return_value=wrapped_response, - ), - pytest.raises(TypeError), + pytest.raises(ValueError, match="does not match the required format"), ): Vardef.get_variable_definition_by_vardok_id("wypvb3wd") def test_get_vardok_id_by_short_name(client_configuration: Configuration): VardefClient.set_config(client_configuration) + vardok_vardef_mapping = Vardef.get_vardok_id_by_short_name("landbak") + assert isinstance(vardok_vardef_mapping, VardokId) + assert vardok_vardef_mapping.vardok_id == "1607" - response_data = VardokIdResponse(vardok_id="1607") - wrapped_response = GetVardokVardefMappingById200Response( - actual_instance=response_data - ) - with patch( - "dapla_metadata.variable_definitions._generated.vardef_client.api.data_migration_api.DataMigrationApi.get_vardok_vardef_mapping_by_id", - return_value=wrapped_response, - ): - vardok_vardef_mapping = Vardef.get_vardok_id_by_short_name("landbak") - assert isinstance(vardok_vardef_mapping, VardokId) - assert vardok_vardef_mapping.vardok_id == "1607" +def test_get_vardok_id_by_unknown_short_name(client_configuration: Configuration): + VardefClient.set_config(client_configuration) + + @dataclass + class IdWrapper: + id: str + + with ( + patch( + "dapla_metadata.variable_definitions.vardef.Vardef.get_variable_definition_by_shortname", + return_value=IdWrapper(id="Xy9_7-Az"), + ), + pytest.raises(VardefClientError) as e, + ): + Vardef.get_vardok_id_by_short_name("unknown") + assert e.value.status == HTTPStatus.NOT_FOUND