Skip to content

Commit

Permalink
fix(model): allow models to have None values
Browse files Browse the repository at this point in the history
  • Loading branch information
laurent-laporte-pro committed Feb 5, 2024
1 parent c2661d1 commit 2618067
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 13 deletions.
4 changes: 2 additions & 2 deletions antarest/study/business/areas/renewable_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class TimeSeriesInterpretation(EnumIgnoreCase):


@camel_case_model
class RenewableClusterInput(RenewableProperties, metaclass=AllOptionalMetaclass):
class RenewableClusterInput(RenewableProperties, metaclass=AllOptionalMetaclass, use_none=True):
"""
Model representing the data structure required to edit an existing renewable cluster.
"""
Expand Down Expand Up @@ -76,7 +76,7 @@ def to_config(self, study_version: t.Union[str, int]) -> RenewableConfigType:


@camel_case_model
class RenewableClusterOutput(RenewableConfig, metaclass=AllOptionalMetaclass):
class RenewableClusterOutput(RenewableConfig, metaclass=AllOptionalMetaclass, use_none=True):
"""
Model representing the output data structure to display the details of a renewable cluster.
"""
Expand Down
2 changes: 1 addition & 1 deletion antarest/study/business/areas/st_storage_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@


@camel_case_model
class STStorageInput(STStorageProperties, metaclass=AllOptionalMetaclass):
class STStorageInput(STStorageProperties, metaclass=AllOptionalMetaclass, use_none=True):
"""
Model representing the form used to EDIT an existing short-term storage.
"""
Expand Down
4 changes: 2 additions & 2 deletions antarest/study/business/areas/thermal_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@


@camel_case_model
class ThermalClusterInput(Thermal860Properties, metaclass=AllOptionalMetaclass):
class ThermalClusterInput(Thermal860Properties, metaclass=AllOptionalMetaclass, use_none=True):
"""
Model representing the data structure required to edit an existing thermal cluster within a study.
"""
Expand Down Expand Up @@ -70,7 +70,7 @@ def to_config(self, study_version: t.Union[str, int]) -> ThermalConfigType:


@camel_case_model
class ThermalClusterOutput(Thermal860Config, metaclass=AllOptionalMetaclass):
class ThermalClusterOutput(Thermal860Config, metaclass=AllOptionalMetaclass, use_none=True):
"""
Model representing the output data structure to display the details of a thermal cluster within a study.
"""
Expand Down
2 changes: 1 addition & 1 deletion antarest/study/business/thematic_trimming_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from antarest.study.storage.variantstudy.model.command.update_config import UpdateConfig


class ThematicTrimmingFormFields(FormFieldsBaseModel, metaclass=AllOptionalMetaclass):
class ThematicTrimmingFormFields(FormFieldsBaseModel, metaclass=AllOptionalMetaclass, use_none=True):
"""
This class manages the configuration of result filtering in a simulation.
Expand Down
2 changes: 1 addition & 1 deletion antarest/study/business/xpansion_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def from_config(cls, config_obj: JSON) -> "GetXpansionSettings":
return cls.construct(**config_obj)


class UpdateXpansionSettings(XpansionSettings, metaclass=AllOptionalMetaclass):
class UpdateXpansionSettings(XpansionSettings, metaclass=AllOptionalMetaclass, use_none=True):
"""
DTO object used to update the Xpansion settings.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,14 @@ class ClusterProperties(ItemProperties):

@property
def installed_capacity(self) -> float:
""""""
# fields may contain `None` values if they are turned into `Optional` fields
if self.unit_count is None or self.nominal_capacity is None:
return 0.0
return self.unit_count * self.nominal_capacity

@property
def enabled_capacity(self) -> float:
# fields may contain `None` values if they are turned into `Optional` fields
if self.enabled is None or self.installed_capacity is None:
return 0.0
return self.enabled * self.installed_capacity
14 changes: 12 additions & 2 deletions antarest/study/web/study_data_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,18 @@
RenewableClusterInput,
RenewableClusterOutput,
)
from antarest.study.business.areas.st_storage_management import * # noqa
from antarest.study.business.areas.thermal_management import * # noqa
from antarest.study.business.areas.st_storage_management import (
STStorageCreation,
STStorageInput,
STStorageMatrix,
STStorageOutput,
STStorageTimeSeries,
)
from antarest.study.business.areas.thermal_management import (
ThermalClusterCreation,
ThermalClusterInput,
ThermalClusterOutput,
)
from antarest.study.business.binding_constraint_management import (
BindingConstraintPropertiesWithName,
ConstraintTermDTO,
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/study_data_blueprint/test_renewable.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def test_lifecycle(
json=bad_properties,
)
assert res.status_code == 422, res.json()
assert res.json()["exception"] == "ValidationError", res.json()
assert res.json()["exception"] == "RequestValidationError", res.json()

# The renewable cluster properties should not have been updated.
res = client.get(
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/study_data_blueprint/test_st_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def test_lifecycle__nominal(
json=bad_properties,
)
assert res.status_code == 422, res.json()
assert res.json()["exception"] == "ValidationError", res.json()
assert res.json()["exception"] == "RequestValidationError", res.json()

# The short-term storage properties should not have been updated.
res = client.get(
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/study_data_blueprint/test_thermal.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ def test_lifecycle(
json=bad_properties,
)
assert res.status_code == 422, res.json()
assert res.json()["exception"] == "ValidationError", res.json()
assert res.json()["exception"] == "RequestValidationError", res.json()

# The thermal cluster properties should not have been updated.
res = client.get(
Expand Down

0 comments on commit 2618067

Please sign in to comment.