-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtest_work_item_detail_sparse.py
More file actions
94 lines (77 loc) · 3 KB
/
test_work_item_detail_sparse.py
File metadata and controls
94 lines (77 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"""Tests for WorkItemDetail parsing with sparse API responses (MFT-34).
When the Plane API is called with a ``fields`` parameter, it returns only the
requested fields. ``assignees`` and ``labels`` may be absent. These tests
verify that ``WorkItemDetail`` handles both full and sparse payloads without
raising a ``ValidationError``.
"""
import pytest
from pydantic import ValidationError
from plane.models.work_items import WorkItemDetail
# -- Fixtures ----------------------------------------------------------------
FULL_RESPONSE = {
"id": "abc-123",
"name": "Test item",
"assignees": [
{
"id": "user-1",
"first_name": "Alice",
"last_name": "Smith",
"email": "alice@example.com",
"display_name": "alice",
}
],
"labels": [
{
"id": "label-1",
"name": "Bug",
"color": "#FF0000",
}
],
"priority": "high",
"state": "state-uuid",
"project": "proj-uuid",
"workspace": "ws-uuid",
}
SPARSE_RESPONSE_NO_ASSIGNEES_LABELS = {
"id": "abc-123",
"name": "Test item",
"state": "state-uuid",
}
SPARSE_RESPONSE_ID_AND_NAME_ONLY = {
"id": "abc-123",
"name": "Test item",
}
# -- Tests -------------------------------------------------------------------
class TestWorkItemDetailSparseResponse:
"""Regression tests for MFT-34: fields parameter causes ValidationError."""
def test_full_response_parses(self):
"""Full API response (with assignees + labels) still works."""
item = WorkItemDetail.model_validate(FULL_RESPONSE)
assert item.id == "abc-123"
assert len(item.assignees) == 1
assert item.assignees[0].id == "user-1"
assert len(item.labels) == 1
assert item.labels[0].name == "Bug"
def test_sparse_response_without_assignees_and_labels(self):
"""Sparse response (fields=id,name,state) must not raise ValidationError."""
item = WorkItemDetail.model_validate(SPARSE_RESPONSE_NO_ASSIGNEES_LABELS)
assert item.id == "abc-123"
assert item.name == "Test item"
assert item.assignees == []
assert item.labels == []
def test_sparse_response_id_and_name_only(self):
"""Minimal sparse response (fields=id,name) must not raise."""
item = WorkItemDetail.model_validate(SPARSE_RESPONSE_ID_AND_NAME_ONLY)
assert item.id == "abc-123"
assert item.assignees == []
assert item.labels == []
def test_empty_assignees_and_labels_accepted(self):
"""Explicit empty lists are accepted (normal case with no assignees)."""
data = {**FULL_RESPONSE, "assignees": [], "labels": []}
item = WorkItemDetail.model_validate(data)
assert item.assignees == []
assert item.labels == []
def test_name_still_required(self):
"""``name`` is still required — sparse responses always include it."""
with pytest.raises(ValidationError):
WorkItemDetail.model_validate({"id": "abc-123"})