• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

testit-tms / adapters-python / 16518562847

25 Jul 2025 09:22AM UTC coverage: 44.651% (+8.3%) from 36.372%
16518562847

Pull #196

github

web-flow
Merge 38c255586 into a30e55a09
Pull Request #196: feat: TMS-34041: support the api-client without pydantic.

11 of 39 new or added lines in 2 files covered. (28.21%)

2 existing lines in 1 file now uncovered.

1106 of 2477 relevant lines covered (44.65%)

0.96 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

53.52
/testit-python-commons/src/testit_python_commons/client/converter.py
1
import typing
2✔
2

3
from testit_api_client.models import (
2✔
4
    AttachmentPutModelAutoTestStepResultsModel,
5
    AutoTestStepResultUpdateRequest,
6
    CreateAutoTestRequest,
7
    UpdateAutoTestRequest,
8
    AutoTestPostModel,
9
    AutoTestPutModel,
10
    AutoTestResultsForTestRunModel,
11
    AutoTestStepModel,
12
    AvailableTestResultOutcome,
13
    LinkPostModel,
14
    LinkPutModel,
15
    LinkType,
16
    CreateEmptyRequest,
17
    TestRunV2ApiResult,
18
    AutoTestSearchApiModelFilter,
19
    AutoTestSearchApiModelIncludes,
20
    ApiV2AutoTestsSearchPostRequest,
21
    ApiV2TestResultsIdPutRequest,
22
    TestResultResponse,
23
    TestResultV2GetModel,
24
    AttachmentApiResult,
25
    AttachmentUpdateRequest
26
)
27

28
from testit_python_commons.models.link import Link
2✔
29
from testit_python_commons.models.step_result import StepResult
2✔
30
from testit_python_commons.models.test_result import TestResult
2✔
31
from testit_python_commons.models.test_result_with_all_fixture_step_results_model import TestResultWithAllFixtureStepResults
2✔
32
from testit_python_commons.services.logger import adapter_logger
2✔
33

34

35
class Converter:
2✔
36
    @classmethod
2✔
37
    @adapter_logger
2✔
38
    def test_run_to_test_run_short_model(cls, project_id, name):
2✔
NEW
39
        return CreateEmptyRequest(
×
40
            project_id=project_id,
41
            name=name
42
        )
43

44
    @classmethod
2✔
45
    @adapter_logger
2✔
46
    def get_id_from_create_test_run_response(cls, response: TestRunV2ApiResult):
2✔
47
        return response.id
×
48

49
    @classmethod
2✔
50
    @adapter_logger
2✔
51
    def get_resolved_autotests_from_get_test_run_response(cls, response: TestRunV2ApiResult, configuration: str):
2✔
52
        autotests = response.test_results
×
53

54
        return cls.__get_resolved_autotests(autotests, configuration)
×
55

56
    @classmethod
2✔
57
    @adapter_logger
2✔
58
    def project_id_and_external_id_to_auto_tests_search_post_request(cls, project_id: str, external_id: str):
2✔
NEW
59
        autotests_filter = AutoTestSearchApiModelFilter(
×
60
            project_ids=[project_id],
61
            external_ids=[external_id],
62
            is_deleted=False)
NEW
63
        autotests_includes = AutoTestSearchApiModelIncludes(
×
64
            include_steps=False,
65
            include_links=False,
66
            include_labels=False)
67

NEW
68
        return ApiV2AutoTestsSearchPostRequest(filter=autotests_filter, includes=autotests_includes)
×
69

70
    @staticmethod
2✔
71
    @adapter_logger
2✔
72
    def __get_resolved_autotests(autotests: typing.List[TestResultV2GetModel], configuration: str):
2✔
73
        resolved_autotests = []
×
74

75
        for autotest in autotests:
×
76
            if configuration == autotest.configuration_id:
×
77
                resolved_autotests.append(autotest.auto_test.external_id)
×
78

79
        return resolved_autotests
×
80

81
    @classmethod
2✔
82
    @adapter_logger
