testit-python-commons 3.8.0__tar.gz → 3.9.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/PKG-INFO +2 -2
  2. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/setup.py +2 -2
  3. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/src/testit_python_commons/client/api_client.py +6 -6
  4. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/src/testit_python_commons/client/converter.py +9 -9
  5. testit_python_commons-3.9.1/src/testit_python_commons/client/helpers/bulk_autotest_helper.py +222 -0
  6. testit_python_commons-3.9.1/src/testit_python_commons/client/helpers/threads_manager.py +86 -0
  7. testit_python_commons-3.9.1/src/testit_python_commons/client/models/__init__.py +8 -0
  8. testit_python_commons-3.9.1/src/testit_python_commons/client/models/threads_for_create_and_result.py +35 -0
  9. testit_python_commons-3.9.1/src/testit_python_commons/client/models/threads_for_update_and_result.py +45 -0
  10. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/src/testit_python_commons/models/test_result.py +12 -12
  11. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/src/testit_python_commons/models/test_result_with_all_fixture_step_results_model.py +5 -7
  12. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/src/testit_python_commons/services/step_manager.py +3 -3
  13. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/src/testit_python_commons/services/step_result_storage.py +2 -2
  14. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/src/testit_python_commons.egg-info/PKG-INFO +2 -2
  15. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/src/testit_python_commons.egg-info/SOURCES.txt +4 -0
  16. testit_python_commons-3.9.1/src/testit_python_commons.egg-info/requires.txt +3 -0
  17. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/tests/test_app_properties.py +1 -0
  18. testit_python_commons-3.8.0/src/testit_python_commons/client/helpers/bulk_autotest_helper.py +0 -158
  19. testit_python_commons-3.8.0/src/testit_python_commons.egg-info/requires.txt +0 -3
  20. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/README.md +0 -0
  21. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/setup.cfg +0 -0
  22. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/src/testit.py +0 -0
  23. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/src/testit_python_commons/__init__.py +0 -0
  24. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/src/testit_python_commons/app_properties.py +0 -0
  25. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/src/testit_python_commons/client/__init__.py +0 -0
  26. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/src/testit_python_commons/client/client_configuration.py +0 -0
  27. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/src/testit_python_commons/client/helpers/__init__.py +0 -0
  28. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/src/testit_python_commons/decorators.py +0 -0
  29. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/src/testit_python_commons/dynamic_methods.py +0 -0
  30. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/src/testit_python_commons/models/__init__.py +0 -0
  31. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/src/testit_python_commons/models/adapter_mode.py +0 -0
  32. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/src/testit_python_commons/models/fixture.py +0 -0
  33. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/src/testit_python_commons/models/link.py +0 -0
  34. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/src/testit_python_commons/models/link_type.py +0 -0
  35. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/src/testit_python_commons/models/outcome_type.py +0 -0
  36. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/src/testit_python_commons/models/step_result.py +0 -0
  37. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/src/testit_python_commons/services/__init__.py +0 -0
  38. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/src/testit_python_commons/services/adapter_manager.py +0 -0
  39. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/src/testit_python_commons/services/adapter_manager_configuration.py +0 -0
  40. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/src/testit_python_commons/services/fixture_manager.py +0 -0
  41. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/src/testit_python_commons/services/fixture_storage.py +0 -0
  42. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/src/testit_python_commons/services/logger.py +0 -0
  43. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/src/testit_python_commons/services/plugin_manager.py +0 -0
  44. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/src/testit_python_commons/services/retry.py +0 -0
  45. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/src/testit_python_commons/services/utils.py +0 -0
  46. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/src/testit_python_commons/step.py +0 -0
  47. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/src/testit_python_commons/utils/__init__.py +0 -0
  48. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/src/testit_python_commons/utils/html_escape_utils.py +0 -0
  49. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/src/testit_python_commons.egg-info/dependency_links.txt +0 -0
  50. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/src/testit_python_commons.egg-info/top_level.txt +0 -0
  51. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/tests/test_dynamic_methods.py +0 -0
  52. {testit_python_commons-3.8.0 → testit_python_commons-3.9.1}/tests/test_html_escape_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: testit-python-commons
3
- Version: 3.8.0
3
+ Version: 3.9.1
4
4
  Summary: Python commons for Test IT
5
5
  Home-page: https://github.com/testit-tms/adapters-python/
6
6
  Author: Integration team
@@ -17,7 +17,7 @@ Classifier: Programming Language :: Python :: 3.12
17
17
  Description-Content-Type: text/markdown
18
18
  Requires-Dist: pluggy
19
19
  Requires-Dist: tomli
20
- Requires-Dist: testit-api-client==7.0.1
20
+ Requires-Dist: testit-api-client==7.1.1
21
21
  Dynamic: author
22
22
  Dynamic: author-email
23
23
  Dynamic: classifier
@@ -1,6 +1,6 @@
1
1
  from setuptools import find_packages, setup
2
2
 
3
- VERSION = "3.8.0"
3
+ VERSION = "3.9.1"
4
4
 
