diff --git a/plane/models/enums.py b/plane/models/enums.py index a1bf59a..0f6dde4 100644 --- a/plane/models/enums.py +++ b/plane/models/enums.py @@ -56,6 +56,7 @@ "FILE", "FORMULA", "CASCADING", + "RATING", ] RelationTypeEnum = Literal["ISSUE", "USER", "RELEASE", "RICH_TEXT"] CycleStatusEnum = Literal["current", "upcoming", "completed", "draft", "incomplete"] @@ -80,6 +81,7 @@ class PropertyType(str, Enum): FILE = "FILE" FORMULA = "FORMULA" CASCADING = "CASCADING" + RATING = "RATING" class RelationType(str, Enum): @@ -92,7 +94,7 @@ class RelationType(str, Enum): class CustomerPropertyType(str, Enum): - """Customer property types -- the work item set without FORMULA and CASCADING.""" + """Customer property types -- the work item set without FORMULA, CASCADING and RATING.""" TEXT = "TEXT" DATETIME = "DATETIME" diff --git a/plane/models/v2/work_item_properties.py b/plane/models/v2/work_item_properties.py index df06a0f..e28b3b2 100644 --- a/plane/models/v2/work_item_properties.py +++ b/plane/models/v2/work_item_properties.py @@ -19,6 +19,7 @@ "EMAIL", "FILE", "FORMULA", + "RATING", ] WorkItemPropertyRelationType = Literal["ISSUE", "USER", "RELEASE", "RICH_TEXT"] diff --git a/plane/models/v2/work_item_types.py b/plane/models/v2/work_item_types.py index 4be1bde..3d49e0c 100644 --- a/plane/models/v2/work_item_types.py +++ b/plane/models/v2/work_item_types.py @@ -19,6 +19,7 @@ "EMAIL", "FILE", "FORMULA", + "RATING", ] WorkItemPropertyRelationType = Literal["ISSUE", "USER", "RELEASE", "RICH_TEXT"] diff --git a/plane/models/work_item_properties.py b/plane/models/work_item_properties.py index a014789..685ad08 100644 --- a/plane/models/work_item_properties.py +++ b/plane/models/work_item_properties.py @@ -287,6 +287,7 @@ class CreateWorkItemPropertyValue(BaseModel): - DATETIME: string (YYYY-MM-DD or YYYY-MM-DD HH:MM:SS) - DECIMAL: number (int or float) - BOOLEAN: boolean (true/false) + - RATING: integer from 1 to 5 (clear a rating with DELETE, not 0) - OPTION/RELATION (single): string (UUID) - OPTION/RELATION (multi, when is_multi=True): list of strings (UUIDs) or single string - RELATION with relation_type=RICH_TEXT: RichTextValue @@ -323,7 +324,7 @@ class WorkItemPropertyValueDetail(BaseModel): id: str = Field(..., description="Unique identifier for this property value") property_id: str = Field(..., description="ID of the property") issue_id: str = Field(..., description="ID of the work item") - value: str | bool | float | None = Field( + value: str | bool | int | float | None = Field( ..., description="The actual value, formatted according to property type" ) value_type: str | None = Field(None, description="Type of the value") diff --git a/tests/unit/test_work_item_properties.py b/tests/unit/test_work_item_properties.py index e107e9e..bcc8a5c 100644 --- a/tests/unit/test_work_item_properties.py +++ b/tests/unit/test_work_item_properties.py @@ -794,6 +794,30 @@ def test_a_cascading_property_parses(self) -> None: assert prop.property_type == PropertyType.CASCADING + def test_a_rating_property_parses(self) -> None: + """Same failure as CASCADING: one RATING property broke listing the workspace's.""" + prop = WorkItemProperty.model_validate( + {"id": "p", "property_type": "RATING", "display_name": "Impact"} + ) + + assert prop.property_type == PropertyType.RATING + + def test_a_rating_value_stays_an_int(self) -> None: + """Plane returns a rating as an int; the union had no int, so 4 read back as 4.0.""" + detail = WorkItemPropertyValueDetail.model_validate( + {"id": "v", "property_id": "p", "issue_id": "w", "value": 4} + ) + + assert detail.value == 4 + assert type(detail.value) is int + + def test_a_decimal_value_stays_a_float(self) -> None: + detail = WorkItemPropertyValueDetail.model_validate( + {"id": "v", "property_id": "p", "issue_id": "w", "value": 4.5} + ) + + assert type(detail.value) is float + def test_rich_text_is_a_relation_type_not_a_property_type(self) -> None: assert "RICH_TEXT" in {member.value for member in RelationType} assert "RICH_TEXT" not in {member.value for member in PropertyType} diff --git a/tests/v2/test_work_item_properties_resource.py b/tests/v2/test_work_item_properties_resource.py index 41c1115..ea75ac3 100644 --- a/tests/v2/test_work_item_properties_resource.py +++ b/tests/v2/test_work_item_properties_resource.py @@ -26,7 +26,9 @@ CreateWorkItemPropertyOption, UpdateWorkItemProperty, UpdateWorkItemPropertyOption, + WorkItemProperty, ) +from plane.models.v2.work_item_types import WorkItemProperty as WorkItemTypeProperty PROJECT_BASE = "https://api.example.com/api/v2/workspaces/acme/projects/ENG/work-item-properties" WORKSPACE_BASE = "https://api.example.com/api/v2/workspaces/acme/work-item-properties" @@ -482,5 +484,20 @@ def test_workspace_options_crud(workspace_options: WorkspaceWorkItemPropertyOpti assert responses.calls[3].request.url == f"{WORKSPACE_BASE}/p1/options/o1/" +@pytest.mark.parametrize("model", [WorkItemProperty, WorkItemTypeProperty]) +def test_a_rating_property_parses(model: type[WorkItemProperty | WorkItemTypeProperty]) -> None: + """The golden lists RATING; without it in the Literal one rating property made + listing a workspace's properties, or a type's, raise ValidationError.""" + prop = model.model_validate({"id": "p1", "display_name": "Impact", "property_type": "RATING"}) + + assert prop.property_type == "RATING" + + +def test_create_a_rating_property() -> None: + body = CreateWorkItemProperty(display_name="Impact", property_type="RATING") + + assert body.model_dump(exclude_none=True)["property_type"] == "RATING" + + # -- Navigation: a fetched property reaches its options/contexts -- see # tests/v2/test_loaded_work_item_properties.py.