Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/mx-1533 prepare graph identity provider #67

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- cruft template link
- workflow that syncs main branch to openCoDE
- constant for MEX_PRIMARY_SOURCE_IDENTIFIER

### Changes

Expand All @@ -22,6 +23,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- ExtractedData raises proper ValidationError when parsing wrong base type

### Security


Expand Down
8 changes: 5 additions & 3 deletions mex/common/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
MergedDistribution,
)
from mex.common.models.extracted_data import (
MEX_PRIMARY_SOURCE_IDENTIFIER,
MEX_PRIMARY_SOURCE_IDENTIFIER_IN_PRIMARY_SOURCE,
MEX_PRIMARY_SOURCE_STABLE_TARGET_ID,
BaseExtractedData,
Expand Down Expand Up @@ -62,26 +63,26 @@
"BaseResource",
"BaseVariable",
"BaseVariableGroup",
"EXTRACTED_MODEL_CLASSES_BY_NAME",
"EXTRACTED_MODEL_CLASSES",
"ExtractedAccessPlatform",
"ExtractedActivity",
"ExtractedContactPoint",
"ExtractedData",
"ExtractedDistribution",
"EXTRACTED_MODEL_CLASSES",
"EXTRACTED_MODEL_CLASSES_BY_NAME",
"ExtractedOrganization",
"ExtractedOrganizationalUnit",
"ExtractedPerson",
"ExtractedPrimarySource",
"ExtractedResource",
"ExtractedVariable",
"ExtractedVariableGroup",
"MERGED_MODEL_CLASSES_BY_NAME",
"MergedAccessPlatform",
"MergedActivity",
"MergedContactPoint",
"MergedDistribution",
"MergedItem",
"MERGED_MODEL_CLASSES_BY_NAME",
"MergedOrganization",
"MergedOrganizationalUnit",
"MergedPerson",
Expand All @@ -90,6 +91,7 @@
"MergedVariable",
"MergedVariableGroup",
"MEX_PRIMARY_SOURCE_IDENTIFIER_IN_PRIMARY_SOURCE",
"MEX_PRIMARY_SOURCE_IDENTIFIER",
"MEX_PRIMARY_SOURCE_STABLE_TARGET_ID",
"MExModel",
)
Expand Down
13 changes: 7 additions & 6 deletions mex/common/models/extracted_data.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from typing import Annotated, Any

from pydantic import Field, model_validator
from pydantic import Field, model_validator, validate_call

from mex.common.models.base import MExModel
from mex.common.types import PrimarySourceID
from mex.common.types import Identifier, PrimarySourceID

MEX_PRIMARY_SOURCE_STABLE_TARGET_ID = PrimarySourceID("00000000000000")
MEX_PRIMARY_SOURCE_IDENTIFIER = Identifier("00000000000000")
MEX_PRIMARY_SOURCE_IDENTIFIER_IN_PRIMARY_SOURCE = "mex"
MEX_PRIMARY_SOURCE_STABLE_TARGET_ID = PrimarySourceID("00000000000000")


class BaseExtractedData(MExModel):
Expand Down Expand Up @@ -65,11 +66,11 @@ class ExtractedData(BaseExtractedData):
to automatically set identifiers for provenance. See below, for description.
"""

# TODO make stable_target_id and identifier computed fields (MX-1435)
@model_validator(mode="before")
@classmethod
def set_identifiers( # noqa: C901 # TODO in https://jira.rki.local/browse/MX-1435
cls, values: dict[str, Any]
) -> dict[str, Any]:
@validate_call
def set_identifiers(cls, values: dict[str, Any]) -> dict[str, Any]: # noqa: C901
"""Ensure identifier and provenance attributes are set for this instance.

All extracted data classes have four important identifiers that are defined
Expand Down
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "mex-common"
version = "0.19.0"
version = "0.19.1"
description = "Common library for MEx python projects."
authors = ["RKI MEx Team <[email protected]>"]
readme = "README.md"
Expand All @@ -16,7 +16,7 @@ langdetect = "^1.0.9"
ldap3 = "^2.9.1"
numpy = "^1.26.2"
pandas = "^2.1.4"
pydantic = "^2.5.2"
pydantic = "^2.5.3"
pydantic-settings = "^2.1.0"
requests = "^2.31.0"

Expand Down
5 changes: 5 additions & 0 deletions tests/models/test_extracted_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class ExtractedThing(BaseThing, ExtractedData):
"""Extracted version of a dummy thing model."""


def test_extracted_data_requires_dict_for_construction() -> None:
with pytest.raises(ValidationError, match="Input should be a valid dictionary"):
ExtractedThing.model_validate(["this is a list"])


def test_extracted_data_requires_identifier_in_primary_source() -> None:
with pytest.raises(ValidationError, match="identifierInPrimarySource"):
ExtractedThing(
Expand Down