5
5
  setup(
6
6
  name='testit-python-commons',
@@ -25,5 +25,5 @@ setup(
25
25
  py_modules=['testit', 'testit_python_commons'],
26
26
  packages=find_packages(where='src'),
27
27
  package_dir={'': 'src'},
28
- install_requires=['pluggy', 'tomli', 'testit-api-client==7.0.1']
28
+ install_requires=['pluggy', 'tomli', 'testit-api-client==7.1.1']
29
29
  )
@@ -1,6 +1,5 @@
1
1
  import logging
2
2
  import os
3
- import typing
4
3
  from datetime import datetime
5
4
 
6
5
  from testit_api_client import ApiClient, Configuration
@@ -23,6 +22,7 @@ from testit_python_commons.models.test_result import TestResult
23
22
  from testit_python_commons.services.logger import adapter_logger
24
23
  from testit_python_commons.services.retry import retry
25
24
  from testit_python_commons.utils.html_escape_utils import HtmlEscapeUtils
25
+ from typing import List
26
26
 
27
27
 
28
28
  class ApiClientWorker:
@@ -118,7 +118,7 @@ class ApiClientWorker:
118
118
  return self.__load_test_result(test_result)
119
119
 
120
120
  @adapter_logger
121
- def write_tests(self, test_results: typing.List[TestResult], fixture_containers: dict):
121
+ def write_tests(self, test_results: List[TestResult], fixture_containers: dict):
122
122
  bulk_autotest_helper = BulkAutotestHelper(self.__autotest_api, self.__test_run_api, self.__config)
123
123
 
124
124
  for test_result in test_results:
@@ -234,7 +234,7 @@ class ApiClientWorker:
234
234
  logging.error(f'Getting workitem by id {work_item_id} status: {exc}')
235
235
 
236
236
  @adapter_logger
237
- def __get_work_items_linked_to_autotest(self, autotest_global_id: str) -> typing.List[WorkItemIdentifierModel]:
237
+ def __get_work_items_linked_to_autotest(self, autotest_global_id: str) -> List[WorkItemIdentifierModel]:
238
238
  return self.__autotest_api.get_work_items_linked_to_auto_test(id=autotest_global_id)
239
239
 
240
240
  @adapter_logger
@@ -275,7 +275,7 @@ class ApiClientWorker:
275
275
  return autotest_response.id
276
276
 
277
277
  @adapter_logger
278
- def __create_tests(self, autotests_for_create: typing.List[AutoTestPostModel]):
278
+ def __create_tests(self, autotests_for_create: List[AutoTestPostModel]):
279
279
  logging.debug(f'Creating autotests: "{autotests_for_create}')
280
280
 
281
281
  autotests_for_create = self._escape_html_in_model(autotests_for_create)
@@ -298,7 +298,7 @@ class ApiClientWorker:
298
298
  logging.debug(f'Autotest "{test_result.get_autotest_name()}" was updated')
299
299
 
300
300
  @adapter_logger
301
- def __update_tests(self, autotests_for_update: typing.List[AutoTestPutModel]):
301
+ def __update_tests(self, autotests_for_update: List[AutoTestPutModel]):
302
302
  logging.debug(f'Updating autotests: {autotests_for_update}')
303
303
 
304
304
  autotests_for_update = self._escape_html_in_model(autotests_for_update)
@@ -341,7 +341,7 @@ class ApiClientWorker:
341
341
  return Converter.get_test_result_id_from_testrun_result_post_response(response)
342
342
 
343
343
  @adapter_logger
344
- def __load_test_results(self, test_results: typing.List[AutoTestResultsForTestRunModel]):
344
+ def __load_test_results(self, test_results: List[AutoTestResultsForTestRunModel]):
345
345
  logging.debug(f'Loading test results: {test_results}')
346
346
 
347
347
  test_results = self._escape_html_in_model(test_results)
@@ -1,5 +1,5 @@
1
1
  import logging
2
- import typing
2
+ from typing import List
3
3
 
4
4
  from testit_api_client.models import (
5
5
  AutoTestApiResult,
@@ -71,7 +71,7 @@ class Converter:
71
71
 
72
72
  @staticmethod
73
73
  @adapter_logger
74
- def __get_resolved_autotests(autotests: typing.List[TestResultV2GetModel], configuration: str):
74
+ def __get_resolved_autotests(autotests: List[TestResultV2GetModel], configuration: str):
75
75
  resolved_autotests = []
76
76
 
77
77
  for autotest in autotests:
@@ -325,7 +325,7 @@ class Converter:
325
325
 
326
326
  @classmethod
327
327
  @adapter_logger
328
- def links_to_links_post_model(cls, links: typing.List[Link]) -> typing.List[LinkPostModel]:
328
+ def links_to_links_post_model(cls, links: List[Link]) -> List[LinkPostModel]:
329
329
  post_model_links = []
330
330
 
331
331
  for link in links:
@@ -337,7 +337,7 @@ class Converter:
337
337
 
338
338
  @classmethod
339
339
  @adapter_logger
340
- def links_to_links_put_model(cls, links: typing.List[Link]) -> typing.List[LinkPutModel]:
340
+ def links_to_links_put_model(cls, links: List[Link]) -> List[LinkPutModel]:
341
341
  put_model_links = []
342
342
 
343
343
  for link in links:
@@ -350,7 +350,7 @@ class Converter:
350
350
  @classmethod
351
351
  @adapter_logger
352
352
  def attachment_models_to_attachment_put_models(
353
- cls, attachments: typing.List[AttachmentApiResult]) -> typing.List[AttachmentUpdateRequest]:
353
+ cls, attachments: List[AttachmentApiResult]) -> List[AttachmentUpdateRequest]:
354
354
  put_model_attachments = []
355
355
 
356
356
  for attachment in attachments:
@@ -368,7 +368,7 @@ class Converter:
368
368
  @classmethod
369
369
  # @adapter_logger
370
370
  def step_results_to_autotest_steps_model(
371
- cls, step_results: typing.List[StepResult]) -> typing.List[AutoTestStepModel]:
371
+ cls, step_results: List[StepResult]) -> List[AutoTestStepModel]:
372
372
  autotest_model_steps = []
373
373
 
374
374
  for step_result in step_results:
@@ -385,7 +385,7 @@ class Converter:
385
385
  @classmethod
386
386
  @adapter_logger
387
387
  def step_results_to_attachment_put_model_autotest_step_results_model(
388
- cls, step_results: typing.List[StepResult]) -> typing.List[AttachmentPutModelAutoTestStepResultsModel]:
388
+ cls, step_results: List[StepResult]) -> List[AttachmentPutModelAutoTestStepResultsModel]:
389
389
  autotest_model_step_results = []
390
390
 
391
391
  for step_result in step_results:
@@ -410,7 +410,7 @@ class Converter:
410
410
  @adapter_logger
