qase-python-commons 4.0.1__py3-none-any.whl → 4.1.1__py3-none-any.whl

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.

Potentially problematic release.


This version of qase-python-commons might be problematic. Click here for more details.

@@ -3,7 +3,7 @@ from typing import Union
3
3
 
4
4
  import certifi
5
5
  from qase.api_client_v1 import ApiClient, ProjectsApi, Project, EnvironmentsApi, RunsApi, AttachmentsApi, \
6
- AttachmentGet, RunCreate, ConfigurationsApi, ConfigurationCreate, ConfigurationGroupCreate
6
+ AttachmentGet, RunCreate, ConfigurationsApi, ConfigurationCreate, ConfigurationGroupCreate, RunPublic
7
7
  from qase.api_client_v1.configuration import Configuration
8
8
  from .. import Logger
9
9
  from .base_api_client import BaseApiClient
@@ -210,6 +210,37 @@ class ApiV1Client(BaseApiClient):
210
210
  return True
211
211
  return False
212
212
 
213
+ def enable_public_report(self, project_code: str, run_id: int) -> str:
214
+ """
215
+ Enable public report for a test run and return the public link
216
+
217
+ :param project_code: project code
218
+ :param run_id: test run id
219
+ :return: public report link or None if failed
220
+ """
221
+ try:
222
+ self.logger.log_debug(f"Enabling public report for run {run_id}")
223
+ api_runs = RunsApi(self.client)
224
+
225
+ # Create RunPublic object with status=True
226
+ run_public = RunPublic(status=True)
227
+
228
+ # Call the API to enable public report
229
+ response = api_runs.update_run_publicity(project_code, run_id, run_public)
230
+
231
+ # Extract the public URL from response
232
+ if response.result and response.result.url:
233
+ public_url = response.result.url
234
+ self.logger.log_debug(f"Public report enabled for run {run_id}: {public_url}")
235
+ return public_url
236
+ else:
237
+ self.logger.log_debug(f"Public report enabled for run {run_id} but no URL returned")
238
+ return None
239
+
240
+ except Exception as e:
241
+ self.logger.log(f"Error at enabling public report for run {run_id}: {e}", "error")
242
+ return None
243
+
213
244
  def update_external_link(self, project_code: str, run_id: int):
214
245
  """Update external link for a test run"""
215
246
  try:
@@ -86,3 +86,14 @@ class BaseApiClient(abc.ABC):
86
86
  :return: None