2✔
83
    def test_result_to_autotest_post_model(
2✔
84
            cls,
85
            test_result: TestResult,
86
            project_id: str):
87
        return AutoTestPostModel(
×
88
            external_id=test_result.get_external_id(),
89
            project_id=project_id,
90
            name=test_result.get_autotest_name(),
91
            steps=cls.step_results_to_autotest_steps_model(
92
                test_result.get_step_results()),
93
            setup=cls.step_results_to_autotest_steps_model(
94
                test_result.get_setup_results()),
95
            teardown=cls.step_results_to_autotest_steps_model(
96
                test_result.get_teardown_results()),
97
            namespace=test_result.get_namespace(),
98
            classname=test_result.get_classname(),
99
            title=test_result.get_title(),
100
            description=test_result.get_description(),
101
            links=cls.links_to_links_post_model(test_result.get_links()),
102
            labels=test_result.get_labels(),
103
            should_create_work_item=test_result.get_automatic_creation_test_cases(),
104
            external_key=test_result.get_external_key()
105
        )
106

107
    @classmethod
2✔
108
    @adapter_logger
2✔
109
    def test_result_to_create_autotest_request(
2✔
110
            cls,
111
            test_result: TestResult,
112
            project_id: str):
NEW
113
        return CreateAutoTestRequest(
×
114
            external_id=test_result.get_external_id(),
115
            project_id=project_id,
116
            name=test_result.get_autotest_name(),
117
            steps=cls.step_results_to_autotest_steps_model(
118
                test_result.get_step_results()),
119
            setup=cls.step_results_to_autotest_steps_model(
120
                test_result.get_setup_results()),
121
            teardown=cls.step_results_to_autotest_steps_model(
122
                test_result.get_teardown_results()),
123
            namespace=test_result.get_namespace(),
124
            classname=test_result.get_classname(),
125
            title=test_result.get_title(),
126
            description=test_result.get_description(),
127
            links=cls.links_to_links_post_model(test_result.get_links()),
128
            labels=test_result.get_labels(),
129
            should_create_work_item=test_result.get_automatic_creation_test_cases(),
130
            external_key=test_result.get_external_key()
131
        )
132

133
    @classmethod
2✔
134
    @adapter_logger
2✔
135
    def test_result_to_autotest_put_model(
2✔
136
            cls,
137
            test_result: TestResult,
138
            project_id: str):
139
        if test_result.get_outcome() == 'Passed':
×
140
            return AutoTestPutModel(
×
141
                external_id=test_result.get_external_id(),
142
                project_id=project_id,
143
                name=test_result.get_autotest_name(),
144
                steps=cls.step_results_to_autotest_steps_model(
145
                    test_result.get_step_results()),
146
                setup=cls.step_results_to_autotest_steps_model(
147
                    test_result.get_setup_results()),
148
                teardown=cls.step_results_to_autotest_steps_model(
149
                    test_result.get_teardown_results()),
150
                namespace=test_result.get_namespace(),
151
                classname=test_result.get_classname(),
152
                title=test_result.get_title(),
153
                description=test_result.get_description(),
154
                links=cls.links_to_links_put_model(test_result.get_links()),
155
                labels=test_result.get_labels(),
156
                external_key=test_result.get_external_key()
157
            )
158
        else:
159
            return AutoTestPutModel(
×
160
                external_id=test_result.get_external_id(),
161
                project_id=project_id,
162
                name=test_result.get_autotest_name(),
163
                steps=cls.step_results_to_autotest_steps_model(
164
                    test_result.get_step_results()),
165
                setup=cls.step_results_to_autotest_steps_model(
166
                    test_result.get_setup_results()),
167
                teardown=cls.step_results_to_autotest_steps_model(
168
                    test_result.get_teardown_results()),
169
                namespace=test_result.get_namespace(),
170
                classname=test_result.get_classname(),
171
                title=test_result.get_title(),
172
                description=test_result.get_description(),
173
                links=cls.links_to_links_put_model(test_result.get_links()),
174
                labels=test_result.get_labels(),
175
                external_key=test_result.get_external_key()
176
            )
