Skip to content

Commit

Permalink
model dumps licensed item to aoivd unset
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov committed Feb 6, 2025
1 parent a68e871 commit 8af4eb6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,22 @@ def _update_json_schema_extra(schema: JsonDict) -> None:

@classmethod
def from_domain_model(cls, item: LicensedItem) -> Self:

return cls.model_validate(
{
"licensed_item_id": item.licensed_item_id,
"display_name": item.display_name,
"licensed_resource_type": item.licensed_resource_type,
**item.model_dump(
include={
"licensed_item_id",
"display_name",
"licensed_resource_type",
"pricing_plan_id",
"created_at",
"modified_at",
},
exclude_unset=True,
),
"licensed_resource_data": {
**item.licensed_resource_data,
},
"pricing_plan_id": item.pricing_plan_id,
"created_at": item.created_at,
"modified_at": item.modified_at,
}
)

Expand Down
5 changes: 4 additions & 1 deletion packages/models-library/tests/test_licenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ def test_licensed_item_from_domain_model():
# date is required
assert got.licensed_resource_data.source.features["date"]

#
# id is required
assert (
got.licensed_resource_data.source.id
== item.licensed_resource_data["source"]["id"]
)

# checks unset fields
assert "category_icon" not in got.licensed_resource_data.model_fields_set


def test_strict_check_of_examples():
class TestLicensedItemRestGet(LicensedItemRestGet):
Expand Down

0 comments on commit 8af4eb6

Please sign in to comment.