411
411
  def fixtures_containers_to_test_results_with_all_fixture_step_results(
412
412
  fixtures_containers: dict,
413
- test_result_ids: dict) -> typing.List[TestResultWithAllFixtureStepResults]:
413
+ test_result_ids: dict) -> List[TestResultWithAllFixtureStepResults]:
414
414
  test_results_with_all_fixture_step_results = []
415
415
 
416
416
  for external_id, test_result_id in test_result_ids.items():
@@ -432,7 +432,7 @@ class Converter:
432
432
  @classmethod
433
433
  @adapter_logger
434
434
  def step_results_to_auto_test_step_result_update_request(
435
- cls, step_results: typing.List[StepResult]) -> typing.List[AutoTestStepResultUpdateRequest]:
435
+ cls, step_results: List[StepResult]) -> List[AutoTestStepResultUpdateRequest]:
436
436
  autotest_model_step_results = []
437
437
 
438
438
  for step_result in step_results:
@@ -0,0 +1,222 @@
1
+ import logging
2
+
3
+ from testit_api_client.apis import AutoTestsApi, TestRunsApi
4
+ from testit_api_client.models import (
5
+ AutoTestPostModel,
6
+ AutoTestPutModel,
7
+ AutoTestResultsForTestRunModel,
8
+ LinkAutoTestToWorkItemRequest,
9
+ WorkItemIdentifierModel
10
+ )
11
+
12
+ from testit_python_commons.client.client_configuration import ClientConfiguration
13
+ from testit_python_commons.client.helpers.threads_manager import ThreadsManager
14
+ from testit_python_commons.client.models import (
15
+ ThreadForCreateAndResult,
16
+ ThreadsForCreateAndResult,
17
+ ThreadForUpdateAndResult,
18
+ ThreadsForUpdateAndResult
19
+ )
20
+ from testit_python_commons.services.logger import adapter_logger
21
+ from testit_python_commons.services.retry import retry
22
+ from testit_python_commons.utils.html_escape_utils import HtmlEscapeUtils
23
+ from typing import Dict, List
24
+
25
+
26
+ class BulkAutotestHelper:
27
+ __max_tests_for_import = 100
28
+
29
+ def __init__(
30
+ self,
31
+ autotests_api: AutoTestsApi,
32
+ test_runs_api: TestRunsApi,
33
+ config: ClientConfiguration):
34
+ self.__autotests_api = autotests_api
35
+ self.__test_runs_api = test_runs_api
36
+ self.__test_run_id = config.get_test_run_id()
37
+ self.__automatic_updation_links_to_test_cases = config.get_automatic_updation_links_to_test_cases()
38
+ self.__threads_manager = ThreadsManager()
39
+
40
+ @adapter_logger
41
+ def add_for_create(
42
+ self,
43
+ create_model: AutoTestPostModel,
44
+ result_model: AutoTestResultsForTestRunModel):
45
+ thread_for_create_and_result: ThreadForCreateAndResult = self.__threads_manager.\
46
+ get_thread_for_create_and_result(create_model.external_id)
47
+
48
+ thread_for_create: Dict[str, AutoTestPostModel] = thread_for_create_and_result.get_thread_for_create()
49
+ thread_for_create[create_model.external_id] = create_model
50
+
51
+ thread_results_for_created_autotests: Dict[str, AutoTestResultsForTestRunModel] = thread_for_create_and_result\
52
+ .get_thread_results_for_created_autotests()
53
+ thread_results_for_created_autotests[result_model.auto_test_external_id] = result_model
54
+
55
+ if len(thread_for_create) >= self.__max_tests_for_import:
56
+ self.__teardown_for_create()
57
+
58
+ @adapter_logger
59
+ def add_for_update(
60
+ self,
61
+ update_model: AutoTestPutModel,
62
+ result_model: AutoTestResultsForTestRunModel,
63
+ autotest_links_to_wi_for_update: Dict[str, List[str]]):
64
+ thread_for_update_and_result: ThreadForUpdateAndResult = self.__threads_manager.\
65
+ get_thread_for_update_and_result(update_model.external_id)
66
+
67
+ thread_for_update: Dict[str, AutoTestPutModel] = thread_for_update_and_result.get_thread_for_update()
68
+ thread_for_update[update_model.external_id] = update_model
69
+
70
+ thread_results_for_updated_autotests: Dict[str, AutoTestResultsForTestRunModel] = thread_for_update_and_result\
71
+ .get_thread_results_for_updated_autotests()
72
+ thread_results_for_updated_autotests[result_model.auto_test_external_id] = result_model
73
+
74
+ thread_for_autotest_links_to_wi_for_update: Dict[str, List[str]] = thread_for_update_and_result\
75
+ .get_thread_for_autotest_links_to_wi_for_update()
76
+ thread_for_autotest_links_to_wi_for_update.update(autotest_links_to_wi_for_update)
77
+
78
+ if len(thread_for_update) >= self.__max_tests_for_import:
79
+ self.__teardown_for_update()
80
+
81
+ @adapter_logger
82
+ def teardown(self):
83
+ self.__teardown_for_create()
84
+ self.__teardown_for_update()
85
+
86
+ def __teardown_for_create(self):
87
+ all_threads_for_create_and_result: ThreadsForCreateAndResult = self.__threads_manager\
88
+ .get_all_threads_for_create_and_result()
89
+
90
+ thread_for_create: Dict[str, AutoTestPostModel] = all_threads_for_create_and_result\
91
+ .get_threads_for_create()
92
+ autotests_for_create = list(thread_for_create.values())
93
+
94
+ if autotests_for_create:
95
+ self.__create_tests(autotests_for_create)
96
+
97
+ threads_results_for_created_autotests: List[Dict[str, AutoTestResultsForTestRunModel]] = all_threads_for_create_and_result\
98
+ .get_threads_results_for_created_autotests()
99
+
100
+ for thread_results_for_created_autotests in threads_results_for_created_autotests:
101
+ self.__load_test_results(list(thread_results_for_created_autotests.values()))
102
+
103
+ self.__threads_manager.delete_threads_for_create_and_result()
104
+
105
+ def __teardown_for_update(self):
106
+ all_threads_for_update_and_result: ThreadsForUpdateAndResult = self.__threads_manager\
107
+ .get_all_threads_for_update_and_result()
108
+
109
+ thread_for_update: Dict[str, AutoTestPutModel] = all_threads_for_update_and_result\
110
+ .get_threads_for_update()
111
+
112
+ autotests_for_update = list(thread_for_update.values())
113
+
114
+ if autotests_for_update:
115
+ self.__update_tests(autotests_for_update)
116
+
117
+ thread_for_autotest_links_to_wi_for_update: Dict[str, List[str]] = all_threads_for_update_and_result\
118
+ .get_threads_for_autotest_links_to_wi_for_update()
119
+
120
+ for autotest_id, work_item_ids in thread_for_autotest_links_to_wi_for_update.items():
121
+ self.__update_autotest_link_from_work_items(autotest_id, work_item_ids)
122
+
123
+ threads_results_for_updated_autotests: List[Dict[str, AutoTestResultsForTestRunModel]] = all_threads_for_update_and_result\
124
+ .get_threads_results_for_updated_autotests()
125
+
126
+ for thread_results_for_updated_autotests in threads_results_for_updated_autotests:
127
+ self.__load_test_results(list(thread_results_for_updated_autotests.values()))
128
+
129
+ self.__threads_manager.delete_threads_for_update_and_result()
130
+
131
+ @adapter_logger
132
+ def __bulk_create(
133
+ self,
134
+ thread_for_create: List[AutoTestPostModel],
135
+ thread_results_for_created_autotests: List[AutoTestResultsForTestRunModel]
136
+ ):
137
+ self.__create_tests(thread_for_create)
138
+ self.__load_test_results(thread_results_for_created_autotests)
139
+
140
+ @adapter_logger
141
+ def __bulk_update(
142
+ self,
143
+ thread_for_update: Dict[str, AutoTestPutModel],
144
+ thread_results_for_updated_autotests: List[AutoTestResultsForTestRunModel],
145
+ thread_for_autotest_links_to_wi_for_update: Dict[str, List[str]]
146
+ ):
147
+ self.__update_tests(list(thread_for_update.values()))
148
+ self.__load_test_results(thread_results_for_updated_autotests)
149
+
150
+ for autotest_id, work_item_ids in thread_for_autotest_links_to_wi_for_update.items():
151
+ self.__update_autotest_link_from_work_items(autotest_id, work_item_ids)
152
+
153
+ @adapter_logger
154
+ def __create_tests(self, autotests_for_create: List[AutoTestPostModel]):
155
+ logging.debug(f'Creating autotests: "{autotests_for_create}')
156
+
157
+ autotests_for_create = HtmlEscapeUtils.escape_html_in_object(autotests_for_create)
158
+ self.__autotests_api.create_multiple(auto_test_post_model=autotests_for_create)
159
+
160
+ logging.debug(f'Autotests were created')
161
+
162
+ @adapter_logger
163
+ def __update_tests(self, autotests_for_update: List[AutoTestPutModel]):
164
+ logging.debug(f'Updating autotests: {autotests_for_update}')
165
+
166
+ autotests_for_update = HtmlEscapeUtils.escape_html_in_object(autotests_for_update)
167
+ self.__autotests_api.update_multiple(auto_test_put_model=autotests_for_update)
168
+
169
+ logging.debug(f'Autotests were updated')
170
+
171
+ @adapter_logger
172
+ def __load_test_results(self, test_results: List[AutoTestResultsForTestRunModel]):
173
+ logging.debug(f'Loading test results: {test_results}')
174
+
175
+ test_results = HtmlEscapeUtils.escape_html_in_object(test_results)
176
+ self.__test_runs_api.set_auto_test_results_for_test_run(
177
+ id=self.__test_run_id,
178
+ auto_test_results_for_test_run_model=test_results)
179
+
180
+ # TODO: delete after fix PUT/api/v2/autoTests
181
+ @adapter_logger
182
+ def __get_work_items_linked_to_autotest(self, autotest_global_id: str) -> List[WorkItemIdentifierModel]:
183
+ return self.__autotests_api.get_work_items_linked_to_auto_test(id=autotest_global_id)
184
+
185
+ # TODO: delete after fix PUT/api/v2/autoTests
186
+ @adapter_logger
187
+ @retry
188
+ def __unlink_test_to_work_item(self, autotest_global_id: str, work_item_id: str):
189
+ self.__autotests_api.delete_auto_test_link_from_work_item(
190
+ id=autotest_global_id,
191
+ work_item_id=work_item_id)
192
+
193
+ logging.debug(f'Autotest was unlinked with workItem "{work_item_id}" by global id "{autotest_global_id}')
194
+
195
+ # TODO: delete after fix PUT/api/v2/autoTests
196
+ @adapter_logger
197
+ @retry
198
+ def __link_test_to_work_item(self, autotest_global_id: str, work_item_id: str):
199
+ self.__autotests_api.link_auto_test_to_work_item(
200
+ autotest_global_id,
201
+ link_auto_test_to_work_item_request=LinkAutoTestToWorkItemRequest(id=work_item_id))
202
+
203
+ logging.debug(f'Autotest was linked with workItem "{work_item_id}" by global id "{autotest_global_id}')
204
+
205
+ # TODO: delete after fix PUT/api/v2/autoTests
206
+ @adapter_logger
207
+ def __update_autotest_link_from_work_items(self, autotest_global_id: str, work_item_ids: list):
208
+ linked_work_items = self.__get_work_items_linked_to_autotest(autotest_global_id)
209
+
210
+ for linked_work_item in linked_work_items:
211
+ linked_work_item_id = str(linked_work_item.global_id)
212
+
213
+ if linked_work_item_id in work_item_ids:
214
+ work_item_ids.remove(linked_work_item_id)
215
+
216
+ continue
217
+
218
+ if self.__automatic_updation_links_to_test_cases != 'false':
219
+ self.__unlink_test_to_work_item(autotest_global_id, linked_work_item_id)
220
+
221
+ for work_item_id in work_item_ids:
222
+ self.__link_test_to_work_item(autotest_global_id, work_item_id)
@@ -0,0 +1,86 @@
1
+ from testit_api_client.models import (
2
+ AutoTestPostModel,
3
+ AutoTestPutModel,
4
+ AutoTestResultsForTestRunModel,
5
+ )
6
+
7
+ from testit_python_commons.client.models import (
8
+ ThreadForCreateAndResult,
9
+ ThreadsForCreateAndResult,
10
+ ThreadForUpdateAndResult,
11
+ ThreadsForUpdateAndResult
12
+ )
13
+ from testit_python_commons.services.logger import adapter_logger
14
+ from typing import Dict, List
15
+
16
+
17
+ class ThreadsManager:
18
+ def __init__(self):
19
+ self.__thread_for_create: Dict[str, AutoTestPostModel] = {}
20
+ self.__thread_for_update: Dict[str, AutoTestPutModel] = {}
21
+ self.__threads_results_for_created_autotests: List[Dict[str, AutoTestResultsForTestRunModel]] = []
22
+ self.__threads_results_for_updated_autotests: List[Dict[str, AutoTestResultsForTestRunModel]] = []
23
+ self.__thread_for_autotest_links_to_wi_for_update: Dict[str, List[str]] = {}
24
+
25
+ @adapter_logger
26
+ def get_thread_for_create_and_result(self, external_id: str) -> ThreadForCreateAndResult:
27
+ thread_results_for_created_autotests = self.__get_thread_results_for_created_autotests(external_id)
28
+
29
+ return ThreadForCreateAndResult(self.__thread_for_create, thread_results_for_created_autotests)
30
+
31
+ @adapter_logger
32
+ def get_all_threads_for_create_and_result(self) -> ThreadsForCreateAndResult:
33
+ return ThreadsForCreateAndResult(self.__thread_for_create, self.__threads_results_for_created_autotests)
34
+
35
+ @adapter_logger
36
+ def get_thread_for_update_and_result(self, external_id: str) -> ThreadForUpdateAndResult:
37
+ thread_results_for_updated_autotests = self.__get_thread_results_for_updated_autotests(external_id)
38
+
39
+ return ThreadForUpdateAndResult(
40
+ self.__thread_for_update,
41
+ thread_results_for_updated_autotests,
42
+ self.__thread_for_autotest_links_to_wi_for_update
43
+ )
44
+
45
+ @adapter_logger
46
+ def get_all_threads_for_update_and_result(self) -> ThreadsForUpdateAndResult:
47
+ return ThreadsForUpdateAndResult(
48
+ self.__thread_for_update,
49
+ self.__threads_results_for_updated_autotests,
50
+ self.__thread_for_autotest_links_to_wi_for_update
51
+ )
52
+
53
+ @adapter_logger
54
+ def delete_threads_for_create_and_result(self):
55
+ self.__thread_for_create.clear()
56
+ self.__threads_results_for_created_autotests.clear()
57
+
58
+ @adapter_logger
59
+ def delete_threads_for_update_and_result(self):
60
+ self.__thread_for_update.clear()
61
+ self.__threads_results_for_updated_autotests.clear()
62
+ self.__thread_for_autotest_links_to_wi_for_update.clear()
63
+
64
+ @adapter_logger
65
+ def __get_thread_results_for_created_autotests(self, external_id: str) -> Dict[str, AutoTestResultsForTestRunModel]:
66
+ for thread in self.__threads_results_for_created_autotests:
67
+ if external_id not in thread.keys():
68
+ return thread
69
+
70
+ new_thread: Dict[str, AutoTestResultsForTestRunModel] = {}
71
+
72
+ self.__threads_results_for_created_autotests.append(new_thread)
73
+
74
+ return new_thread
75
+
76
+ @adapter_logger
77
+ def __get_thread_results_for_updated_autotests(self, external_id: str) -> Dict[str, AutoTestResultsForTestRunModel]:
78
+ for thread in self.__threads_results_for_updated_autotests:
79
+ if external_id not in thread.keys():
80
+ return thread
81
+
82
+ new_thread: Dict[str, AutoTestResultsForTestRunModel] = {}
83
+
84
+ self.__threads_results_for_updated_autotests.append(new_thread)
85
+
86
+ return new_thread
@@ -0,0 +1,8 @@
1
+ from testit_python_commons.client.models.threads_for_create_and_result import (
2
+ ThreadForCreateAndResult,
3
+ ThreadsForCreateAndResult
4
+ )
5
+ from testit_python_commons.client.models.threads_for_update_and_result import (
6
+ ThreadForUpdateAndResult,
7
+ ThreadsForUpdateAndResult
8
+ )
@@ -0,0 +1,35 @@
1
+ from typing import Dict, List
2
+
3
+ from testit_api_client.models import AutoTestPostModel, AutoTestResultsForTestRunModel
4
+
5
+
6
+ class ThreadForCreateAndResult:
7
+ def __init__(
8
+ self,
9
+ thread_for_create: Dict[str, AutoTestPostModel],
10
+ thread_results_for_created_autotests: Dict[str, AutoTestResultsForTestRunModel]
11
+ ):
12
+ self.__thread_for_create = thread_for_create
13
+ self.__thread_results_for_created_autotests = thread_results_for_created_autotests
14
+
15
+ def get_thread_for_create(self) -> Dict[str, AutoTestPostModel]:
16
+ return self.__thread_for_create
17
+
18
+ def get_thread_results_for_created_autotests(self) -> Dict[str, AutoTestResultsForTestRunModel]:
19
+ return self.__thread_results_for_created_autotests
20
+
21
+
22
+ class ThreadsForCreateAndResult:
23
+ def __init__(
24
+ self,
25
+ threads_for_create: Dict[str, AutoTestPostModel],
26
+ threads_results_for_created_autotests: List[Dict[str, AutoTestResultsForTestRunModel]]
27
+ ):
28
+ self.__threads_for_create = threads_for_create
29
+ self.__threads_results_for_created_autotests = threads_results_for_created_autotests
30
+
31
+ def get_threads_for_create(self) -> Dict[str, AutoTestPostModel]:
32
+ return self.__threads_for_create
33
+
34
+ def get_threads_results_for_created_autotests(self) -> List[Dict[str, AutoTestResultsForTestRunModel]]:
35
+ return self.__threads_results_for_created_autotests
@@ -0,0 +1,45 @@
1
+ from typing import Dict, List
2
+
3
+ from testit_api_client.models import AutoTestPutModel, AutoTestResultsForTestRunModel
4
+
5
+
6
+ class ThreadForUpdateAndResult:
7
+ def __init__(
8
+ self,
9
+ thread_for_update: Dict[str, AutoTestPutModel],
10
+ thread_results_for_updated_autotests: Dict[str, AutoTestResultsForTestRunModel],
11
+ thread_for_autotest_links_to_wi_for_update: Dict[str, List[str]]
12
+ ):
13
+ self.__thread_for_update = thread_for_update
14
+ self.__thread_results_for_updated_autotests = thread_results_for_updated_autotests
15
+ self.__thread_for_autotest_links_to_wi_for_update = thread_for_autotest_links_to_wi_for_update
16
+
17
+ def get_thread_for_update(self) -> Dict[str, AutoTestPutModel]:
18
+ return self.__thread_for_update
19
+
20
+ def get_thread_results_for_updated_autotests(self) -> Dict[str, AutoTestResultsForTestRunModel]:
21
+ return self.__thread_results_for_updated_autotests
22
+
23
+ def get_thread_for_autotest_links_to_wi_for_update(self) -> Dict[str, List[str]]:
24
+ return self.__thread_for_autotest_links_to_wi_for_update
25
+
26
+
27
+ class ThreadsForUpdateAndResult:
28
+ def __init__(
29
+ self,
30
+ threads_for_update: Dict[str, AutoTestPutModel],
31
+ threads_results_for_updated_autotests: List[Dict[str, AutoTestResultsForTestRunModel]],
32
+ threads_for_autotest_links_to_wi_for_update: Dict[str, List[str]]
33
+ ):
34
+ self.__threads_for_update = threads_for_update
35
+ self.__threads_results_for_updated_autotests = threads_results_for_updated_autotests
36
+ self.__threads_for_autotest_links_to_wi_for_update = threads_for_autotest_links_to_wi_for_update
37
+
38
+ def get_threads_for_update(self) -> Dict[str, AutoTestPutModel]:
39
+ return self.__threads_for_update
40
+
41
+ def get_threads_results_for_updated_autotests(self) -> List[Dict[str, AutoTestResultsForTestRunModel]]:
42
+ return self.__threads_results_for_updated_autotests
43
+
44
+ def get_threads_for_autotest_links_to_wi_for_update(self) -> Dict[str, List[str]]:
45
+ return self.__threads_for_autotest_links_to_wi_for_update
@@ -1,4 +1,4 @@
1
- import typing
1
+ from typing import List
2
2
 