177

178
    @classmethod
2✔
179
    @adapter_logger
2✔
180
    def test_result_to_update_autotest_request(
2✔
181
            cls,
182
            test_result: TestResult,
183
            project_id: str):
NEW
184
        if test_result.get_outcome() == 'Passed':
×
NEW
185
            return UpdateAutoTestRequest(
×
186
                external_id=test_result.get_external_id(),
187
                project_id=project_id,
188
                name=test_result.get_autotest_name(),
189
                steps=cls.step_results_to_autotest_steps_model(
190
                    test_result.get_step_results()),
191
                setup=cls.step_results_to_autotest_steps_model(
192
                    test_result.get_setup_results()),
193
                teardown=cls.step_results_to_autotest_steps_model(
194
                    test_result.get_teardown_results()),
195
                namespace=test_result.get_namespace(),
196
                classname=test_result.get_classname(),
197
                title=test_result.get_title(),
198
                description=test_result.get_description(),
199
                links=cls.links_to_links_put_model(test_result.get_links()),
200
                labels=test_result.get_labels(),
201
                external_key=test_result.get_external_key()
202
            )
203
        else:
NEW
204
            return UpdateAutoTestRequest(
×
205
                external_id=test_result.get_external_id(),
206
                project_id=project_id,
207
                name=test_result.get_autotest_name(),
208
                steps=cls.step_results_to_autotest_steps_model(
209
                    test_result.get_step_results()),
210
                setup=cls.step_results_to_autotest_steps_model(
211
                    test_result.get_setup_results()),
212
                teardown=cls.step_results_to_autotest_steps_model(
213
                    test_result.get_teardown_results()),
214
                namespace=test_result.get_namespace(),
215
                classname=test_result.get_classname(),
216
                title=test_result.get_title(),
217
                description=test_result.get_description(),
218
                links=cls.links_to_links_put_model(test_result.get_links()),
219
                labels=test_result.get_labels(),
220
                external_key=test_result.get_external_key()
221
            )
222

223
    @classmethod
2✔
224
    @adapter_logger
2✔
225
    def test_result_to_testrun_result_post_model(
2✔
226
            cls,
227
            test_result: TestResult,
228
            configuration_id: str):
229
        return AutoTestResultsForTestRunModel(
×
230
            configuration_id=configuration_id,
231
            auto_test_external_id=test_result.get_external_id(),
232
            outcome=AvailableTestResultOutcome(test_result.get_outcome()),
233
            step_results=cls.step_results_to_attachment_put_model_autotest_step_results_model(
234
                test_result.get_step_results()),
235
            setup_results=cls.step_results_to_attachment_put_model_autotest_step_results_model(
236
                test_result.get_setup_results()),
237
            teardown_results=cls.step_results_to_attachment_put_model_autotest_step_results_model(
238
                test_result.get_teardown_results()),
239
            traces=test_result.get_traces(),
240
            attachments=test_result.get_attachments(),
241
            parameters=test_result.get_parameters(),
242
            properties=test_result.get_properties(),
243
            links=cls.links_to_links_post_model(
244
                test_result.get_result_links()),
245
            duration=round(test_result.get_duration()),
246
            message=test_result.get_message(),
247
            started_on=test_result.get_started_on(),
248
            completed_on=test_result.get_completed_on()
249
        )
250

251
    @classmethod
2✔
252
    @adapter_logger
2✔
253
    def convert_test_result_model_to_test_results_id_put_request(
2✔
254
            cls,
255
            test_result: TestResultResponse) -> ApiV2TestResultsIdPutRequest:
NEW
256
        return ApiV2TestResultsIdPutRequest(
×
257
            failure_class_ids=test_result.failure_class_ids,
258
            outcome=test_result.outcome,
259
            comment=test_result.comment,
260
            links=test_result.links,
261
            step_results=test_result.step_results,
262
            attachments=cls.attachment_models_to_attachment_put_models(test_result.attachments),
263
            duration_in_ms=test_result.duration_in_ms,
264
            step_comments=test_result.step_comments,
265
            # setup_results=test_result.setup_results,
266
            # teardown_results=test_result.teardown_results,
267
            message=test_result.message,
268
            trace=test_result.traces)
269

270
    @classmethod
2✔
271
    @adapter_logger
2✔
272
    def convert_test_result_with_all_setup_and_teardown_steps_to_test_results_id_put_request(
2✔
273
            cls,
274
            test_result: TestResultWithAllFixtureStepResults) -> ApiV2TestResultsIdPutRequest:
NEW
275
        return ApiV2TestResultsIdPutRequest(
×
276
            setup_results=cls.step_results_to_attachment_put_model_autotest_step_results_model(
277
                test_result.get_setup_results()),
278
            teardown_results=cls.step_results_to_attachment_put_model_autotest_step_results_model(
279
                test_result.get_teardown_results()))
280

281
    @classmethod
2✔
282
    @adapter_logger
2✔
283
    def get_test_result_id_from_testrun_result_post_response(cls, response) -> str:
2✔
284
        return response[0]
×
285

286
    @staticmethod
2✔
287
    @adapter_logger
2✔
288
    def link_to_link_post_model(link: Link) -> LinkPostModel:
2✔
289
        if link.get_link_type():
×
290
            return LinkPostModel(
×
291
                url=link.get_url(),
292
                title=link.get_title(),
293
                type=LinkType(link.get_link_type()),
294
                description=link.get_description(),
295
                has_info=True,
296
            )
297
        else:
298
            return LinkPostModel(
×
299
                url=link.get_url(),
300
                title=link.get_title(),
301
                description=link.get_description(),
302
                has_info=True,
303
            )
304

305
    @staticmethod
2✔
306
    @adapter_logger
2✔
307
    def link_to_link_put_model(link: Link) -> LinkPutModel:
2✔
308
        if link.get_link_type():
×
309
            return LinkPutModel(
×
310
                url=link.get_url(),
311
                title=link.get_title(),
312
                type=LinkType(link.get_link_type()),
313
                description=link.get_description(),
314
                has_info=True,
315
            )
316
        else:
317
            return LinkPutModel(
×
318
                url=link.get_url(),
319
                title=link.get_title(),
320
                description=link.get_description(),
321
                has_info=True,
322
            )
323

324
    @classmethod
2✔
325
    @adapter_logger
2✔
326
    def links_to_links_post_model(cls, links: typing.List[Link]) -> typing.List[LinkPostModel]:
2✔
327
        post_model_links = []
×
328

329
        for link in links:
×
330
            post_model_links.append(
×
331
                cls.link_to_link_post_model(link)
332
            )
333

334
        return post_model_links
×
335

336
    @classmethod
2✔
337
    @adapter_logger
2✔
338
    def links_to_links_put_model(cls, links: typing.List[Link]) -> typing.List[LinkPutModel]:
2✔
339
        put_model_links = []
×
340

341
        for link in links:
×
342
            put_model_links.append(
×
343
                cls.link_to_link_put_model(link)
344
            )
345

346
        return put_model_links
×
347

348
    @classmethod
2✔
349
    @adapter_logger
2✔
350
    def attachment_models_to_attachment_put_models(
2✔
351
            cls, attachments: typing.List[AttachmentApiResult]) -> typing.List[AttachmentUpdateRequest]:
352
        put_model_attachments = []
×
353

354
        for attachment in attachments:
×
355
            put_model_attachments.append(
×
356
                cls.attachment_model_to_attachment_put_model(attachment)
357
            )
358

359
        return put_model_attachments
×
360

361
    @staticmethod
2✔
362
    @adapter_logger
2✔
363
    def attachment_model_to_attachment_put_model(attachment: AttachmentApiResult) -> AttachmentUpdateRequest:
2✔
364
        return AttachmentUpdateRequest(id=attachment.id)