87
87
  """
88
88
  pass
89
+
90
+ @abc.abstractmethod
91
+ def enable_public_report(self, project_code: str, run_id: int) -> str:
92
+ """
93
+ Enable public report for a test run and return the public link
94
+
95
+ :param project_code: project code
96
+ :param run_id: test run id
97
+ :return: public report link or None if failed
98
+ """
99
+ pass
qase/commons/config.py CHANGED
@@ -1,18 +1,28 @@
1
1
  import os
2
2
  import json
3
- from .logger import Logger
3
+ from .logger import Logger, LoggingOptions
4
4
  from .models.config.qaseconfig import QaseConfig, Mode
5
+ from .utils import QaseUtils
5
6
 
6
7
 
7
8
  class ConfigManager:
8
9
 
9
10
  def __init__(self, config_file='./qase.config.json'):
10
- self.logger = Logger()
11
11
  self.__config_file = config_file
12
12
  self.config = QaseConfig()
13
13
 
14
+ # Initialize temporary logger for error handling during config loading
15
+ self.logger = Logger(debug=False)
16
+
14
17
  self.__load_file_config()
15
18
  self.__load_env_config()
19
+
20
+ # Re-initialize logger with proper logging options after config is loaded
21
+ logging_options = LoggingOptions(
22
+ console=self.config.logging.console if self.config.logging.console is not None else True,
23
+ file=self.config.logging.file if self.config.logging.file is not None else self.config.debug
24
+ )
25
+ self.logger = Logger(debug=self.config.debug, logging_options=logging_options)
16
26
 
17
27
  def validate_config(self):
18
28
  errors: list[str] = []
@@ -159,6 +169,11 @@ class ConfigManager:
159
169
  # Parse comma-separated string
160
170
  self.config.testops.set_status_filter([s.strip() for s in status_filter.split(',')])
161
171
 
172
+ if testops.get("showPublicReportLink") is not None:
173
+ self.config.testops.set_show_public_report_link(
174
+ testops.get("showPublicReportLink")
175
+ )
176
+
162
177
  if config.get("report"):
163
178
  report = config.get("report")
164
179
 
@@ -201,6 +216,9 @@ class ConfigManager:
201
216
  xfail_status.get("xpass")
202
217
  )
203
218
 
219
+ if config.get("logging"):
220
+ self.config.set_logging(config.get("logging"))
221
+
204
222
  except Exception as e:
205
223
  self.logger.log("Failed to load config from file", "error")
206
224
 
@@ -308,6 +326,9 @@ class ConfigManager:
308
326
  # Parse comma-separated string
309
327
  self.config.testops.set_status_filter([s.strip() for s in value.split(',')])
310
328
 
329
+ if key == 'QASE_TESTOPS_SHOW_PUBLIC_REPORT_LINK':
330
+ self.config.testops.set_show_public_report_link(value)
331
+
311
332
  if key == 'QASE_REPORT_DRIVER':
312
333
  self.config.report.set_driver(value)
313
334
 
@@ -326,5 +347,11 @@ class ConfigManager:
326
347
  if key == 'QASE_PYTEST_XFAIL_STATUS_XPASS':
327
348
  self.config.framework.pytest.xfail_status.set_xpass(value)
328
349
 
350
+ if key == 'QASE_LOGGING_CONSOLE':
351
+ self.config.logging.set_console(QaseUtils.parse_bool(value))
352
+
353
+ if key == 'QASE_LOGGING_FILE':
354
+ self.config.logging.set_file(QaseUtils.parse_bool(value))
355
+
329
356
  except Exception as e:
330
- self.logger.log("Failed to load config from env vars {e}", "error")
357
+ self.logger.log(f"Failed to load config from env vars {e}", "error")
qase/commons/logger.py CHANGED
@@ -1,14 +1,39 @@
1
1
  import os
2
2
  import datetime
3
3
  import threading
4
+ from typing import Optional
5
+
6
+
7
+ class LoggingOptions:
8
+ def __init__(self, console: bool = True, file: bool = False):
9
+ self.console = console
10
+ self.file = file
4
11
 
5
12
 
6
13
  class Logger:
7
14
  _log_file = None
8
15
 
9
- def __init__(self, debug: bool = False, prefix: str = '', dir: str = os.path.join('.', 'logs')) -> None:
16
+ def __init__(self, debug: bool = False, prefix: str = '', dir: str = os.path.join('.', 'logs'),
17
+ logging_options: Optional[LoggingOptions] = None) -> None:
10
18
  self.debug = debug
11
- if self.debug:
19
+ self.prefix = prefix
20
+ self.dir = dir
21
+
22
+ # Initialize logging options
23
+ if logging_options is None:
24
+ # Default behavior: console always enabled, file enabled only in debug mode
25
+ self.logging_options = LoggingOptions(
26
+ console=True,
27
+ file=debug
28
+ )
29
+ else:
30
+ self.logging_options = logging_options
31
+
32
+ # Override with environment variables if set
33
+ self._load_env_logging_options()
34
+
35
+ # Setup file logging if enabled
36
+ if self.logging_options.file:
12
37
  if Logger._log_file is None:
13
38
  timestamp = self._get_timestamp()
14
39
  filename = f'{prefix}_{timestamp}.log'
@@ -21,16 +46,38 @@ class Logger:
21
46
 
22
47
  self.lock = threading.Lock()
23
48
 
49
+ def _load_env_logging_options(self):
50
+ """Load logging options from environment variables"""
51
+ # QASE_LOGGING_CONSOLE
52
+ console_env = os.environ.get('QASE_LOGGING_CONSOLE')
53
+ if console_env is not None:
54
+ self.logging_options.console = console_env.lower() in ('true', '1', 'yes', 'on')
55
+
56
+ # QASE_LOGGING_FILE
57
+ file_env = os.environ.get('QASE_LOGGING_FILE')
58
+ if file_env is not None:
59
+ self.logging_options.file = file_env.lower() in ('true', '1', 'yes', 'on')
60
+
61
+ # Legacy QASE_DEBUG support
62
+ debug_env = os.environ.get('QASE_DEBUG')
63
+ if debug_env is not None and debug_env.lower() in ('true', '1', 'yes', 'on'):
64
+ # When debug is enabled via env, enable file logging if not explicitly disabled
65
+ if not hasattr(self.logging_options, 'file') or self.logging_options.file is None:
66
+ self.logging_options.file = True
67
+
24
68
  def log(self, message: str, level: str = 'info'):
25
69
  time_str = self._get_timestamp("%H:%M:%S")
26
70
  log = f"[Qase][{time_str}][{level}] {message}\n"
27
71
 
28
- try:
29
- print(log, end='')
30
- except (OSError, IOError):
31
- pass
72
+ # Console output
73
+ if self.logging_options.console:
74
+ try:
75
+ print(log, end='')
76
+ except (OSError, IOError):
77
+ pass
32
78
 
33
- if self.debug:
79
+ # File output
80
+ if self.logging_options.file:
34
81
  with self.lock:
35
82
  with open(Logger._log_file, 'a', encoding='utf-8') as f:
36
83
  f.write(log)
@@ -39,6 +86,15 @@ class Logger:
39
86
  if self.debug:
40
87
  self.log(message, 'debug')
41
88
 
89
+ def log_error(self, message: str):
90
+ self.log(message, 'error')
91
+
92
+ def log_warning(self, message: str):
93
+ self.log(message, 'warning')
94
+
95
+ def log_info(self, message: str):
96
+ self.log(message, 'info')
97
+
42
98
  @staticmethod
43
99
  def _get_timestamp(fmt: str = "%Y%m%d"):
44
100
  now = datetime.datetime.now()
@@ -1,5 +1,5 @@
1
1
  from enum import Enum
2
- from typing import List, Dict
2
+ from typing import List, Dict, Optional
3
3
 
4
4
  from .framework import Framework
5
5
  from .report import ReportConfig
@@ -14,6 +14,21 @@ class Mode(Enum):
14
14
  off = "off"
15
15
 
16
16
 
17
+ class LoggingConfig(BaseModel):
18
+ console: Optional[bool] = None
19
+ file: Optional[bool] = None
20
+
21
+ def __init__(self):
22
+ self.console = None
23
+ self.file = None
24
+
25
+ def set_console(self, console: bool):
26
+ self.console = console
27
+
28
+ def set_file(self, file: bool):
29
+ self.file = file
30
+
31
+
17
32
  class ExecutionPlan(BaseModel):
18
33
  path: str = None
19
34
 
@@ -37,6 +52,7 @@ class QaseConfig(BaseModel):
37
52
  framework: Framework = None
38
53
  exclude_params: list = None
39
54
  status_mapping: Dict[str, str] = None
55
+ logging: LoggingConfig = None
40
56
 
41
57
  def __init__(self):
42
58
  self.mode = Mode.off
@@ -49,6 +65,7 @@ class QaseConfig(BaseModel):
49
65
  self.profilers = []
50
66
  self.exclude_params = []
51
67
  self.status_mapping = {}
68
+ self.logging = LoggingConfig()
52
69
 
53
70
  def set_mode(self, mode: str):
54
71
  if any(mode == e.value for e in Mode.__members__.values()):
@@ -75,3 +92,9 @@ class QaseConfig(BaseModel):
75
92
 
76
93
  def set_status_mapping(self, status_mapping: Dict[str, str]):
77
94
  self.status_mapping = status_mapping
95
+
96
+ def set_logging(self, logging_config: dict):
97
+ if logging_config.get("console") is not None:
98
+ self.logging.set_console(QaseUtils.parse_bool(logging_config.get("console")))
99
+ if logging_config.get("file") is not None:
100
+ self.logging.set_file(QaseUtils.parse_bool(logging_config.get("file")))
@@ -49,6 +49,7 @@ class TestopsConfig(BaseModel):
49
49
  batch: BatchConfig = None
50
50
  configurations: ConfigurationsConfig = None
51
51
  status_filter: List[str] = None
52
+ show_public_report_link: bool = None
52
53
 
53
54
  def __init__(self):
54
55
  self.api = ApiConfig()
@@ -58,6 +59,7 @@ class TestopsConfig(BaseModel):
58
59
  self.configurations = ConfigurationsConfig()
59
60
  self.defect = False
60
61
  self.status_filter = []
62
+ self.show_public_report_link = False
61
63
 
62
64
  def set_project(self, project: str):
63
65
  self.project = project
@@ -67,3 +69,6 @@ class TestopsConfig(BaseModel):
67
69
 
68
70
  def set_status_filter(self, status_filter: List[str]):
69
71
  self.status_filter = status_filter
72
+
73
+ def set_show_public_report_link(self, show_public_report_link):
74
+ self.show_public_report_link = QaseUtils.parse_bool(show_public_report_link)
@@ -24,7 +24,8 @@ class QaseCoreReporter:
24
24
  reporter_name: Union[str, None] = None):
25
25
  config.validate_config()
26
26
  self.config = config.config
27
- self.logger = Logger(self.config.debug)
27
+ # Use the logger from ConfigManager instead of creating a new one
28
+ self.logger = config.logger
28
29
  self._execution_plan = None
29
30
  self.profilers = []
30
31
  self.overhead = 0
@@ -144,6 +144,18 @@ class QaseTestOps:
144
144
  self.logger.log_debug("Completing run")
145
145
  self.client.complete_run(self.project_code, self.run_id)
146
146
  self.logger.log_debug("Run completed")
147
+
148
+ # Enable public report if configured
149
+ if self.config.testops.show_public_report_link:
150
+ try:
151
+ self.logger.log_debug("Enabling public report")
152
+ public_url = self.client.enable_public_report(self.project_code, self.run_id)
153
+ if public_url:
154
+ self.logger.log(f"Public report link: {public_url}", "info")
155
+ else:
156
+ self.logger.log("Failed to generate public report link", "warning")
157
+ except Exception as e:
158
+ self.logger.log(f"Failed to generate public report link: {e}", "warning")
147
159
 
148
160
  def complete_worker(self) -> None:
149
161
  if len(self.results) > 0:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: qase-python-commons
3
- Version: 4.0.1
3
+ Version: 4.1.1
4
4
  Summary: A library for Qase TestOps and Qase Report
5
5
  Author-email: Qase Team <support@qase.io>
6
6
  Project-URL: Homepage, https://github.com/qase-tms/qase-python/tree/main/qase-python-commons
@@ -1,12 +1,12 @@
1
1
  qase/__init__.py,sha256=FLefSJnT6MTsTfZSDjMbMImI6674fAoJ5ZT3PNWGcRo,37
2
2
  qase/commons/__init__.py,sha256=3HI65PJES4Q6YvtkSuRPh6tZboTETJo8wbdHlNYaePU,323
3
- qase/commons/config.py,sha256=EnbPrICXG5kJ6lQGSQO4ZuBqikngmZVbH2bcCxR3qWk,14204
3
+ qase/commons/config.py,sha256=SyG1-2RfKQAhQLUbq7szbUUp9ABYvbSiaT8WdQEjMcA,15556
4
4
  qase/commons/loader.py,sha256=-MMY4HgSI6q1xq3NaJoq_w4liM73qdFKjYLVCT1E7Pc,1064
5
- qase/commons/logger.py,sha256=KEQr8G0eFZxlI3LJIaaNWOKD8o3NhKsZD06swXFn3FI,1313
5
+ qase/commons/logger.py,sha256=V_QTSDWNnUgd0j58rydYYN1AYOu3wa9T2fWjpOyxyuA,3430
6
6
  qase/commons/utils.py,sha256=utPRoYyThLs2tgD1lmjkwJ9KZuE7ZjliUiZkJJWFca0,3330
7
- qase/commons/client/api_v1_client.py,sha256=_dpvldRonALKubInPU03hYhyGJqxeq3DiIuyjDeOngg,11543
7
+ qase/commons/client/api_v1_client.py,sha256=BaE9Ix-k5Xc7Wiz8ILKKsWb5G5J3hqgjwaIcrocvCdY,12879
8
8
  qase/commons/client/api_v2_client.py,sha256=GsIrXJcBw6GtzvJjbjMYa0tvUIxEEe4pALRN2LBMKPM,9043
9
- qase/commons/client/base_api_client.py,sha256=qiK93rXXeLOmp6e3cgsLA4lmrV_rCL1BIi_xUeqFrDE,2613
9
+ qase/commons/client/base_api_client.py,sha256=4NtXhUxrxEPOBIzEAE-b50KHMwlhxwnSLGcYx8NMjbY,2961
10
10
  qase/commons/exceptions/reporter.py,sha256=dP-Mwcq8HKBOjgu3YqhyULDmDGU09BmT6Fh9HjICaUc,45
11
11
  qase/commons/models/__init__.py,sha256=FTt5dYASBX4r6-tQi-_JAUVx4uvJs9GTxROdAZEV6Jo,272
12
12
  qase/commons/models/attachment.py,sha256=cGfB0BaTDVfA7euJubKvi2cXXNvlSm_dy5x-ak3H3ec,1625
@@ -22,24 +22,24 @@ qase/commons/models/config/batch.py,sha256=X0H8SVOCCD2pV6LSMqjI-tIjRcLifnrM5Mare
22
22
  qase/commons/models/config/connection.py,sha256=wK2fGjc0G0rMVVhPnjw_t_M1YWZwANlhwl-awmI7XSo,516
23
23
  qase/commons/models/config/framework.py,sha256=sSWKQp18zxiS_79_XDH2hkHLpYEQnyH3bRquaT8XYYY,1803
24
24
  qase/commons/models/config/plan.py,sha256=JbAY7qfGXYreXOLa32OLxw6z0paeCCf87-2b1m8xkks,137
25
- qase/commons/models/config/qaseconfig.py,sha256=69uiGwgD9Pau1D5hMjGxFIMRKIKF9G_peQGc1DOLEI8,2111
25
+ qase/commons/models/config/qaseconfig.py,sha256=oWc03PKV8-jb3JNgs_tqQP-22wsKZW25eSaAacYl4no,2838
26
26
  qase/commons/models/config/report.py,sha256=g3Z2B3Tewaasjc1TMj2mkXxz0Zc1C39sHeTXH0MRM2Y,497
27
27
  qase/commons/models/config/run.py,sha256=UGE5PA_EyiFpfIev-TOob1BocxT1vdUdWW3ELMD58zQ,1239
28
- qase/commons/models/config/testops.py,sha256=rJ9wW-VMt-5XaoPdRUKeM9rlV0eTiRINEhEulFVczv0,1893
28
+ qase/commons/models/config/testops.py,sha256=LdylcNG1ctxjNHXwrwcerAKY3h0WByKWYIrKOzEV2K8,2133
29
29
  qase/commons/profilers/__init__.py,sha256=GhKT5hRbHbhAC4GhdyChA8XoAsGQOnIb8S2Z4-fdS7Q,222
30
30
  qase/commons/profilers/db.py,sha256=Am1tvvLgJq4_A8JsuSeBGf47BD2lnSX-5KiMjSgr-Ko,391
31
31
  qase/commons/profilers/network.py,sha256=zKNBnTQG4BMg8dn8O--tQzQLpu-qs5ADhHEnqIas0gM,4950
32
32
  qase/commons/profilers/sleep.py,sha256=HT6h0R-2XHZAoBYRxS2T_KC8RrnEoVjP7MXusaE4Nec,1624
33
33
  qase/commons/reporters/__init__.py,sha256=J0aNLzb_MPPT_zF8BtX_w9nj_U7Ad06RGpyWK5Pxq1o,169
34
- qase/commons/reporters/core.py,sha256=4MpiCGypoW0yso2BFjSvE3uTLCTbOinfwoIiYTdLIo4,9477
34
+ qase/commons/reporters/core.py,sha256=FJx1kxXkUz9vwkSAXapkNS3vF97Igvlq7Yyjp-4BpeI,9539
35
35
  qase/commons/reporters/report.py,sha256=ZLwtVn5gjwgJFtfbpLUO-vW3M3skEq3AhKJwtmM0nUw,4810
36
- qase/commons/reporters/testops.py,sha256=uph_8upIt5bu4ncqyK7ehXR9NqtpZ34wGUBFLVJKOpE,7481
36
+ qase/commons/reporters/testops.py,sha256=k3c91l_xuLq6NRLkzfwRqRTLfnpSxEQe38HNH8XMOTk,8161
37
37
  qase/commons/status_mapping/__init__.py,sha256=NPsWKDC7rGSCYfVunnGnHxL0_HmKWH7RBaMjWTH_Mtk,322
38
38
  qase/commons/status_mapping/status_mapping.py,sha256=kohSLNK6_qbMSP-M8gxHTTmOECgzDE3XvLqOzidPlYI,7213
39
39
  qase/commons/util/__init__.py,sha256=0sRRfrMOIPCHpk9tXM94Pj10qrk18B61qEcbLpRjw_I,74
40
40
  qase/commons/util/host_data.py,sha256=n8o5PDs8kELCZZ5GR7Jug6LsgZHWJudU7iRmZHRdrlw,5264
41
41
  qase/commons/validators/base.py,sha256=wwSn-4YiuXtfGMGnSKgo9Vm5hAKevVmmfd2Ro6Q7MYQ,173
42
- qase_python_commons-4.0.1.dist-info/METADATA,sha256=vZW1syFDf3ekHfwfHNEP1HG4LKOH9_do81VCE5hTGgg,1982
43
- qase_python_commons-4.0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
44
- qase_python_commons-4.0.1.dist-info/top_level.txt,sha256=Mn5aFk7H7Uia4s1NRDsvebu8vCrFy9nOuRIBfkIY5kQ,5
45
- qase_python_commons-4.0.1.dist-info/RECORD,,
42
+ qase_python_commons-4.1.1.dist-info/METADATA,sha256=4YhfVavjg9v0ZDrWFNhqF5h4n2WHbsYygN1LcQvyrNE,1982
43
+ qase_python_commons-4.1.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
44
+ qase_python_commons-4.1.1.dist-info/top_level.txt,sha256=Mn5aFk7H7Uia4s1NRDsvebu8vCrFy9nOuRIBfkIY5kQ,5
45
+ qase_python_commons-4.1.1.dist-info/RECORD,,