3
3
  from testit_python_commons.models.link import Link
4
4
  from testit_python_commons.models.step_result import StepResult
@@ -18,14 +18,14 @@ class TestResult:
18
18
  __classname: str = None
19
19
  __message: str = None
20
20
  __traces: str = None
21
- __step_results: typing.List[StepResult] = []
22
- __setup_results: typing.List[StepResult] = []
23
- __teardown_results: typing.List[StepResult] = []
24
- __links: typing.List[Link] = []
25
- __result_links: typing.List[Link] = []
26
- __attachments: typing.List[str] = []
27
- __labels: typing.List[str] = []
28
- __work_item_ids: typing.List[str] = []
21
+ __step_results: List[StepResult] = []
22
+ __setup_results: List[StepResult] = []
23
+ __teardown_results: List[StepResult] = []
24
+ __links: List[Link] = []
25
+ __result_links: List[Link] = []
26
+ __attachments: List[str] = []
27
+ __labels: List[str] = []
28
+ __work_item_ids: List[str] = []
29
29
  __parameters: dict = {}
30
30
  __properties: dict = {}
31
31
  __automatic_creation_test_cases: bool = False
@@ -158,7 +158,7 @@ class TestResult:
158
158
  return self
159
159
 
160
160
  @adapter_logger
161
- def get_step_results(self) -> typing.List[StepResult]:
161
+ def get_step_results(self) -> List[StepResult]:
162
162
  return self.__step_results
