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

testit-tms / adapters-python / 17402521449

02 Sep 2025 11:47AM UTC coverage: 36.535% (-0.3%) from 36.848%
17402521449

Pull #200

github

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

31 of 78 new or added lines in 5 files covered. (39.74%)

4 existing lines in 2 files now uncovered.

1240 of 3394 relevant lines covered (36.54%)

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
    @staticmethod
2✔
40
    @adapter_logger
2✔
41
    def test_run_to_test_run_short_model(project_id: str, name: str) -> CreateEmptyRequest:
2✔
42
        return CreateEmptyRequest(
×
43
            project_id=project_id,
44
            name=name
45
        )
46

47
    @staticmethod
2✔
48
    @adapter_logger
2✔
49
    def get_id_from_create_test_run_response(response: TestRunV2ApiResult) -> str:
2✔
50
        return response.id
×
51

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

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

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

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

NEW
88
        return ApiV2AutoTestsSearchPostRequest(filter=autotests_filter, includes=autotests_includes)
×
89

90
    @staticmethod
2✔
91
    @adapter_logger
2✔
92
    def get_global_ids_from_autotest_response_list (
2✔
93
            autotests: typing.List[TestResultShortResponse],
94
            configuration: str) -> typing.List[int]:
UNCOV
95
        resolved_autotests = []
×
96

97
        for autotest in autotests:
×
98
            if configuration == autotest.configuration_id:
×
NEW
99
                resolved_autotests.append(autotest.autotest_global_id)
×
100

101
        return resolved_autotests
×
102

103
    @staticmethod
2✔
104
    def autotest_results_to_external_ids(
2✔
105
            autotests: typing.List[AutoTestApiResult]) -> typing.List[str]:
NEW
106
        external_ids = []
×
107

NEW
108
        for autotest in autotests:
×
NEW
109
            external_id = autotest.external_id
×
110

NEW
111
            if external_id is None:
×
NEW
112
                continue
×
113

NEW
114
            external_ids.append(external_id)
×
115

NEW
116
        return external_ids
×
117

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

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

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

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

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

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

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

318
    @classmethod
2✔
319
    @adapter_logger
2✔
320
    def get_test_result_id_from_testrun_result_post_response(cls, response) -> str:
2✔
321
        return response[0]
×
322

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

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

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

366
        for link in links:
×
367
            post_model_links.append(
×
368
                cls.link_to_link_post_model(link)
369
            )
370

371
        return post_model_links
×
372

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

378
        for link in links:
×
379
            put_model_links.append(
×
380
                cls.link_to_link_put_model(link)
381
            )
382

383
        return put_model_links
×
384

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

391
        for attachment in attachments:
×
392
            put_model_attachments.append(
×
393
                cls.attachment_model_to_attachment_put_model(attachment)
394
            )
395

396
        return put_model_attachments
×
397

398
    @staticmethod
2✔
399
    @adapter_logger
2✔
400
    def attachment_model_to_attachment_put_model(attachment: AttachmentApiResult) -> AttachmentUpdateRequest:
2✔
401
        return AttachmentUpdateRequest(id=attachment.id)
×
402

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

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

418
        return autotest_model_steps
×
419

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

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

442
        return autotest_model_step_results
×
443

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

451
        for external_id, test_result_id in test_result_ids.items():
×
452
            test_result_with_all_fixture_step_results = TestResultWithAllFixtureStepResults(test_result_id)
×
453

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

459
                    if fixtures_container.afters:
×
460
                        test_result_with_all_fixture_step_results.set_teardown_results(
×
461
                            fixtures_container.afters[0].steps)
462

463
            test_results_with_all_fixture_step_results.append(test_result_with_all_fixture_step_results)
×
464

465
        return test_results_with_all_fixture_step_results
×
466

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

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

489
        return autotest_model_step_results
×
490

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

500
        model = cls.test_result_to_create_autotest_request(
×
501
            test_result,
502
            project_id)
503
        model.work_item_ids_for_link_with_auto_test = work_item_ids_for_link_with_auto_test
×
504

505
        return model
×
506

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

516
        model = cls.test_result_to_autotest_post_model(
×
517
            test_result,
518
            project_id)
519
        model.work_item_ids_for_link_with_auto_test = work_item_ids_for_link_with_auto_test
×
520

521
        return model
×
522

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

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

541
        return model
×
542

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

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

561
        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