Repository navigation
Expand file tree
/
Copy pathtest_issues_comments.py
More file actions
236 lines (195 loc) · 7.37 KB
/
Copy pathtest_issues_comments.py
File metadata and controls
236 lines (195 loc) · 7.37 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
# Copyright (C) CVAT.ai Corporation
#
# SPDX-License-Identifier: MIT
import io
from logging import Logger
from pathlib import Path
import pytest
from cvat_sdk import Client
from cvat_sdk.api_client import exceptions, models
from cvat_sdk.core.proxies.tasks import ResourceType, Task
class TestIssuesUsecases:
@pytest.fixture(autouse=True)
def setup(
self,
tmp_path: Path,
fxt_login: tuple[Client, str],
fxt_logger: tuple[Logger, io.StringIO],
fxt_stdout: io.StringIO,
):
self.tmp_path = tmp_path
logger, self.logger_stream = fxt_logger
self.stdout = fxt_stdout
self.client, self.user = fxt_login
self.client.logger = logger
api_client = self.client.api_client
for k in api_client.configuration.logger:
api_client.configuration.logger[k] = logger
yield
@pytest.fixture
def fxt_new_task(self, fxt_image_file: Path):
task = self.client.tasks.create_from_data(
spec={
"name": "test_task",
"labels": [{"name": "car"}, {"name": "person"}],
},
resource_type=ResourceType.LOCAL,
resources=[fxt_image_file],
data_params={"image_quality": 80},
)
return task
def test_can_retrieve_issue(self, fxt_new_task: Task):
issue = self.client.issues.create(
models.IssueWriteRequest(
frame=0,
position=[2.0, 4.0],
job=fxt_new_task.get_jobs()[0].id,
message="hello",
)
)
retrieved_issue = self.client.issues.retrieve(issue.id)
assert issue.id == retrieved_issue.id
assert self.stdout.getvalue() == ""
def test_can_list_issues(self, fxt_new_task: Task):
issue = self.client.issues.create(
models.IssueWriteRequest(
frame=0,
position=[2.0, 4.0],
job=fxt_new_task.get_jobs()[0].id,
message="hello",
assignee=self.client.users.list()[0].id,
)
)
issues = self.client.issues.list()
assert any(issue.id == j.id for j in issues)
assert self.stdout.getvalue() == ""
def test_can_list_comments(self, fxt_new_task: Task):
issue = self.client.issues.create(
models.IssueWriteRequest(
frame=0,
position=[2.0, 4.0],
job=fxt_new_task.get_jobs()[0].id,
message="hello",
)
)
comment = self.client.comments.create(models.CommentWriteRequest(issue.id, message="hi!"))
issue.fetch()
comment_ids = {c.id for c in issue.get_comments()}
assert len(comment_ids) == 2
assert comment.id in comment_ids
assert self.stdout.getvalue() == ""
def test_can_modify_issue(self, fxt_new_task: Task):
issue = self.client.issues.create(
models.IssueWriteRequest(
frame=0,
position=[2.0, 4.0],
job=fxt_new_task.get_jobs()[0].id,
message="hello",
)
)
issue.update(models.PatchedIssueWriteRequest(resolved=True))
retrieved_issue = self.client.issues.retrieve(issue.id)
assert retrieved_issue.resolved is True
assert issue.resolved == retrieved_issue.resolved
assert self.stdout.getvalue() == ""
def test_can_remove_issue(self, fxt_new_task: Task):
issue = self.client.issues.create(
models.IssueWriteRequest(
frame=0,
position=[2.0, 4.0],
job=fxt_new_task.get_jobs()[0].id,
message="hello",
)
)
comments = issue.get_comments()
issue.remove()
with pytest.raises(exceptions.NotFoundException):
issue.fetch()
with pytest.raises(exceptions.NotFoundException):
self.client.comments.retrieve(comments[0].id)
assert self.stdout.getvalue() == ""
class TestCommentsUsecases:
@pytest.fixture(autouse=True)
def setup(
self,
tmp_path: Path,
fxt_login: tuple[Client, str],
fxt_logger: tuple[Logger, io.StringIO],
fxt_stdout: io.StringIO,
):
self.tmp_path = tmp_path
logger, self.logger_stream = fxt_logger
self.stdout = fxt_stdout
self.client, self.user = fxt_login
self.client.logger = logger
api_client = self.client.api_client
for k in api_client.configuration.logger:
api_client.configuration.logger[k] = logger
yield
@pytest.fixture
def fxt_new_task(self, fxt_image_file: Path):
task = self.client.tasks.create_from_data(
spec={
"name": "test_task",
"labels": [{"name": "car"}, {"name": "person"}],
},
resource_type=ResourceType.LOCAL,
resources=[fxt_image_file],
data_params={"image_quality": 80},
)
return task
def test_can_retrieve_comment(self, fxt_new_task: Task):
issue = self.client.issues.create(
models.IssueWriteRequest(
frame=0,
position=[2.0, 4.0],
job=fxt_new_task.get_jobs()[0].id,
message="hello",
)
)
comment = self.client.comments.create(models.CommentWriteRequest(issue.id, message="hi!"))
retrieved_comment = self.client.comments.retrieve(comment.id)
assert comment.id == retrieved_comment.id
assert self.stdout.getvalue() == ""
def test_can_list_comments(self, fxt_new_task: Task):
issue = self.client.issues.create(
models.IssueWriteRequest(
frame=0,
position=[2.0, 4.0],
job=fxt_new_task.get_jobs()[0].id,
message="hello",
)
)
comment = self.client.comments.create(models.CommentWriteRequest(issue.id, message="hi!"))
comments = self.client.comments.list()
assert any(comment.id == c.id for c in comments)
assert self.stdout.getvalue() == ""
def test_can_modify_comment(self, fxt_new_task: Task):
issue = self.client.issues.create(
models.IssueWriteRequest(
frame=0,
position=[2.0, 4.0],
job=fxt_new_task.get_jobs()[0].id,
message="hello",
)
)
comment = self.client.comments.create(models.CommentWriteRequest(issue.id, message="hi!"))
comment.update(models.PatchedCommentWriteRequest(message="bar"))
retrieved_comment = self.client.comments.retrieve(comment.id)
assert retrieved_comment.message == "bar"
assert comment.message == retrieved_comment.message
assert self.stdout.getvalue() == ""
def test_can_remove_comment(self, fxt_new_task: Task):
issue = self.client.issues.create(
models.IssueWriteRequest(
frame=0,
position=[2.0, 4.0],
job=fxt_new_task.get_jobs()[0].id,
message="hello",
)
)
comment = self.client.comments.create(models.CommentWriteRequest(issue.id, message="hi!"))
comment.remove()
with pytest.raises(exceptions.NotFoundException):
comment.fetch()
assert self.stdout.getvalue() == ""