163
163
 
164
164
  @adapter_logger
@@ -168,7 +168,7 @@ class TestResult:
168
168
  return self
169
169
 
170
170
  @adapter_logger
171
- def get_setup_results(self) -> typing.List[StepResult]:
171
+ def get_setup_results(self) -> List[StepResult]:
172
172
  return self.__setup_results
173
173
 
174
174
  @adapter_logger
@@ -178,7 +178,7 @@ class TestResult:
178
178
  return self
179
179
 
180
180
  @adapter_logger
181
- def get_teardown_results(self) -> typing.List[StepResult]:
181
+ def get_teardown_results(self) -> List[StepResult]:
182
182
  return self.__teardown_results
183
183
 
184
184
  @adapter_logger
@@ -1,7 +1,5 @@
1
- import typing
2
-
3
1
  from testit_python_commons.models.step_result import StepResult
4
-
2
+ from typing import List
5
3
 
6
4
  class TestResultWithAllFixtureStepResults:
7
5
  def __init__(self, test_result_id: str):
@@ -12,18 +10,18 @@ class TestResultWithAllFixtureStepResults:
12
10
  def get_test_result_id(self) -> str:
13
11
  return self.__test_result_id
14
12
 
15
- def set_setup_results(self, setup_results: typing.List[StepResult]):
13
+ def set_setup_results(self, setup_results: List[StepResult]):
16
14
  self.__setup_results += setup_results
