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

testit-tms / adapters-python / 17395550471

02 Sep 2025 06:45AM UTC coverage: 36.554% (-0.3%) from 36.848%
17395550471

Pull #200

github

web-flow
Merge 2b90378f4 into 6559ad79f
Pull Request #200: feat: TMS-33268: support the "status code" field.

13 of 60 new or added lines in 4 files covered. (21.67%)

1 existing line in 1 file now uncovered.

1241 of 3395 relevant lines covered (36.55%)

0.73 hits per line

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

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

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

31
from testit_python_commons.models.link import Link
2✔
32
from testit_python_commons.models.step_result import StepResult
2✔
33
from testit_python_commons.models.test_result import TestResult
2✔
34
from testit_python_commons.models.test_result_with_all_fixture_step_results_model import TestResultWithAllFixtureStepResults
2✔
35
from testit_python_commons.services.logger import adapter_logger
2✔
36

37

38
class Converter:
2✔
39
    @classmethod
2✔
40
    @adapter_logger
2✔
41
    def test_run_to_test_run_short_model(cls, project_id, name):
2✔
42
        return CreateEmptyRequest(
×
43
            project_id=project_id,
44
            name=name
45
        )
46

47
    @classmethod
2✔
48
    @adapter_logger
2✔
49
    def get_id_from_create_test_run_response(cls, response: TestRunV2ApiResult):
2✔
50
        return response.id
×
51

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

64
        return ApiV2AutoTestsSearchPostRequest(filter=autotests_filter, includes=autotests_includes)
×
65

66
    @staticmethod
2✔
67
    def testrun_id_and_configuration_id_and_in_progress_outcome_to_test_results_search_post_request(
2✔
68
            testrun_id: str,
69
            configuration_id: str) -> ApiV2TestResultsSearchPostRequest:
NEW
70
        return ApiV2TestResultsSearchPostRequest(
×
71
            test_run_ids=[testrun_id],
72
            configuration_ids=[configuration_id],
73
            status_codes=["InProgress"])
74

75
    @staticmethod
2✔
76
    def autotest_ids_to_autotests_search_post_request(
2✔
77
            autotest_ids: typing.List[int]) -> ApiV2AutoTestsSearchPostRequest:
NEW
78
        autotests_filter = AutoTestSearchApiModelFilter(
×
79
            global_ids=autotest_ids)
NEW
80
        autotests_includes = AutoTestSearchApiModelIncludes(
×
81
            include_steps=False,
82
            include_links=False,
83
            include_labels=False)
84

NEW
85
        return ApiV2AutoTestsSearchPostRequest(filter=autotests_filter, includes=autotests_includes)
×
86

87
    @staticmethod
2✔
88
    @adapter_logger
2✔
89
    def test_result_short_get_models_to_autotest_ids(
2✔
90
            autotests: typing.List[TestResultShortResponse],
91
            configuration: str):
UNCOV
92
        resolved_autotests = []
×
93

94
        for autotest in autotests:
×
95
            if configuration == autotest.configuration_id:
×
NEW
96
                resolved_autotests.append(autotest.autotest_global_id)
×
97

98
        return resolved_autotests
×
99

100
    @staticmethod
2✔
101
    def autotest_models_to_external_ids(
2✔
102
            autotests: typing.List[AutoTestApiResult]) -> typing.List[str]:
NEW
103
        external_ids = []
×
104

NEW
105
        for autotest in autotests:
×
NEW
106
            external_id = autotest.external_id
×
107

NEW
108
            if external_id is None:
×
NEW
109
                continue
×
110

NEW
111
            external_ids.append(external_id)
×
112

NEW
113
        return external_ids
×
114

115
    @classmethod
2✔
116
    @adapter_logger
2✔
117
    def test_result_to_autotest_post_model(
2✔
118
            cls,
119
            test_result: TestResult,
120
            project_id: str):
121
        return AutoTestPostModel(
×
122
            external_id=test_result.get_external_id(),
123
            project_id=project_id,
124
            name=test_result.get_autotest_name(),
125
            steps=cls.step_results_to_autotest_steps_model(
126
                test_result.get_step_results()),
127
            setup=cls.step_results_to_autotest_steps_model(
128
                test_result.get_setup_results()),
129
            teardown=cls.step_results_to_autotest_steps_model(
130
                test_result.get_teardown_results()),
131
            namespace=test_result.get_namespace(),
132
            classname=test_result.get_classname(),
133
            title=test_result.get_title(),
134
            description=test_result.get_description(),
135
            links=cls.links_to_links_post_model(test_result.get_links()),
136
            labels=test_result.get_labels(),
137
            should_create_work_item=test_result.get_automatic_creation_test_cases(),
138
            external_key=test_result.get_external_key()
139
        )
