testit-python-commons 3.2.0__tar.gz → 3.2.2__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 (36) hide show
  1. {testit_python_commons-3.2.0 → testit_python_commons-3.2.2}/PKG-INFO +1 -1
  2. {testit_python_commons-3.2.0 → testit_python_commons-3.2.2}/setup.py +1 -1
  3. {testit_python_commons-3.2.0 → testit_python_commons-3.2.2}/src/testit_python_commons/app_properties.py +12 -0
  4. {testit_python_commons-3.2.0 → testit_python_commons-3.2.2}/src/testit_python_commons/client/api_client.py +65 -26
  5. {testit_python_commons-3.2.0 → testit_python_commons-3.2.2}/src/testit_python_commons/client/client_configuration.py +4 -0
  6. testit_python_commons-3.2.2/src/testit_python_commons/services/retry.py +23 -0
  7. {testit_python_commons-3.2.0 → testit_python_commons-3.2.2}/src/testit_python_commons.egg-info/PKG-INFO +1 -1
  8. {testit_python_commons-3.2.0 → testit_python_commons-3.2.2}/src/testit_python_commons.egg-info/SOURCES.txt +1 -0
  9. {testit_python_commons-3.2.0 → testit_python_commons-3.2.2}/README.md +0 -0
  10. {testit_python_commons-3.2.0 → testit_python_commons-3.2.2}/setup.cfg +0 -0
  11. {testit_python_commons-3.2.0 → testit_python_commons-3.2.2}/src/testit.py +0 -0
  12. {testit_python_commons-3.2.0 → testit_python_commons-3.2.2}/src/testit_python_commons/__init__.py +0 -0
  13. {testit_python_commons-3.2.0 → testit_python_commons-3.2.2}/src/testit_python_commons/client/__init__.py +0 -0
  14. {testit_python_commons-3.2.0 → testit_python_commons-3.2.2}/src/testit_python_commons/client/converter.py +0 -0
  15. {testit_python_commons-3.2.0 → testit_python_commons-3.2.2}/src/testit_python_commons/decorators.py +0 -0
  16. {testit_python_commons-3.2.0 → testit_python_commons-3.2.2}/src/testit_python_commons/dynamic_methods.py +0 -0
  17. {testit_python_commons-3.2.0 → testit_python_commons-3.2.2}/src/testit_python_commons/models/__init__.py +0 -0
  18. {testit_python_commons-3.2.0 → testit_python_commons-3.2.2}/src/testit_python_commons/models/adapter_mode.py +0 -0
  19. {testit_python_commons-3.2.0 → testit_python_commons-3.2.2}/src/testit_python_commons/models/link.py +0 -0
  20. {testit_python_commons-3.2.0 → testit_python_commons-3.2.2}/src/testit_python_commons/models/link_type.py +0 -0
  21. {testit_python_commons-3.2.0 → testit_python_commons-3.2.2}/src/testit_python_commons/models/outcome_type.py +0 -0
  22. {testit_python_commons-3.2.0 → testit_python_commons-3.2.2}/src/testit_python_commons/models/step_result.py +0 -0
  23. {testit_python_commons-3.2.0 → testit_python_commons-3.2.2}/src/testit_python_commons/models/test_result.py +0 -0
  24. {testit_python_commons-3.2.0 → testit_python_commons-3.2.2}/src/testit_python_commons/models/test_result_with_all_fixture_step_results_model.py +0 -0
  25. {testit_python_commons-3.2.0 → testit_python_commons-3.2.2}/src/testit_python_commons/services/__init__.py +0 -0
  26. {testit_python_commons-3.2.0 → testit_python_commons-3.2.2}/src/testit_python_commons/services/adapter_manager.py +0 -0
  27. {testit_python_commons-3.2.0 → testit_python_commons-3.2.2}/src/testit_python_commons/services/adapter_manager_configuration.py +0 -0
  28. {testit_python_commons-3.2.0 → testit_python_commons-3.2.2}/src/testit_python_commons/services/logger.py +0 -0
  29. {testit_python_commons-3.2.0 → testit_python_commons-3.2.2}/src/testit_python_commons/services/plugin_manager.py +0 -0
  30. {testit_python_commons-3.2.0 → testit_python_commons-3.2.2}/src/testit_python_commons/services/step_manager.py +0 -0
  31. {testit_python_commons-3.2.0 → testit_python_commons-3.2.2}/src/testit_python_commons/services/step_result_storage.py +0 -0
  32. {testit_python_commons-3.2.0 → testit_python_commons-3.2.2}/src/testit_python_commons/services/utils.py +0 -0
  33. {testit_python_commons-3.2.0 → testit_python_commons-3.2.2}/src/testit_python_commons/step.py +0 -0
  34. {testit_python_commons-3.2.0 → testit_python_commons-3.2.2}/src/testit_python_commons.egg-info/dependency_links.txt +0 -0
  35. {testit_python_commons-3.2.0 → testit_python_commons-3.2.2}/src/testit_python_commons.egg-info/requires.txt +0 -0
  36. {testit_python_commons-3.2.0 → testit_python_commons-3.2.2}/src/testit_python_commons.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: testit-python-commons