17
15
 
18
16
  return self
19
17
 
20
- def get_setup_results(self) -> typing.List[StepResult]:
18
+ def get_setup_results(self) -> List[StepResult]:
21
19
  return self.__setup_results
22
20
 
23
- def set_teardown_results(self, teardown_results: typing.List[StepResult]):
21
+ def set_teardown_results(self, teardown_results: List[StepResult]):
24
22
  self.__teardown_results = teardown_results + self.__teardown_results
25
23
 
26
24
  return self
27
25
 
28
- def get_teardown_results(self) -> typing.List[StepResult]:
26
+ def get_teardown_results(self) -> List[StepResult]:
29
27
  return self.__teardown_results
@@ -1,11 +1,11 @@
1
- import typing
1
+ from typing import List
2
2
 
3
3
  from testit_python_commons.models.step_result import StepResult
4
4
  from testit_python_commons.services.step_result_storage import StepResultStorage
5
5
 
6
6
 
7
7
  class StepManager:
8
- __steps_tree: typing.List[StepResult] = []
8
+ __steps_tree: List[StepResult] = []
9
9
 
10
10
  def __init__(self):
11
11
  self.__storage = StepResultStorage()
@@ -29,7 +29,7 @@ class StepManager:
29
29
  def get_active_step(self) -> StepResult:
30
30
  return self.__storage.get_last()
31
31
 
32
- def get_steps_tree(self) -> typing.List[StepResult]:
32
+ def get_steps_tree(self) -> List[StepResult]:
33
33
  steps_tree = self.__steps_tree.copy()
34
34
  self.__steps_tree.clear()
35
35
 
@@ -1,11 +1,11 @@
1
1
  import logging
2
- import typing
2
+ from typing import List
3
3
 
4
4
  from testit_python_commons.models.step_result import StepResult
5
5
 
6
6
 
7
7
  class StepResultStorage:
8
- __storage: typing.List[StepResult] = []
8
+ __storage: List[StepResult] = []
9
9
 
10
10
  def add(self, step_result: StepResult):
11
11
  self.__storage.append(step_result)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: testit-python-commons
3
- Version: 3.8.0
3
+ Version: 3.9.1
4
4
  Summary: Python commons for Test IT
5
5
  Home-page: https://github.com/testit-tms/adapters-python/
6
6
  Author: Integration team
@@ -17,7 +17,7 @@ Classifier: Programming Language :: Python :: 3.12
17
17
  Description-Content-Type: text/markdown
18
18
  Requires-Dist: pluggy
19
19
  Requires-Dist: tomli
20
- Requires-Dist: testit-api-client==7.0.1
20
+ Requires-Dist: testit-api-client==7.1.1
21
21
  Dynamic: author
22
22
  Dynamic: author-email
23
23
  Dynamic: classifier
@@ -17,6 +17,10 @@ src/testit_python_commons/client/client_configuration.py
17
17
  src/testit_python_commons/client/converter.py
18
18
  src/testit_python_commons/client/helpers/__init__.py
19
19
  src/testit_python_commons/client/helpers/bulk_autotest_helper.py
20
+ src/testit_python_commons/client/helpers/threads_manager.py
21
+ src/testit_python_commons/client/models/__init__.py
22
+ src/testit_python_commons/client/models/threads_for_create_and_result.py
23
+ src/testit_python_commons/client/models/threads_for_update_and_result.py
20
24
  src/testit_python_commons/models/__init__.py
21
25
  src/testit_python_commons/models/adapter_mode.py
22
26
  src/testit_python_commons/models/fixture.py
@@ -0,0 +1,3 @@
1
+ pluggy
2
+ tomli
3
+ testit-api-client==7.1.1
@@ -6,6 +6,7 @@ import pytest
6
6
 
7
7
  from testit_python_commons.app_properties import AppProperties
8
8
 
9
+
9
10
  class TestAppProperties:
10
11
  __properties_file = AppProperties._AppProperties__properties_file
11
12
  __env_prefix = AppProperties._AppProperties__env_prefix