140

141
    @classmethod
2✔
142
    @adapter_logger
2✔
143
    def test_result_to_create_autotest_request(
2✔
144
            cls,
145
            test_result: TestResult,
146
            project_id: str):
147
        return CreateAutoTestRequest(
×
148
            external_id=test_result.get_external_id(),
149
            project_id=project_id,
150
            name=test_result.get_autotest_name(),
151
            steps=cls.step_results_to_autotest_steps_model(
152
                test_result.get_step_results()),
153
            setup=cls.step_results_to_autotest_steps_model(
154
                test_result.get_setup_results()),
155
            teardown=cls.step_results_to_autotest_steps_model(
156
                test_result.get_teardown_results()),
157
            namespace=test_result.get_namespace(),
158
            classname=test_result.get_classname(),
159
            title=test_result.get_title(),
160
            description=test_result.get_description(),
161
            links=cls.links_to_links_post_model(test_result.get_links()),
162
            labels=test_result.get_labels(),
163
            should_create_work_item=test_result.get_automatic_creation_test_cases(),
164
            external_key=test_result.get_external_key()
165
        )
166

167
    @classmethod
2✔
168
    @adapter_logger
2✔
169
    def test_result_to_autotest_put_model(
2✔
170
            cls,
171
            test_result: TestResult,
172
            project_id: str):
173
        if test_result.get_outcome() == 'Passed':
×
174
            return AutoTestPutModel(
×
175
                external_id=test_result.get_external_id(),
176
                project_id=project_id,
177
                name=test_result.get_autotest_name(),
178
                steps=cls.step_results_to_autotest_steps_model(
179
                    test_result.get_step_results()),
180
                setup=cls.step_results_to_autotest_steps_model(
181
                    test_result.get_setup_results()),
182
                teardown=cls.step_results_to_autotest_steps_model(
183
                    test_result.get_teardown_results()),
184
                namespace=test_result.get_namespace(),
185
                classname=test_result.get_classname(),
186
                title=test_result.get_title(),
187
                description=test_result.get_description(),
188
                links=cls.links_to_links_put_model(test_result.get_links()),
189
                labels=test_result.get_labels(),
190
                external_key=test_result.get_external_key()
191
            )
192
        else:
193
            return AutoTestPutModel(
×
194
                external_id=test_result.get_external_id(),
195
                project_id=project_id,
196
                name=test_result.get_autotest_name(),
197
                steps=cls.step_results_to_autotest_steps_model(
198
                    test_result.get_step_results()),
199
                setup=cls.step_results_to_autotest_steps_model(
200
                    test_result.get_setup_results()),
201
                teardown=cls.step_results_to_autotest_steps_model(
202
                    test_result.get_teardown_results()),
203
                namespace=test_result.get_namespace(),
204
                classname=test_result.get_classname(),
205
                title=test_result.get_title(),
206
                description=test_result.get_description(),
207
                links=cls.links_to_links_put_model(test_result.get_links()),
208
                labels=test_result.get_labels(),
209
                external_key=test_result.get_external_key()
210
            )
211

212
    @classmethod
2✔
213
    @adapter_logger
2✔
214
    def test_result_to_update_autotest_request(
2✔
215
            cls,
216
            test_result: TestResult,
217
            project_id: str):
218
        if test_result.get_outcome() == 'Passed':
×
219
            return UpdateAutoTestRequest(
×
220
                external_id=test_result.get_external_id(),
221
                project_id=project_id,
222
                name=test_result.get_autotest_name(),
223
                steps=cls.step_results_to_autotest_steps_model(
224
                    test_result.get_step_results()),
225
                setup=cls.step_results_to_autotest_steps_model(
226
                    test_result.get_setup_results()),
227
                teardown=cls.step_results_to_autotest_steps_model(
228
                    test_result.get_teardown_results()),
229
                namespace=test_result.get_namespace(),
230
                classname=test_result.get_classname(),
231
                title=test_result.get_title(),
232
                description=test_result.get_description(),
233
                links=cls.links_to_links_put_model(test_result.get_links()),
234
                labels=test_result.get_labels(),
235
                external_key=test_result.get_external_key()
236
            )
237
        else:
238
            return UpdateAutoTestRequest(
×
239
                external_id=test_result.get_external_id(),
240
                project_id=project_id,
241
                name=test_result.get_autotest_name(),
242
                steps=cls.step_results_to_autotest_steps_model(
243
                    test_result.get_step_results()),
244
                setup=cls.step_results_to_autotest_steps_model(
245
                    test_result.get_setup_results()),
246
                teardown=cls.step_results_to_autotest_steps_model(
247
                    test_result.get_teardown_results()),
248
                namespace=test_result.get_namespace(),
249
                classname=test_result.get_classname(),
250
                title=test_result.get_title(),
251
                description=test_result.get_description(),
252
                links=cls.links_to_links_put_model(test_result.get_links()),
253
                labels=test_result.get_labels(),
254
                external_key=test_result.get_external_key()
255
            )
256

257
    @classmethod
2✔
258
    @adapter_logger
2✔
259
    def test_result_to_testrun_result_post_model(
2✔
260
            cls,
261
            test_result: TestResult,
262
            configuration_id: str):
263
        return AutoTestResultsForTestRunModel(
×
264
            configuration_id=configuration_id,
265
            auto_test_external_id=test_result.get_external_id(),
266
            status_code=test_result.get_outcome(),
267
            step_results=cls.step_results_to_attachment_put_model_autotest_step_results_model(
268
                test_result.get_step_results()),
269
            setup_results=cls.step_results_to_attachment_put_model_autotest_step_results_model(
270
                test_result.get_setup_results()),
271
            teardown_results=cls.step_results_to_attachment_put_model_autotest_step_results_model(
272
                test_result.get_teardown_results()),
273
            traces=test_result.get_traces(),
274
            attachments=test_result.get_attachments(),
275
            parameters=test_result.get_parameters(),
276
            properties=test_result.get_properties(),
277
            links=cls.links_to_links_post_model(
278
                test_result.get_result_links()),
279
            duration=round(test_result.get_duration()),
280
            message=test_result.get_message(),
281
            started_on=test_result.get_started_on(),
282
            completed_on=test_result.get_completed_on()
283
        )
284

285
    @classmethod
2✔
286
    @adapter_logger
2✔
287
    def convert_test_result_model_to_test_results_id_put_request(
2✔
288
            cls,
289
            test_result: TestResultResponse) -> ApiV2TestResultsIdPutRequest:
290
        return ApiV2TestResultsIdPutRequest(
×
291
            failure_class_ids=test_result.failure_class_ids,
292
            status_code=test_result.status.code,
293
            comment=test_result.comment,
294
            links=test_result.links,
295
            step_results=test_result.step_results,
296
            attachments=cls.attachment_models_to_attachment_put_models(test_result.attachments),
297
            duration_in_ms=test_result.duration_in_ms,
298
            step_comments=test_result.step_comments,
299
            # setup_results=test_result.setup_results,
300
            # teardown_results=test_result.teardown_results,
301
            message=test_result.message,
302
            trace=test_result.traces)
303

304
    @classmethod
2✔
305
    @adapter_logger
2✔
306
    def convert_test_result_with_all_setup_and_teardown_steps_to_test_results_id_put_request(
2✔
307
            cls,
308
            test_result: TestResultWithAllFixtureStepResults) -> ApiV2TestResultsIdPutRequest:
309
        return ApiV2TestResultsIdPutRequest(
×
310
            setup_results=cls.step_results_to_attachment_put_model_autotest_step_results_model(
311
                test_result.get_setup_results()),
312
            teardown_results=cls.step_results_to_attachment_put_model_autotest_step_results_model(
313
                test_result.get_teardown_results()))
314

315
    @classmethod
2✔
316
    @adapter_logger
2✔
317
    def get_test_result_id_from_testrun_result_post_response(cls, response) -> str:
2✔
318
        return response[0]
×
319

320
    @staticmethod
2✔
321
    @adapter_logger
2✔
322
    def link_to_link_post_model(link: Link) -> LinkPostModel:
2✔
323
        if link.get_link_type():
×
324
            return LinkPostModel(
×
325
                url=link.get_url(),
326
                title=link.get_title(),
327
                type=LinkType(link.get_link_type()),
328
                description=link.get_description(),
329
                has_info=True,
330
            )
331
        else:
332
            return LinkPostModel(
×
333
                url=link.get_url(),
334
                title=link.get_title(),
335
                description=link.get_description(),
336
                has_info=True,
337
            )
338

339
    @staticmethod
2✔
340
    @adapter_logger
2✔
341
    def link_to_link_put_model(link: Link) -> LinkPutModel:
2✔
342
        if link.get_link_type():
×
343
            return LinkPutModel(
×
344
                url=link.get_url(),
345
                title=link.get_title(),
346
                type=LinkType(link.get_link_type()),
347
                description=link.get_description(),
348
                has_info=True,
349
            )
350
        else:
351
            return LinkPutModel(
×
352
                url=link.get_url(),
353
                title=link.get_title(),
354
                description=link.get_description(),
355
                has_info=True,
356
            )
357

358
    @classmethod
2✔
359
    @adapter_logger
2✔
360
    def links_to_links_post_model(cls, links: typing.List[Link]) -> typing.List[LinkPostModel]:
2✔
361
        post_model_links = []
×
362

363
        for link in links:
×
364
            post_model_links.append(
×
365
                cls.link_to_link_post_model(link)
366
            )
367

368
        return post_model_links
×
369

370
    @classmethod
2✔
371
    @adapter_logger
2✔
372
    def links_to_links_put_model(cls, links: typing.List[Link]) -> typing.List[LinkPutModel]:
2✔
373
        put_model_links = []
×
374

375
        for link in links:
×
376
            put_model_links.append(
×
377
                cls.link_to_link_put_model(link)
378
            )
379

380
        return put_model_links
×
381

382
    @classmethod
2✔
383
    @adapter_logger
2✔
384
    def attachment_models_to_attachment_put_models(
2✔
385
            cls, attachments: typing.List[AttachmentApiResult]) -> typing.List[AttachmentUpdateRequest]:
386
        put_model_attachments = []
×
387

388
        for attachment in attachments:
×
389
            put_model_attachments.append(
×
390
                cls.attachment_model_to_attachment_put_model(attachment)
391
            )
392

393
        return put_model_attachments
×
394

395
    @staticmethod
2✔
396
    @adapter_logger
2✔
397
    def attachment_model_to_attachment_put_model(attachment: AttachmentApiResult) -> AttachmentUpdateRequest:
2✔
398
        return AttachmentUpdateRequest(id=attachment.id)
×
399

400
    @classmethod
2✔
401
    # @adapter_logger
402
    def step_results_to_autotest_steps_model(
2✔
403
            cls, step_results: typing.List[StepResult]) -> typing.List[AutoTestStepModel]:
404
        autotest_model_steps = []
×
405

406
        for step_result in step_results:
×
407
            autotest_model_steps.append(
×
408
                AutoTestStepModel(
409
                    title=step_result.get_title(),
410
                    description=step_result.get_description(),
411
                    steps=cls.step_results_to_autotest_steps_model(
412
                        step_result.get_step_results()))
413
            )
414

415
        return autotest_model_steps
×
416

417
    @classmethod
2✔
418
    @adapter_logger
2✔
419
    def step_results_to_attachment_put_model_autotest_step_results_model(
2✔
420
            cls, step_results: typing.List[StepResult]) -> typing.List[AttachmentPutModelAutoTestStepResultsModel]:
421
        autotest_model_step_results = []
×
422

423
        for step_result in step_results:
×
424
            autotest_model_step_results.append(
×
425
                AttachmentPutModelAutoTestStepResultsModel(
426
                    title=step_result.get_title(),
427
                    outcome=AvailableTestResultOutcome(step_result.get_outcome()),
428
                    description=step_result.get_description(),
429
                    duration=step_result.get_duration(),
430
                    parameters=step_result.get_parameters(),
431
                    attachments=step_result.get_attachments(),
432
                    started_on=step_result.get_started_on(),
433
                    completed_on=step_result.get_completed_on(),
434
                    step_results=cls.step_results_to_attachment_put_model_autotest_step_results_model(
435
                        step_result.get_step_results())
436
                )
437
            )
438

439
        return autotest_model_step_results
×
440

441
    @staticmethod
2✔
442
    @adapter_logger
2✔
443
    def fixtures_containers_to_test_results_with_all_fixture_step_results(
2✔
444
            fixtures_containers: dict,
445
            test_result_ids: dict) -> typing.List[TestResultWithAllFixtureStepResults]:
446
        test_results_with_all_fixture_step_results = []
×
447

448
        for external_id, test_result_id in test_result_ids.items():
×
449
            test_result_with_all_fixture_step_results = TestResultWithAllFixtureStepResults(test_result_id)
×
450

451
            for uuid, fixtures_container in fixtures_containers.items():
×
452
                if external_id in fixtures_container.external_ids:
×
453
                    if fixtures_container.befores:
×
454
                        test_result_with_all_fixture_step_results.set_setup_results(fixtures_container.befores[0].steps)
×
455

456
                    if fixtures_container.afters:
×
457
                        test_result_with_all_fixture_step_results.set_teardown_results(
×
458
                            fixtures_container.afters[0].steps)
459

460
            test_results_with_all_fixture_step_results.append(test_result_with_all_fixture_step_results)
×
461

462
        return test_results_with_all_fixture_step_results
×
463

464
    @classmethod
2✔
465
    @adapter_logger
2✔
466
    def step_results_to_auto_test_step_result_update_request(
2✔
467
            cls, step_results: typing.List[StepResult]) -> typing.List[AutoTestStepResultUpdateRequest]:
468
        autotest_model_step_results = []
×
469

470
        for step_result in step_results:
×
471
            autotest_model_step_results.append(
×
472
                AutoTestStepResultUpdateRequest(
473
                    title=step_result.get_title(),
474
                    outcome=AvailableTestResultOutcome(step_result.get_outcome()),
475
                    description=step_result.get_description(),
476
                    duration=step_result.get_duration(),
477
                    parameters=step_result.get_parameters(),
478
                    attachments=step_result.get_attachments(),
479
                    started_on=step_result.get_started_on(),
480
                    completed_on=step_result.get_completed_on(),
481
                    step_results=cls.step_results_to_auto_test_step_result_update_request(
482
                        step_result.get_step_results())
483
                )
484
            )
485

486
        return autotest_model_step_results
×
487

488
    @classmethod
2✔
489
    @adapter_logger
2✔
490
    def prepare_to_create_autotest(
2✔
491
            cls,
492
            test_result: TestResult,
493
            project_id: str,
494
            work_item_ids_for_link_with_auto_test: list) -> AutoTestPostModel:
495
        logging.debug('Preparing to create the auto test ' + test_result.get_external_id())
×
496

497
        model = cls.test_result_to_create_autotest_request(
×
498
            test_result,
499
            project_id)
500
        model.work_item_ids_for_link_with_auto_test = work_item_ids_for_link_with_auto_test
×
501

502
        return model
×
503

504
    @classmethod
2✔
505
    @adapter_logger
2✔
506
    def prepare_to_mass_create_autotest(
2✔
507
            cls,
508
            test_result: TestResult,
509
            project_id: str,
510
            work_item_ids_for_link_with_auto_test: list) -> AutoTestPostModel:
511
        logging.debug('Preparing to create the auto test ' + test_result.get_external_id())
×
512

513
        model = cls.test_result_to_autotest_post_model(
×
514
            test_result,
515
            project_id)
516
        model.work_item_ids_for_link_with_auto_test = work_item_ids_for_link_with_auto_test
×
517

518
        return model
×
519

520
    @classmethod
2✔
521
    @adapter_logger
2✔
522
    def prepare_to_update_autotest(
2✔
523
            cls,
524
            test_result: TestResult,
525
            autotest: AutoTestApiResult,
526
            project_id: str) -> UpdateAutoTestRequest:
527
        logging.debug('Preparing to update the auto test ' + test_result.get_external_id())
×
528

529
        model = cls.test_result_to_update_autotest_request(
×
530
            test_result,
531
            project_id)
532
        model.is_flaky = autotest.is_flaky
×
533
        # TODO: return after fix PUT/api/v2/autoTests
534
        # model.work_item_ids_for_link_with_auto_test = self.__get_work_item_uuids_for_link_with_auto_test(
535
        #     test_result.get_work_item_ids(),
536
        #     str(autotest.global_id))
537

538
        return model
×
539

540
    @classmethod
2✔
541
    @adapter_logger
2✔
542
    def prepare_to_mass_update_autotest(
2✔
543
            cls,
544
            test_result: TestResult,
545
            autotest: AutoTestApiResult,
546
            project_id: str) -> AutoTestPutModel:
547
        logging.debug('Preparing to update the auto test ' + test_result.get_external_id())
×
548

549
        model = cls.test_result_to_autotest_put_model(
×
550
            test_result,
551
            project_id)
552
        model.is_flaky = autotest.is_flaky
×
553
        # TODO: return after fix PUT/api/v2/autoTests
554
        # model.work_item_ids_for_link_with_auto_test = self.__get_work_item_uuids_for_link_with_auto_test(
555
        #     test_result.get_work_item_ids(),
556
        #     str(autotest.global_id))
557

558
        return model
×
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