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

testit-tms / adapters-python / 17916648770

22 Sep 2025 01:20PM UTC coverage: 40.025% (+3.0%) from 37.068%
17916648770

push

github

web-flow
feat: TMS-33268: support the "status code" field. (#200)

* feat: TMS-33268: support the "status code" field.

* fix: add the types of input and return values.

* fix: fix the names of the methods for api_client and converter.

* feat: support the AutotestExternalId field from the TestResultShortResponse model.

---------

Co-authored-by: pavel.butuzov <pavel.butuzov@testit.software>

29 of 57 new or added lines in 5 files covered. (50.88%)

3 existing lines in 2 files now uncovered.

1280 of 3198 relevant lines covered (40.03%)

0.8 hits per line

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

51.72
/testit-python-commons/src/testit_python_commons/client/converter.py
1
import logging
2✔
2
from typing import List
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: 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_external_ids_from_autotest_response_list(
2✔
93
            autotests: List[TestResultShortResponse],
94
            configuration: str) -> List[str]:
NEW
95
        external_ids: List[str] = []
×
96

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

NEW
101
        return external_ids
×
102

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

129
    @classmethod
2✔
130
    @adapter_logger
2✔
131
    def test_result_to_create_autotest_request(
2✔
132
            cls,
133
            test_result: TestResult,
134
            project_id: str) -> CreateAutoTestRequest:
135
        return CreateAutoTestRequest(
×
136
            external_id=test_result.get_external_id(),
137
            project_id=project_id,
138
            name=test_result.get_autotest_name(),
139
            steps=cls.step_results_to_autotest_steps_model(
140
                test_result.get_step_results()),
141
            setup=cls.step_results_to_autotest_steps_model(
142
                test_result.get_setup_results()),
143
            teardown=cls.step_results_to_autotest_steps_model(
144
                test_result.get_teardown_results()),
145
            namespace=test_result.get_namespace(),
146
            classname=test_result.get_classname(),
147
            title=test_result.get_title(),
148
            description=test_result.get_description(),
149
            links=cls.links_to_links_post_model(test_result.get_links()),
150
            labels=test_result.get_labels(),
151
            should_create_work_item=test_result.get_automatic_creation_test_cases(),
152
            external_key=test_result.get_external_key()
153
        )
154

155
    @classmethod
2✔
156
    @adapter_logger
2✔
157
    def test_result_to_autotest_put_model(
2✔
158
            cls,
159
            test_result: TestResult,
160
            project_id: str) -> AutoTestPutModel:
161
        if test_result.get_outcome() == 'Passed':
×
162
            return AutoTestPutModel(
×
163
                external_id=test_result.get_external_id(),
164
                project_id=project_id,
165
                name=test_result.get_autotest_name(),
166
                steps=cls.step_results_to_autotest_steps_model(
167
                    test_result.get_step_results()),
168
                setup=cls.step_results_to_autotest_steps_model(
169
                    test_result.get_setup_results()),
170
                teardown=cls.step_results_to_autotest_steps_model(
171
                    test_result.get_teardown_results()),
172
                namespace=test_result.get_namespace(),
173
                classname=test_result.get_classname(),
174
                title=test_result.get_title(),
175
                description=test_result.get_description(),
176
                links=cls.links_to_links_put_model(test_result.get_links()),
177
                labels=test_result.get_labels(),
178
                external_key=test_result.get_external_key()
179
            )
180
        else:
181
            return AutoTestPutModel(
×
182
                external_id=test_result.get_external_id(),
183
                project_id=project_id,
184
                name=test_result.get_autotest_name(),
185
                steps=cls.step_results_to_autotest_steps_model(
186
                    test_result.get_step_results()),
187
                setup=cls.step_results_to_autotest_steps_model(
188
                    test_result.get_setup_results()),
189
                teardown=cls.step_results_to_autotest_steps_model(
190
                    test_result.get_teardown_results()),
191
                namespace=test_result.get_namespace(),
192
                classname=test_result.get_classname(),
193
                title=test_result.get_title(),
194
                description=test_result.get_description(),
195
                links=cls.links_to_links_put_model(test_result.get_links()),
196
                labels=test_result.get_labels(),
197
                external_key=test_result.get_external_key()
198
            )
199

200
    @classmethod
2✔
201
    @adapter_logger
2✔
202
    def test_result_to_update_autotest_request(
2✔
203
            cls,
204
            test_result: TestResult,
205
            project_id: str) -> UpdateAutoTestRequest:
206
        if test_result.get_outcome() == 'Passed':
×
207
            return UpdateAutoTestRequest(
×
208
                external_id=test_result.get_external_id(),
209
                project_id=project_id,
210
                name=test_result.get_autotest_name(),
211
                steps=cls.step_results_to_autotest_steps_model(
212
                    test_result.get_step_results()),
213
                setup=cls.step_results_to_autotest_steps_model(
214
                    test_result.get_setup_results()),
215
                teardown=cls.step_results_to_autotest_steps_model(
216
                    test_result.get_teardown_results()),
217
                namespace=test_result.get_namespace(),
218
                classname=test_result.get_classname(),
219
                title=test_result.get_title(),
220
                description=test_result.get_description(),
221
                links=cls.links_to_links_put_model(test_result.get_links()),
222
                labels=test_result.get_labels(),
223
                external_key=test_result.get_external_key()
224
            )
225
        else:
226
            return UpdateAutoTestRequest(
×
227
                external_id=test_result.get_external_id(),
228
                project_id=project_id,
229
                name=test_result.get_autotest_name(),
230
                steps=cls.step_results_to_autotest_steps_model(
231
                    test_result.get_step_results()),
232
                setup=cls.step_results_to_autotest_steps_model(
233
                    test_result.get_setup_results()),
234
                teardown=cls.step_results_to_autotest_steps_model(
235
                    test_result.get_teardown_results()),
236
                namespace=test_result.get_namespace(),
237
                classname=test_result.get_classname(),
238
                title=test_result.get_title(),
239
                description=test_result.get_description(),
240
                links=cls.links_to_links_put_model(test_result.get_links()),
241
                labels=test_result.get_labels(),
242
                external_key=test_result.get_external_key()
243
            )
244

245
    @classmethod
2✔
246
    @adapter_logger
2✔
247
    def test_result_to_testrun_result_post_model(
2✔
248
            cls,
249
            test_result: TestResult,
250
            configuration_id: str) -> AutoTestResultsForTestRunModel:
251
        return AutoTestResultsForTestRunModel(
×
252
            configuration_id=configuration_id,
253
            auto_test_external_id=test_result.get_external_id(),
254
            status_code=test_result.get_outcome(),
255
            step_results=cls.step_results_to_attachment_put_model_autotest_step_results_model(
256
                test_result.get_step_results()),
257
            setup_results=cls.step_results_to_attachment_put_model_autotest_step_results_model(
258
                test_result.get_setup_results()),
259
            teardown_results=cls.step_results_to_attachment_put_model_autotest_step_results_model(
260
                test_result.get_teardown_results()),
261
            traces=test_result.get_traces(),
262
            attachments=test_result.get_attachments(),
263
            parameters=test_result.get_parameters(),
264
            properties=test_result.get_properties(),
265
            links=cls.links_to_links_post_model(
266
                test_result.get_result_links()),
267
            duration=round(test_result.get_duration()),
268
            message=test_result.get_message(),
269
            started_on=test_result.get_started_on(),
270
            completed_on=test_result.get_completed_on()
271
        )
272

273
    @classmethod
2✔
274
    @adapter_logger
2✔
275
    def convert_test_result_model_to_test_results_id_put_request(
2✔
276
            cls,
277
            test_result: TestResultResponse) -> ApiV2TestResultsIdPutRequest:
278
        return ApiV2TestResultsIdPutRequest(
×
279
            failure_class_ids=test_result.failure_class_ids,
280
            status_code=test_result.status.code,
281
            comment=test_result.comment,
282
            links=test_result.links,
283
            step_results=test_result.step_results,
284
            attachments=cls.attachment_models_to_attachment_put_models(test_result.attachments),
285
            duration_in_ms=test_result.duration_in_ms,
286
            step_comments=test_result.step_comments,
287
            # setup_results=test_result.setup_results,
288
            # teardown_results=test_result.teardown_results,
289
            message=test_result.message,
290
            trace=test_result.traces)
291

292
    @classmethod
2✔
293
    @adapter_logger
2✔
294
    def convert_test_result_with_all_setup_and_teardown_steps_to_test_results_id_put_request(
2✔
295
            cls,
296
            test_result: TestResultWithAllFixtureStepResults) -> ApiV2TestResultsIdPutRequest:
297
        return ApiV2TestResultsIdPutRequest(
×
298
            setup_results=cls.step_results_to_attachment_put_model_autotest_step_results_model(
299
                test_result.get_setup_results()),
300
            teardown_results=cls.step_results_to_attachment_put_model_autotest_step_results_model(
301
                test_result.get_teardown_results()))
302

303
    @classmethod
2✔
304
    @adapter_logger
2✔
305
    def get_test_result_id_from_testrun_result_post_response(cls, response) -> str:
2✔
306
        return response[0]
×
307

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

327
    @staticmethod
2✔
328
    @adapter_logger
2✔
329
    def link_to_link_put_model(link: Link) -> LinkPutModel:
2✔
330
        if link.get_link_type():
×
331
            return LinkPutModel(
×
332
                url=link.get_url(),
333
                title=link.get_title(),
334
                type=LinkType(link.get_link_type()),
335
                description=link.get_description(),
336
                has_info=True,
337
            )
338
        else:
339
            return LinkPutModel(
×
340
                url=link.get_url(),
341
                title=link.get_title(),
342
                description=link.get_description(),
343
                has_info=True,
344
            )
345

346
    @classmethod
2✔
347
    @adapter_logger
2✔
348
    def links_to_links_post_model(cls, links: List[Link]) -> List[LinkPostModel]:
2✔
349
        post_model_links = []
×
350

351
        for link in links:
×
352
            post_model_links.append(
×
353
                cls.link_to_link_post_model(link)
354
            )
355

356
        return post_model_links
×
357

358
    @classmethod
2✔
359
    @adapter_logger
2✔
360
    def links_to_links_put_model(cls, links: List[Link]) -> List[LinkPutModel]:
2✔
361
        put_model_links = []
×
362

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

368
        return put_model_links
×
369

370
    @classmethod
2✔
371
    @adapter_logger
2✔
372
    def attachment_models_to_attachment_put_models(
2✔
373
            cls, attachments: List[AttachmentApiResult]) -> List[AttachmentUpdateRequest]:
374
        put_model_attachments = []
×
375

376
        for attachment in attachments:
×
377
            put_model_attachments.append(
×
378
                cls.attachment_model_to_attachment_put_model(attachment)
379
            )
380

381
        return put_model_attachments
×
382

383
    @staticmethod
2✔
384
    @adapter_logger
2✔
385
    def attachment_model_to_attachment_put_model(attachment: AttachmentApiResult) -> AttachmentUpdateRequest:
2✔
386
        return AttachmentUpdateRequest(id=attachment.id)
×
387

388
    @classmethod
2✔
389
    # @adapter_logger
390
    def step_results_to_autotest_steps_model(
2✔
391
            cls, step_results: List[StepResult]) -> List[AutoTestStepModel]:
392
        autotest_model_steps = []
×
393

394
        for step_result in step_results:
×
395
            autotest_model_steps.append(
×
396
                AutoTestStepModel(
397
                    title=step_result.get_title(),
398
                    description=step_result.get_description(),
399
                    steps=cls.step_results_to_autotest_steps_model(
400
                        step_result.get_step_results()))
401
            )
402

403
        return autotest_model_steps
×
404

405
    @classmethod
2✔
406
    @adapter_logger
2✔
407
    def step_results_to_attachment_put_model_autotest_step_results_model(
2✔
408
            cls, step_results: List[StepResult]) -> List[AttachmentPutModelAutoTestStepResultsModel]:
409
        autotest_model_step_results = []
×
410

411
        for step_result in step_results:
×
412
            autotest_model_step_results.append(
×
413
                AttachmentPutModelAutoTestStepResultsModel(
414
                    title=step_result.get_title(),
415
                    outcome=AvailableTestResultOutcome(step_result.get_outcome()),
416
                    description=step_result.get_description(),
417
                    duration=step_result.get_duration(),
418
                    parameters=step_result.get_parameters(),
419
                    attachments=step_result.get_attachments(),
420
                    started_on=step_result.get_started_on(),
421
                    completed_on=step_result.get_completed_on(),
422
                    step_results=cls.step_results_to_attachment_put_model_autotest_step_results_model(
423
                        step_result.get_step_results())
424
                )
425
            )
426

427
        return autotest_model_step_results
×
428

429
    @staticmethod
2✔
430
    @adapter_logger
2✔
431
    def fixtures_containers_to_test_results_with_all_fixture_step_results(
2✔
432
            fixtures_containers: dict,
433
            test_result_ids: dict) -> List[TestResultWithAllFixtureStepResults]:
434
        test_results_with_all_fixture_step_results = []
×
435

436
        for external_id, test_result_id in test_result_ids.items():
×
437
            test_result_with_all_fixture_step_results = TestResultWithAllFixtureStepResults(test_result_id)
×
438

439
            for uuid, fixtures_container in fixtures_containers.items():
×
440
                if external_id in fixtures_container.external_ids:
×
441
                    if fixtures_container.befores:
×
442
                        test_result_with_all_fixture_step_results.set_setup_results(fixtures_container.befores[0].steps)
×
443

444
                    if fixtures_container.afters:
×
445
                        test_result_with_all_fixture_step_results.set_teardown_results(
×
446
                            fixtures_container.afters[0].steps)
447

448
            test_results_with_all_fixture_step_results.append(test_result_with_all_fixture_step_results)
×
449

450
        return test_results_with_all_fixture_step_results
×
451

452
    @classmethod
2✔
453
    @adapter_logger
2✔
454
    def step_results_to_auto_test_step_result_update_request(
2✔
455
            cls, step_results: List[StepResult]) -> List[AutoTestStepResultUpdateRequest]:
456
        autotest_model_step_results = []
×
457

458
        for step_result in step_results:
×
459
            autotest_model_step_results.append(
×
460
                AutoTestStepResultUpdateRequest(
461
                    title=step_result.get_title(),
462
                    outcome=AvailableTestResultOutcome(step_result.get_outcome()),
463
                    description=step_result.get_description(),
464
                    duration=step_result.get_duration(),
465
                    parameters=step_result.get_parameters(),
466
                    attachments=step_result.get_attachments(),
467
                    started_on=step_result.get_started_on(),
468
                    completed_on=step_result.get_completed_on(),
469
                    step_results=cls.step_results_to_auto_test_step_result_update_request(
470
                        step_result.get_step_results())
471
                )
472
            )
473

474
        return autotest_model_step_results
×
475

476
    @classmethod
2✔
477
    @adapter_logger
2✔
478
    def prepare_to_create_autotest(
2✔
479
            cls,
480
            test_result: TestResult,
481
            project_id: str,
482
            work_item_ids_for_link_with_auto_test: list) -> CreateAutoTestRequest:
483
        logging.debug('Preparing to create the auto test ' + test_result.get_external_id())
×
484

485
        model = cls.test_result_to_create_autotest_request(
×
486
            test_result,
487
            project_id)
488
        model.work_item_ids_for_link_with_auto_test = work_item_ids_for_link_with_auto_test
×
489

490
        return model
×
491

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

501
        model = cls.test_result_to_autotest_post_model(
×
502
            test_result,
503
            project_id)
504
        model.work_item_ids_for_link_with_auto_test = work_item_ids_for_link_with_auto_test
×
505

506
        return model
×
507

508
    @classmethod
2✔
509
    @adapter_logger
2✔
510
    def prepare_to_update_autotest(
2✔
511
            cls,
512
            test_result: TestResult,
513
            autotest: AutoTestApiResult,
514
            project_id: str) -> UpdateAutoTestRequest:
515
        logging.debug('Preparing to update the auto test ' + test_result.get_external_id())
×
516

517
        model = cls.test_result_to_update_autotest_request(
×
518
            test_result,
519
            project_id)
520
        model.is_flaky = autotest.is_flaky
×
521
        # TODO: return after fix PUT/api/v2/autoTests
522
        # model.work_item_ids_for_link_with_auto_test = self.__get_work_item_uuids_for_link_with_auto_test(
523
        #     test_result.get_work_item_ids(),
524
        #     str(autotest.global_id))
525

526
        return model
×
527

528
    @classmethod
2✔
529
    @adapter_logger
2✔
530
    def prepare_to_mass_update_autotest(
2✔
531
            cls,
532
            test_result: TestResult,
533
            autotest: AutoTestApiResult,
534
            project_id: str) -> AutoTestPutModel:
535
        logging.debug('Preparing to update the auto test ' + test_result.get_external_id())
×
536

537
        model = cls.test_result_to_autotest_put_model(
×
538
            test_result,
539
            project_id)
540
        model.is_flaky = autotest.is_flaky
×
541
        # TODO: return after fix PUT/api/v2/autoTests
542
        # model.work_item_ids_for_link_with_auto_test = self.__get_work_item_uuids_for_link_with_auto_test(
543
        #     test_result.get_work_item_ids(),
544
        #     str(autotest.global_id))
545

546
        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