@@ -1,158 +0,0 @@
1
- import logging
2
- import typing
3
-
4
- from testit_api_client.apis import AutoTestsApi, TestRunsApi
5
- from testit_api_client.models import (
6
- AutoTestPostModel,
7
- AutoTestPutModel,
8
- AutoTestResultsForTestRunModel,
9
- LinkAutoTestToWorkItemRequest,
10
- WorkItemIdentifierModel,
11
- )
12
-
13
- from testit_python_commons.client.client_configuration import ClientConfiguration
14
- from testit_python_commons.services.logger import adapter_logger
15
- from testit_python_commons.services.retry import retry
16
- from testit_python_commons.utils.html_escape_utils import HtmlEscapeUtils
17
-
18
-
19
- class BulkAutotestHelper:
20
- __max_tests_for_import = 100
21
-
22
- def __init__(
23
- self,
24
- autotests_api: AutoTestsApi,
25
- test_runs_api: TestRunsApi,
26
- config: ClientConfiguration):
27
- self.__autotests_api = autotests_api
28
- self.__test_runs_api = test_runs_api
29
- self.__test_run_id = config.get_test_run_id()
30
- self.__automatic_updation_links_to_test_cases = config.get_automatic_updation_links_to_test_cases()
31
- self.__autotests_for_create = []
32
- self.__autotests_for_update = []
33
- self.__autotest_links_to_wi_for_update = {}
34
- self.__results_for_autotests_being_created = []
35
- self.__results_for_autotests_being_updated = []
36
-
37
- @adapter_logger
38
- def add_for_create(
39
- self,
40
- create_model: AutoTestPostModel,
41
- result_model: AutoTestResultsForTestRunModel):
42
- self.__autotests_for_create.append(create_model)
43
- self.__results_for_autotests_being_created.append(result_model)
44
-
45
- if len(self.__autotests_for_create) >= self.__max_tests_for_import:
46
- self.__bulk_create()
47
-
48
- @adapter_logger
49
- def add_for_update(
50
- self,
51
- update_model: AutoTestPutModel,
52
- result_model: AutoTestResultsForTestRunModel,
53
- autotest_links_to_wi_for_update: dict):
54
- self.__autotests_for_update.append(update_model)
55
- self.__results_for_autotests_being_updated.append(result_model)
56
- self.__autotest_links_to_wi_for_update.update(autotest_links_to_wi_for_update)
57
-
58
- if len(self.__autotests_for_create) >= self.__max_tests_for_import:
59
- self.__bulk_update()
60
-
61
- @adapter_logger
62
- def teardown(self):
63
- if len(self.__autotests_for_create) > 0:
64
- self.__bulk_create()
65
-
66
- if len(self.__autotests_for_update) > 0:
67
- self.__bulk_update()
68
-
69
- @adapter_logger
70
- def __bulk_create(self):
71
- self.__create_tests(self.__autotests_for_create)
72
- self.__load_test_results(self.__results_for_autotests_being_created)
73
-
74
- self.__autotests_for_create.clear()
75
- self.__results_for_autotests_being_created.clear()
76
-
77
- @adapter_logger
78
- def __bulk_update(self):
79
- self.__update_tests(self.__autotests_for_update)
80
- self.__load_test_results(self.__results_for_autotests_being_updated)
81
-
82
- for autotest_id, work_item_ids in self.__autotest_links_to_wi_for_update.items():
83
- self.__update_autotest_link_from_work_items(autotest_id, work_item_ids)
84
-
85
- self.__autotests_for_update.clear()
86
- self.__results_for_autotests_being_updated.clear()
87
- self.__autotest_links_to_wi_for_update.clear()
88
-
89
- @adapter_logger
90
- def __create_tests(self, autotests_for_create: typing.List[AutoTestPostModel]):
91
- logging.debug(f'Creating autotests: "{autotests_for_create}')
92
-
93
- autotests_for_create = HtmlEscapeUtils.escape_html_in_object(autotests_for_create)
94
- self.__autotests_api.create_multiple(auto_test_post_model=autotests_for_create)
95
-
96
- logging.debug(f'Autotests were created')
97
-
98
- @adapter_logger
99
- def __update_tests(self, autotests_for_update: typing.List[AutoTestPutModel]):
100
- logging.debug(f'Updating autotests: {autotests_for_update}')
101
-
102
- autotests_for_update = HtmlEscapeUtils.escape_html_in_object(autotests_for_update)
103
- self.__autotests_api.update_multiple(auto_test_put_model=autotests_for_update)
104
-
105
- logging.debug(f'Autotests were updated')
106
-
107
- @adapter_logger
108
- def __load_test_results(self, test_results: typing.List[AutoTestResultsForTestRunModel]):
109
- logging.debug(f'Loading test results: {test_results}')
110
-
111
- test_results = HtmlEscapeUtils.escape_html_in_object(test_results)
112
- self.__test_runs_api.set_auto_test_results_for_test_run(
113
- id=self.__test_run_id,
114
- auto_test_results_for_test_run_model=test_results)
115
-
116
- # TODO: delete after fix PUT/api/v2/autoTests
117
- @adapter_logger
118
- def __get_work_items_linked_to_autotest(self, autotest_global_id: str) -> typing.List[WorkItemIdentifierModel]:
119
- return self.__autotests_api.get_work_items_linked_to_auto_test(id=autotest_global_id)
120
-
121
- # TODO: delete after fix PUT/api/v2/autoTests
122
- @adapter_logger
123
- @retry
124
- def __unlink_test_to_work_item(self, autotest_global_id: str, work_item_id: str):
125
- self.__autotests_api.delete_auto_test_link_from_work_item(
126
- id=autotest_global_id,
127
- work_item_id=work_item_id)
128
-
129
- logging.debug(f'Autotest was unlinked with workItem "{work_item_id}" by global id "{autotest_global_id}')
130
-
131
- # TODO: delete after fix PUT/api/v2/autoTests
132
- @adapter_logger
133
- @retry
134
- def __link_test_to_work_item(self, autotest_global_id: str, work_item_id: str):
135
- self.__autotests_api.link_auto_test_to_work_item(
136
- autotest_global_id,
137
- link_auto_test_to_work_item_request=LinkAutoTestToWorkItemRequest(id=work_item_id))
138
-
139
- logging.debug(f'Autotest was linked with workItem "{work_item_id}" by global id "{autotest_global_id}')
140
-
141
- # TODO: delete after fix PUT/api/v2/autoTests
142
- @adapter_logger
143
- def __update_autotest_link_from_work_items(self, autotest_global_id: str, work_item_ids: list):
144
- linked_work_items = self.__get_work_items_linked_to_autotest(autotest_global_id)
145
-
146
- for linked_work_item in linked_work_items:
147
- linked_work_item_id = str(linked_work_item.global_id)
148
-
149
- if linked_work_item_id in work_item_ids:
150
- work_item_ids.remove(linked_work_item_id)
151
-
152
- continue
153
-
154
- if self.__automatic_updation_links_to_test_cases != 'false':
155
- self.__unlink_test_to_work_item(autotest_global_id, linked_work_item_id)
156
-
157
- for work_item_id in work_item_ids:
158
- self.__link_test_to_work_item(autotest_global_id, work_item_id)
@@ -1,3 +0,0 @@
1
- pluggy
2
- tomli
3
- testit-api-client==7.0.1