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

testit-tms / adapters-python / 17091364703

20 Aug 2025 07:15AM UTC coverage: 36.848% (+0.4%) from 36.441%
17091364703

Pull #199

github

web-flow
Merge a58423d45 into e79fbf989
Pull Request #199: fix: fix updating autotest links to workitems.

53 of 147 new or added lines in 3 files covered. (36.05%)

1 existing line in 1 file now uncovered.

1237 of 3357 relevant lines covered (36.85%)

0.74 hits per line

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

52.05
/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
    AutoTestApiResult,
6
    AttachmentPutModelAutoTestStepResultsModel,
7
    AutoTestStepResultUpdateRequest,
8
    CreateAutoTestRequest,
9
    UpdateAutoTestRequest,
10
    AutoTestPostModel,
11
    AutoTestPutModel,
12
    AutoTestResultsForTestRunModel,
13
    AutoTestStepModel,
14
    AvailableTestResultOutcome,
15
    LinkPostModel,
16
    LinkPutModel,
17
    LinkType,
18
    CreateEmptyRequest,
19
    TestRunV2ApiResult,
20
    AutoTestSearchApiModelFilter,
21
    AutoTestSearchApiModelIncludes,
22
    ApiV2AutoTestsSearchPostRequest,
23
    ApiV2TestResultsIdPutRequest,
24
    TestResultResponse,
25
    TestResultV2GetModel,
26
    AttachmentApiResult,
27
    AttachmentUpdateRequest
28
)
29

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

36

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

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

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

56
        return cls.__get_resolved_autotests(autotests, configuration)
×
57

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

70
        return ApiV2AutoTestsSearchPostRequest(filter=autotests_filter, includes=autotests_includes)
×
71

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

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

81
        return resolved_autotests
×
82

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

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

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

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

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

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

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

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

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

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

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

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

336
        return post_model_links
×
337

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

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

348
        return put_model_links
×
349

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

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

361
        return put_model_attachments
×
362

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

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

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

383
        return autotest_model_steps
×
384

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

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

407
        return autotest_model_step_results
×
408

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

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

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

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

428
            test_results_with_all_fixture_step_results.append(test_result_with_all_fixture_step_results)
×
429

430
        return test_results_with_all_fixture_step_results
×
431

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

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

454
        return autotest_model_step_results
×
455

456
    @classmethod
2✔
457
    @adapter_logger
2✔
458
    def prepare_to_create_autotest(
2✔
459
            cls,
460
            test_result: TestResult,
461
            project_id: str,
462
            work_item_ids_for_link_with_auto_test: list) -> AutoTestPostModel:
NEW
463
        logging.debug('Preparing to create the auto test ' + test_result.get_external_id())
×
464

NEW
465
        model = cls.test_result_to_create_autotest_request(
×
466
            test_result,
467
            project_id)
NEW
468
        model.work_item_ids_for_link_with_auto_test = work_item_ids_for_link_with_auto_test
×
469

NEW
470
        return model
×
471

472
    @classmethod
2✔
473
    @adapter_logger
2✔
474
    def prepare_to_mass_create_autotest(
2✔
475
            cls,
476
            test_result: TestResult,
477
            project_id: str,
478
            work_item_ids_for_link_with_auto_test: list) -> AutoTestPostModel:
NEW
479
        logging.debug('Preparing to create the auto test ' + test_result.get_external_id())
×
480

NEW
481
        model = cls.test_result_to_autotest_post_model(
×
482
            test_result,
483
            project_id)
NEW
484
        model.work_item_ids_for_link_with_auto_test = work_item_ids_for_link_with_auto_test
×
485

NEW
486
        return model
×
487

488
    @classmethod
2✔
489
    @adapter_logger
2✔
490
    def prepare_to_update_autotest(
2✔
491
            cls,
492
            test_result: TestResult,
493
            autotest: AutoTestApiResult,
494
            project_id: str) -> UpdateAutoTestRequest:
NEW
495
        logging.debug('Preparing to update the auto test ' + test_result.get_external_id())
×
496

NEW
497
        model = cls.test_result_to_update_autotest_request(
×
498
            test_result,
499
            project_id)
NEW
500
        model.is_flaky = autotest.is_flaky
×
501
        # TODO: return after fix PUT/api/v2/autoTests
502
        # model.work_item_ids_for_link_with_auto_test = self.__get_work_item_uuids_for_link_with_auto_test(
503
        #     test_result.get_work_item_ids(),
504
        #     str(autotest.global_id))
505

NEW
506
        return model
×
507

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

NEW
517
        model = cls.test_result_to_autotest_put_model(
×
518
            test_result,
519
            project_id)
NEW
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

NEW
526
        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