×
365

366
    @classmethod
2✔
367
    # @adapter_logger
368
    def step_results_to_autotest_steps_model(
2✔
369
            cls, step_results: typing.List[StepResult]) -> typing.List[AutoTestStepModel]:
370
        autotest_model_steps = []
×
371

372
        for step_result in step_results:
×
373
            autotest_model_steps.append(
×
374
                AutoTestStepModel(
375
                    title=step_result.get_title(),
376
                    description=step_result.get_description(),
377
                    steps=cls.step_results_to_autotest_steps_model(
378
                        step_result.get_step_results()))
379
            )
380

381
        return autotest_model_steps
×
382

383
    @classmethod
2✔
384
    @adapter_logger
2✔
385
    def step_results_to_attachment_put_model_autotest_step_results_model(
2✔
386
            cls, step_results: typing.List[StepResult]) -> typing.List[AttachmentPutModelAutoTestStepResultsModel]:
387
        autotest_model_step_results = []
×
388

389
        for step_result in step_results:
×
390
            autotest_model_step_results.append(
×
391
                AttachmentPutModelAutoTestStepResultsModel(
392
                    title=step_result.get_title(),
393
                    outcome=AvailableTestResultOutcome(step_result.get_outcome()),
394
                    description=step_result.get_description(),
395
                    duration=step_result.get_duration(),
396
                    parameters=step_result.get_parameters(),
397
                    attachments=step_result.get_attachments(),
398
                    started_on=step_result.get_started_on(),
399
                    completed_on=step_result.get_completed_on(),
400
                    step_results=cls.step_results_to_attachment_put_model_autotest_step_results_model(
401
                        step_result.get_step_results())
402
                )
403
            )
404

405
        return autotest_model_step_results
×
406

407
    @staticmethod
2✔
408
    @adapter_logger
2✔
409
    def fixtures_containers_to_test_results_with_all_fixture_step_results(
2✔
410
            fixtures_containers: dict,
411
            test_result_ids: dict) -> typing.List[TestResultWithAllFixtureStepResults]:
412
        test_results_with_all_fixture_step_results = []
×
413

414
        for external_id, test_result_id in test_result_ids.items():
×
415
            test_result_with_all_fixture_step_results = TestResultWithAllFixtureStepResults(test_result_id)
×
416

417
            for uuid, fixtures_container in fixtures_containers.items():
×
418
                if external_id in fixtures_container.external_ids:
×
419
                    if fixtures_container.befores:
×
420
                        test_result_with_all_fixture_step_results.set_setup_results(fixtures_container.befores[0].steps)
×
421

422
                    if fixtures_container.afters:
×
423
                        test_result_with_all_fixture_step_results.set_teardown_results(
×
424
                            fixtures_container.afters[0].steps)
425

426
            test_results_with_all_fixture_step_results.append(test_result_with_all_fixture_step_results)
×
427

428
        return test_results_with_all_fixture_step_results
×
429

430
    @classmethod
2✔
431
    @adapter_logger
2✔
432
    def step_results_to_auto_test_step_result_update_request(
2✔
433
            cls, step_results: typing.List[StepResult]) -> typing.List[AutoTestStepResultUpdateRequest]:
434
        autotest_model_step_results = []
×
435

436
        for step_result in step_results:
×
437
            autotest_model_step_results.append(
×
438
                AutoTestStepResultUpdateRequest(
439
                    title=step_result.get_title(),
440
                    outcome=AvailableTestResultOutcome(step_result.get_outcome()),
441
                    description=step_result.get_description(),
442
                    duration=step_result.get_duration(),
443
                    parameters=step_result.get_parameters(),
444
                    attachments=step_result.get_attachments(),
445
                    started_on=step_result.get_started_on(),
446
                    completed_on=step_result.get_completed_on(),
447
                    step_results=cls.step_results_to_auto_test_step_result_update_request(
448
                        step_result.get_step_results())
449
                )
450
            )
451

452
        return autotest_model_step_results
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc