Skip to content

Commit 8af4eb6

Browse files
committed
model dumps licensed item to aoivd unset
1 parent a68e871 commit 8af4eb6

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

packages/models-library/src/models_library/api_schemas_webserver/licensed_items.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,22 @@ def _update_json_schema_extra(schema: JsonDict) -> None:
109109

110110
@classmethod
111111
def from_domain_model(cls, item: LicensedItem) -> Self:
112-
113112
return cls.model_validate(
114113
{
115-
"licensed_item_id": item.licensed_item_id,
116-
"display_name": item.display_name,
117-
"licensed_resource_type": item.licensed_resource_type,
114+
**item.model_dump(
115+
include={
116+
"licensed_item_id",
117+
"display_name",
118+
"licensed_resource_type",
119+
"pricing_plan_id",
120+
"created_at",
121+
"modified_at",
122+
},
123+
exclude_unset=True,
124+
),
118125
"licensed_resource_data": {
119126
**item.licensed_resource_data,
120127
},
121-
"pricing_plan_id": item.pricing_plan_id,
122-
"created_at": item.created_at,
123-
"modified_at": item.modified_at,
124128
}
125129
)
126130

packages/models-library/tests/test_licenses.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@ def test_licensed_item_from_domain_model():
2020
# date is required
2121
assert got.licensed_resource_data.source.features["date"]
2222

23-
#
23+
# id is required
2424
assert (
2525
got.licensed_resource_data.source.id
2626
== item.licensed_resource_data["source"]["id"]
2727
)
2828

29+
# checks unset fields
30+
assert "category_icon" not in got.licensed_resource_data.model_fields_set
31+
2932

3033
def test_strict_check_of_examples():
3134
class TestLicensedItemRestGet(LicensedItemRestGet):

0 commit comments

Comments
 (0)