diff --git a/plane/models/enums.py b/plane/models/enums.py index a1bf59a..0fc142c 100644 --- a/plane/models/enums.py +++ b/plane/models/enums.py @@ -56,6 +56,7 @@ "FILE", "FORMULA", "CASCADING", + "SLIDER", ] 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" + SLIDER = "SLIDER" 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 SLIDER.""" TEXT = "TEXT" DATETIME = "DATETIME" diff --git a/plane/models/v2/work_item_properties.py b/plane/models/v2/work_item_properties.py index df06a0f..e44e5b0 100644 --- a/plane/models/v2/work_item_properties.py +++ b/plane/models/v2/work_item_properties.py @@ -19,6 +19,7 @@ "EMAIL", "FILE", "FORMULA", + "SLIDER", ] 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..71df712 100644 --- a/plane/models/v2/work_item_types.py +++ b/plane/models/v2/work_item_types.py @@ -19,6 +19,7 @@ "EMAIL", "FILE", "FORMULA", + "SLIDER", ] 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..1ffd785 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) + - SLIDER: whole number from 0 to 10 (0 is a value; clear a slider with DELETE) - 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_customers.py b/tests/unit/test_customers.py index 231d591..4f6d84a 100644 --- a/tests/unit/test_customers.py +++ b/tests/unit/test_customers.py @@ -667,7 +667,7 @@ class TestCustomerPropertyTypesOffline: BASE = {"name": "tier", "display_name": "Tier"} - @pytest.mark.parametrize("property_type", ["FORMULA", "CASCADING"]) + @pytest.mark.parametrize("property_type", ["FORMULA", "CASCADING", "SLIDER"]) def test_a_work_item_only_type_is_refused(self, property_type: str) -> None: with pytest.raises(ValueError, match="property_type"): CreateCustomerProperty(**self.BASE, property_type=property_type) diff --git a/tests/unit/test_work_item_properties.py b/tests/unit/test_work_item_properties.py index e107e9e..4d61317 100644 --- a/tests/unit/test_work_item_properties.py +++ b/tests/unit/test_work_item_properties.py @@ -794,6 +794,53 @@ def test_a_cascading_property_parses(self) -> None: assert prop.property_type == PropertyType.CASCADING + def test_a_slider_property_parses(self) -> None: + """Same failure as CASCADING: one SLIDER property broke listing the workspace's. + Its server-owned settings have no display_format, so they read as a plain dict.""" + prop = WorkItemProperty.model_validate( + { + "id": "p", + "property_type": "SLIDER", + "display_name": "Confidence", + "settings": {"min": 0, "max": 10}, + } + ) + + assert prop.property_type == PropertyType.SLIDER + assert prop.settings == {"min": 0, "max": 10} + + def test_a_slider_property_is_created_without_settings(self) -> None: + """The server assigns a slider's settings and refuses any sent on create.""" + body = CreateWorkItemProperty(display_name="Confidence", property_type=PropertyType.SLIDER) + + dumped = body.model_dump(exclude_none=True) + assert dumped["property_type"] == "SLIDER" + assert "settings" not in dumped + + @pytest.mark.parametrize("value", [0, 7, 10]) + def test_a_slider_value_stays_an_int(self, value: int) -> None: + """Plane returns a slider value as an int; the union had no int, so 7 read back as + 7.0 -- and 0, a real slider value, must not read as False.""" + detail = WorkItemPropertyValueDetail.model_validate( + {"id": "v", "property_id": "p", "issue_id": "w", "value": value} + ) + + assert detail.value == value + 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_a_slider_zero_is_sent(self) -> None: + """0 sets a slider; it is not dropped as empty.""" + body = CreateWorkItemPropertyValue(value=0) + + assert body.model_dump(exclude_none=True) == {"value": 0} + 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..bfba322 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,31 @@ 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_slider_property_parses(model: type[WorkItemProperty | WorkItemTypeProperty]) -> None: + """The golden lists SLIDER; without it in the Literal one slider property made + listing a workspace's properties, or a type's, raise ValidationError.""" + prop = model.model_validate( + { + "id": "p1", + "display_name": "Confidence", + "property_type": "SLIDER", + "settings": {"min": 0, "max": 10}, + } + ) + + assert prop.property_type == "SLIDER" + assert prop.settings == {"min": 0, "max": 10} + + +def test_create_a_slider_property_without_settings() -> None: + """The server assigns a slider's settings and refuses any sent on create.""" + body = CreateWorkItemProperty(display_name="Confidence", property_type="SLIDER") + + dumped = body.model_dump(exclude_none=True) + assert dumped["property_type"] == "SLIDER" + assert "settings" not in dumped + + # -- Navigation: a fetched property reaches its options/contexts -- see # tests/v2/test_loaded_work_item_properties.py.