-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtest_work_items.py
More file actions
255 lines (223 loc) · 9.49 KB
/
test_work_items.py
File metadata and controls
255 lines (223 loc) · 9.49 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
"""Unit tests for WorkItems API resource (smoke tests with real HTTP requests)."""
import pytest
from plane.client import PlaneClient
from plane.models.projects import Project
from plane.models.query_params import PaginatedQueryParams, WorkItemQueryParams
from plane.models.work_items import AdvancedSearchWorkItem, CreateWorkItem, UpdateWorkItem
class TestWorkItemsAPI:
"""Test WorkItems API resource."""
def test_list_work_items(
self, client: PlaneClient, workspace_slug: str, project: Project
) -> None:
"""Test listing work items."""
response = client.work_items.list(workspace_slug, project.id)
assert response is not None
assert hasattr(response, "results")
assert hasattr(response, "count")
assert isinstance(response.results, list)
def test_list_work_items_with_params(
self, client: PlaneClient, workspace_slug: str, project
) -> None:
"""Test listing work items with query parameters."""
params = PaginatedQueryParams(per_page=10)
response = client.work_items.list(workspace_slug, project.id, params=params)
assert response is not None
assert hasattr(response, "results")
assert len(response.results) <= 10
def test_list_work_items_with_pql_filter(
self, client: PlaneClient, workspace_slug: str, project: Project
) -> None:
"""Test listing work items with a PQL filter."""
created_item = None
created_item_2 = None
try:
created_item = client.work_items.create(
workspace_slug,
project.id,
CreateWorkItem(
name="pql-filter-high-priority-item",
priority="high",
),
)
created_item_2 = client.work_items.create(
workspace_slug,
project.id,
CreateWorkItem(
name="pql-filter-low-priority-item",
priority="low",
),
)
params = WorkItemQueryParams(pql='priority IN ("high")')
response = client.work_items.list(workspace_slug, project.id, params=params)
assert response is not None
assert hasattr(response, "results")
assert isinstance(response.results, list)
assert len(response.results) > 0
result_ids = [item.id for item in response.results]
assert created_item.id in result_ids
assert created_item_2.id not in result_ids
finally:
if created_item is not None:
client.work_items.delete(workspace_slug, project.id, created_item.id)
if created_item_2 is not None:
client.work_items.delete(workspace_slug, project.id, created_item_2.id)
def test_search_work_items(self, client: PlaneClient, workspace_slug: str) -> None:
"""Test searching work items."""
response = client.work_items.search(workspace_slug, "test")
assert response is not None
assert hasattr(response, "issues")
assert isinstance(response.issues, list)
def test_advanced_search_work_items(self, client: PlaneClient, workspace_slug: str) -> None:
"""Test advanced search with query only."""
data = AdvancedSearchWorkItem(query="test", limit=10)
results = client.work_items.advanced_search(workspace_slug, data)
assert isinstance(results, list)
for item in results:
assert item.id is not None
assert item.name is not None
assert item.sequence_id is not None
assert item.project_id is not None
assert item.workspace_id is not None
def test_advanced_search_with_filters(self, client: PlaneClient, workspace_slug: str) -> None:
"""Test advanced search with filters."""
data = AdvancedSearchWorkItem(
filters={
"and": [
{"priority": "high"},
]
},
limit=10,
)
results = client.work_items.advanced_search(workspace_slug, data)
assert isinstance(results, list)
for item in results:
assert item.id is not None
assert item.priority == "high"
def test_advanced_search_with_nested_filters(
self, client: PlaneClient, workspace_slug: str
) -> None:
"""Test advanced search with nested AND/OR filters."""
data = AdvancedSearchWorkItem(
filters={
"or": [
{"priority": "high"},
{"priority": "urgent"},
]
},
limit=10,
)
results = client.work_items.advanced_search(workspace_slug, data)
assert isinstance(results, list)
for item in results:
assert item.priority in ("high", "urgent")
class TestWorkItemsAPICRUD:
"""Test WorkItems API CRUD operations."""
@pytest.fixture
def work_item_data(self) -> CreateWorkItem:
"""Create test work item data."""
import time
return CreateWorkItem(
name=f"Test Work Item {int(time.time())}",
description_html="<p>Test work item description</p>",
priority="medium",
)
@pytest.fixture
def work_item(
self,
client: PlaneClient,
workspace_slug: str,
project: Project,
work_item_data: CreateWorkItem,
):
"""Create a test work item and yield it, then delete it."""
work_item = client.work_items.create(workspace_slug, project.id, work_item_data)
yield work_item
try:
client.work_items.delete(workspace_slug, project.id, work_item.id)
except Exception:
pass
def test_create_work_item(
self,
client: PlaneClient,
workspace_slug: str,
project: Project,
work_item_data: CreateWorkItem,
) -> None:
"""Test creating a work item."""
work_item = client.work_items.create(workspace_slug, project.id, work_item_data)
assert work_item is not None
assert work_item.id is not None
assert work_item.name == work_item_data.name
# Cleanup
try:
client.work_items.delete(workspace_slug, project.id, work_item.id)
except Exception:
pass
def test_retrieve_work_item(
self, client: PlaneClient, workspace_slug: str, project: Project, work_item
) -> None:
"""Test retrieving a work item."""
retrieved = client.work_items.retrieve(workspace_slug, project.id, work_item.id)
assert retrieved is not None
assert retrieved.id == work_item.id
assert hasattr(retrieved, "name")
def test_update_work_item(
self, client: PlaneClient, workspace_slug: str, project: Project, work_item
) -> None:
"""Test updating a work item."""
update_data = UpdateWorkItem(description_html="<p>Updated description</p>")
updated = client.work_items.update(workspace_slug, project.id, work_item.id, update_data)
assert updated is not None
assert updated.id == work_item.id
class TestWorkItemsSubResources:
"""Test WorkItems sub-resources (comments, links, relations, etc.)."""
@pytest.fixture
def work_item(self, client: PlaneClient, workspace_slug: str, project: Project):
"""Create a test work item."""
import time
from plane.models.work_items import CreateWorkItem
work_item_data = CreateWorkItem(
name=f"Test Work Item {int(time.time())}",
description_html="<p>Test work item</p>",
priority="medium",
)
work_item = client.work_items.create(workspace_slug, project.id, work_item_data)
yield work_item
try:
client.work_items.delete(workspace_slug, project.id, work_item.id)
except Exception:
pass
def test_list_comments(
self, client: PlaneClient, workspace_slug: str, project: Project, work_item
) -> None:
"""Test listing work item comments."""
response = client.work_items.comments.list(workspace_slug, project.id, work_item.id)
assert response is not None
assert hasattr(response, "results")
assert hasattr(response, "count")
assert isinstance(response.results, list)
def test_list_links(
self, client: PlaneClient, workspace_slug: str, project: Project, work_item
) -> None:
"""Test listing work item links."""
response = client.work_items.links.list(workspace_slug, project.id, work_item.id)
assert response is not None
assert hasattr(response, "results")
assert hasattr(response, "count")
assert isinstance(response.results, list)
def test_list_activities(
self, client: PlaneClient, workspace_slug: str, project: Project, work_item
) -> None:
"""Test listing work item activities."""
response = client.work_items.activities.list(workspace_slug, project.id, work_item.id)
assert response is not None
assert hasattr(response, "results")
assert hasattr(response, "count")
assert isinstance(response.results, list)
def test_list_attachments(
self, client: PlaneClient, workspace_slug: str, project: Project, work_item
) -> None:
"""Test listing work item attachments."""
response = client.work_items.attachments.list(workspace_slug, project.id, work_item.id)
assert response is not None
assert isinstance(response, list)