3
- Version: 3.2.0
3
+ Version: 3.2.2
4
4
  Summary: Python commons for Test IT
5
5
  Home-page: https://github.com/testit-tms/adapters-python/
6
6
  Author: Integration team
@@ -2,7 +2,7 @@ from setuptools import find_packages, setup
2
2
 
3
3
  setup(
4
4
  name='testit-python-commons',
5
- version='3.2.0',
5
+ version='3.2.2',
6
6
  description='Python commons for Test IT',
7
7
  long_description=open('README.md', "r").read(),
8
8
  long_description_content_type="text/markdown",
@@ -109,6 +109,10 @@ class AppProperties:
109
109
  option.set_automatic_creation_test_cases):
110
110
  cli_properties['automaticcreationtestcases'] = option.set_automatic_creation_test_cases
111
111
 
112
+ if hasattr(option, 'set_automatic_updation_links_to_test_cases') and cls.__check_property_value(
113
+ option.set_automatic_updation_links_to_test_cases):
114
+ cli_properties['automaticupdationlinkstotestcases'] = option.set_automatic_updation_links_to_test_cases
115
+
112
116
  return cli_properties
113
117
 
114
118
  @classmethod
@@ -156,6 +160,11 @@ class AppProperties:
156
160
  env_properties['automaticcreationtestcases'] = os.environ.get(
157
161
  f'{cls.__env_prefix}_AUTOMATIC_CREATION_TEST_CASES')
158
162
 
163
+ if f'{cls.__env_prefix}_AUTOMATIC_UPDATION_LINKS_TO_TEST_CASES' in os.environ.keys() and cls.__check_property_value(
164
+ os.environ.get(f'{cls.__env_prefix}_AUTOMATIC_UPDATION_LINKS_TO_TEST_CASES')):
165
+ env_properties['automaticupdationlinkstotestcases'] = os.environ.get(
166
+ f'{cls.__env_prefix}_AUTOMATIC_UPDATION_LINKS_TO_TEST_CASES')
167
+
159
168
  return env_properties
160
169
 
161
170
  @classmethod
@@ -214,6 +223,9 @@ class AppProperties:
214
223
  if not cls.__check_property_value(properties.get('automaticcreationtestcases')):
215
224
  properties['automaticcreationtestcases'] = 'false'
216
225
 
226
+ if not cls.__check_property_value(properties.get('automaticupdationlinkstotestcases')):
227
+ properties['automaticupdationlinkstotestcases'] = 'false'
228
+
217
229
  @staticmethod
218
230
  def __search_in_environ(var_name: str):
219
231
  if re.fullmatch(r'{[a-zA-Z_]\w*}', var_name) and var_name[1:-1] in os.environ:
@@ -14,30 +14,42 @@ from testit_api_client.models import (
14
14
  from testit_python_commons.client.client_configuration import ClientConfiguration
15
15
  from testit_python_commons.client.converter import Converter
16
16
  from testit_python_commons.models.test_result import TestResult
17
- from testit_python_commons.models.test_result_with_all_fixture_step_results_model import TestResultWithAllFixtureStepResults
17
+ from testit_python_commons.models.test_result_with_all_fixture_step_results_model import \
18
+ TestResultWithAllFixtureStepResults
18
19
  from testit_python_commons.services.logger import adapter_logger
20
+ from testit_python_commons.services.retry import retry
19
21
 
20
22
 
21
23
  class ApiClientWorker:
22
24
  def __init__(self, config: ClientConfiguration):
23
- client_config = Configuration(host=config.get_url())
24
-
25
- if config.get_cert_validation() == 'false':
26
- client_config.verify_ssl = False
27
-
28
- client_config.proxy = config.get_proxy()
29
-
30
- api_client = ApiClient(
31
- configuration=client_config,
32
- header_name='Authorization',
33
- header_value='PrivateToken ' + config.get_private_token()
34
- )
35
- self.__config = config
25
+ api_client_config = self.__get_api_client_configuration(
26
+ url=config.get_url(),
27
+ verify_ssl=config.get_cert_validation() != 'false',
28
+ proxy=config.get_proxy())
29
+ api_client = self.__get_api_client(api_client_config, config.get_private_token())
36
30
 
37
31
  self.__test_run_api = TestRunsApi(api_client=api_client)
38
32
  self.__autotest_api = AutoTestsApi(api_client=api_client)
39
33
  self.__attachments_api = AttachmentsApi(api_client=api_client)
40
34
  self.__test_results_api = TestResultsApi(api_client=api_client)
35
+ self.__config = config
36
+
37
+ @staticmethod
38
+ @adapter_logger
39
+ def __get_api_client_configuration(url: str, verify_ssl: bool = True, proxy: str = None) -> Configuration:
40
+ api_client_configuration = Configuration(host=url)
41
+ api_client_configuration.verify_ssl = verify_ssl
42
+ api_client_configuration.proxy = proxy
43
+
44
+ return api_client_configuration
45
+
46
+ @staticmethod
47
+ @adapter_logger
48
+ def __get_api_client(api_client_config: Configuration, token: str) -> ApiClient:
49
+ return ApiClient(
50
+ configuration=api_client_config,
51
+ header_name='Authorization',
52
+ header_value='PrivateToken ' + token)
41
53
 
42
54
  @adapter_logger
43
55
  def create_test_run(self):
@@ -76,16 +88,37 @@ class ApiClientWorker:
76
88
  self.__update_test(test_result, autotest[0]['is_flaky'])
77
89
 
78
90
  autotest_global_id = autotest[0]['id']
79
-
80
- self.__autotest_api.delete_auto_test_link_from_work_item(id=autotest_global_id)
81
91
  else:
82
92
  autotest_global_id = self.__create_test(test_result)
83
93
 
84
94
  if autotest_global_id:
85
- self.__link_test_to_work_item(autotest_global_id, test_result.get_work_item_ids())
95
+ self.__update_autotest_link_from_work_items(autotest_global_id, test_result.get_work_item_ids())
86
96
 
87
97
  return self.__load_test_result(test_result)
88
98
 
99
+ @adapter_logger
100
+ def __get_work_items_linked_to_autotest(self, autotest_global_id: str) -> list:
101
+ return self.__autotest_api.get_work_items_linked_to_auto_test(id=autotest_global_id)
102
+
103
+ @adapter_logger
104
+ def __update_autotest_link_from_work_items(self, autotest_global_id: str, work_item_ids: list):
105
+
106
+ linked_work_items = self.__get_work_items_linked_to_autotest(autotest_global_id)
107
+
108
+ for linked_work_item in linked_work_items:
109
+ linked_work_item_id = str(linked_work_item['global_id'])
110
+
111
+ if linked_work_item_id in work_item_ids:
112
+ work_item_ids.remove(linked_work_item_id)
113
+
114
+ continue
115
+
116
+ if self.__config.get_automatic_updation_links_to_test_cases() != 'false':
117
+ self.__unlink_test_to_work_item(autotest_global_id, linked_work_item_id)
118
+
119
+ for work_item_id in work_item_ids:
120
+ self.__link_test_to_work_item(autotest_global_id, work_item_id)
121
+
89
122
  @adapter_logger
90
123
  def __create_test(self, test_result: TestResult) -> str:
91
124
  logging.debug(f'Autotest "{test_result.get_autotest_name()}" was not found')
@@ -114,16 +147,22 @@ class ApiClientWorker:
114
147
  logging.debug(f'Autotest "{test_result.get_autotest_name()}" was updated')
115
148
 
116
149
  @adapter_logger
117
- def __link_test_to_work_item(self, autotest_global_id: str, work_item_ids: list):
118
- for work_item_id in work_item_ids:
119
- try:
120
- self.__autotest_api.link_auto_test_to_work_item(
121
- autotest_global_id,
122
- link_auto_test_to_work_item_request=LinkAutoTestToWorkItemRequest(id=work_item_id))
150
+ @retry
151
+ def __unlink_test_to_work_item(self, autotest_global_id: str, work_item_id: str):
152
+ self.__autotest_api.delete_auto_test_link_from_work_item(
153
+ id=autotest_global_id,
154
+ work_item_id=work_item_id)
123
155
 
124
- logging.debug(f'Autotest was linked with workItem "{work_item_id}" by global id "{autotest_global_id}')
125
- except Exception as exc:
126
- logging.error(f'Link with workItem "{work_item_id}" by global id "{autotest_global_id}" status: {exc}')
156
+ logging.debug(f'Autotest was unlinked with workItem "{work_item_id}" by global id "{autotest_global_id}')
157
+
158
+ @adapter_logger
159
+ @retry
160
+ def __link_test_to_work_item(self, autotest_global_id: str, work_item_id: str):
161
+ self.__autotest_api.link_auto_test_to_work_item(
162
+ autotest_global_id,
163
+ link_auto_test_to_work_item_request=LinkAutoTestToWorkItemRequest(id=work_item_id))
164
+
165
+ logging.debug(f'Autotest was linked with workItem "{work_item_id}" by global id "{autotest_global_id}')
127
166
 
128
167
  @adapter_logger
129
168
  def __load_test_result(self, test_result: TestResult) -> str:
@@ -20,6 +20,7 @@ class ClientConfiguration:
20
20
  self.__tms_proxy = app_properties.get('tmsproxy')
21
21
  self.__adapter_mode = app_properties.get('adaptermode')
22
22
  self.__cert_validation = app_properties.get('certvalidation')
23
+ self.__automatic_updation_links_to_test_cases = app_properties.get('automaticupdationlinkstotestcases')
23
24
 
24
25
  @adapter_logger
25
26
  def get_url(self):
@@ -63,3 +64,6 @@ class ClientConfiguration:
63
64
 
64
65
  def get_cert_validation(self):
65
66
  return self.__cert_validation
67
+
68
+ def get_automatic_updation_links_to_test_cases(self):
69
+ return self.__automatic_updation_links_to_test_cases
@@ -0,0 +1,23 @@
1
+ import logging
2
+ import random
3
+ import time
4
+
5
+ import testit_api_client
6
+
7
+
8
+ def retry(func):
9
+ def retry_wrapper(*args, **kwargs):
10
+ attempts = 0
11
+ retries = 10
12
+
13
+ while attempts < retries:
14
+ try:
15
+ return func(*args, **kwargs)
16
+ except testit_api_client.exceptions.ApiException as e:
17
+ sleep_time = random.randrange(0, 100)
18
+ time.sleep(sleep_time/100)
19
+ attempts += 1
20
+
21
+ logging.error(e)
22
+
23
+ return retry_wrapper
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: testit-python-commons
3
- Version: 3.2.0
3
+ Version: 3.2.2
4
4
  Summary: Python commons for Test IT
5
5
  Home-page: https://github.com/testit-tms/adapters-python/
6
6
  Author: Integration team
@@ -28,6 +28,7 @@ src/testit_python_commons/services/adapter_manager.py
28
28
  src/testit_python_commons/services/adapter_manager_configuration.py
29
29
  src/testit_python_commons/services/logger.py
30
30
  src/testit_python_commons/services/plugin_manager.py
31
+ src/testit_python_commons/services/retry.py
31
32
  src/testit_python_commons/services/step_manager.py
32
33
  src/testit_python_commons/services/step_result_storage.py
33
34
  src/testit_python_commons/services/utils.py