1212# limitations under the License
1313
1414"""This package is the base package for ReportPortal client."""
15- import typing
16- import warnings
15+
16+ import sys
17+ from typing import Optional , Tuple , TypedDict , Union
18+
19+ # noinspection PyUnreachableCode
20+ if sys .version_info >= (3 , 11 ):
21+ from typing import Unpack
22+ else :
23+ from typing_extensions import Unpack
1724
1825import aenum
1926
@@ -34,74 +41,94 @@ class ClientType(aenum.Enum):
3441 ASYNC_BATCHED = aenum .auto ()
3542
3643
44+ class _ClientOptions (TypedDict , total = False ):
45+ client_type : ClientType
46+ endpoint : str
47+ project : str
48+ api_key : Optional [str ]
49+ # OAuth 2.0 parameters
50+ oauth_uri : Optional [str ]
51+ oauth_username : Optional [str ]
52+ oauth_password : Optional [str ]
53+ oauth_client_id : Optional [str ]
54+ oauth_client_secret : Optional [str ]
55+ oauth_scope : Optional [str ]
56+ # Common client parameters
57+ launch_uuid : Optional [str ]
58+ is_skipped_an_issue : bool
59+ verify_ssl : Union [bool , str ]
60+ retries : int
61+ max_pool_size : int
62+ http_timeout : Union [float , Tuple [float , float ]]
63+ mode : str
64+ launch_uuid_print : bool
65+ print_output : OutputType
66+ truncate_attributes : bool
67+ log_batch_size : int
68+ log_batch_payload_limit : int
69+ # Async client specific parameters
70+ keepalive_timeout : float
71+ # Async threaded/batched client specific parameters
72+ task_timeout : float
73+ shutdown_timeout : float
74+ # Async batched client specific parameters
75+ trigger_num : int
76+ trigger_interval : float
77+
78+
3779# noinspection PyIncorrectDocstring
3880def create_client (
39- client_type : ClientType , endpoint : str , project : str , * , api_key : str = None , ** kwargs : typing . Any
40- ) -> typing . Optional [RP ]:
81+ client_type : ClientType , endpoint : str , project : str , ** kwargs : Unpack [ _ClientOptions ]
82+ ) -> Optional [RP ]:
4183 """Create and ReportPortal Client based on the type and arguments provided.
4284
4385 :param client_type: Type of the Client to create.
44- :type client_type: ClientType
4586 :param endpoint: Endpoint of the ReportPortal service.
46- :type endpoint: str
4787 :param project: Project name to report to.
48- :type project: str
4988 :param api_key: Authorization API key.
50- :type api_key: str
89+ :param oauth_uri: OAuth 2.0 token endpoint URI (for OAuth authentication).
90+ :param oauth_username: Username for OAuth 2.0 authentication.
91+ :param oauth_password: Password for OAuth 2.0 authentication.
92+ :param oauth_client_id: OAuth 2.0 client ID.
93+ :param oauth_client_secret: OAuth 2.0 client secret (optional).
94+ :param oauth_scope: OAuth 2.0 scope (optional).
5195 :param launch_uuid: A launch UUID to use instead of starting own one.
52- :type launch_uuid: str
5396 :param is_skipped_an_issue: Option to mark skipped tests as not 'To Investigate' items on the server
5497 side.
55- :type is_skipped_an_issue: bool
5698 :param verify_ssl: Option to skip ssl verification.
57- :type verify_ssl: typing.Union[bool, str]
5899 :param retries: Number of retry attempts to make in case of connection / server
59100 errors.
60- :type retries: int
61101 :param max_pool_size: Option to set the maximum number of connections to save the pool.
62- :type max_pool_size: int
63102 :param http_timeout : A float in seconds for connect and read timeout. Use a Tuple to
64103 specific connect and read separately.
65- :type http_timeout: Tuple[float, float]
66104 :param mode: Launch mode, all Launches started by the client will be in that mode.
67- :type mode: str
68105 :param launch_uuid_print: Print Launch UUID into passed TextIO or by default to stdout.
69- :type launch_uuid_print: bool
70106 :param print_output: Set output stream for Launch UUID printing.
71- :type print_output: OutputType
72107 :param truncate_attributes: Truncate test item attributes to default maximum length.
73- :type truncate_attributes: bool
74108 :param log_batch_size: Option to set the maximum number of logs that can be processed in one
75109 batch.
76- :type log_batch_size: int
77110 :param log_batch_payload_limit: Maximum size in bytes of logs that can be processed in one batch.
78- :type log_batch_payload_limit: int
79111 :param keepalive_timeout: For Async Clients only. Maximum amount of idle time in seconds before
80112 force connection closing.
81- :type keepalive_timeout: int
82113 :param task_timeout: For Async Threaded and Batched Clients only. Time limit in seconds for a
83114 Task processing.
84- :type task_timeout: float
85115 :param shutdown_timeout: For Async Threaded and Batched Clients only. Time limit in seconds for
86116 shutting down internal Tasks.
87- :type shutdown_timeout: float
88117 :param trigger_num: For Async Batched Client only. Number of tasks which triggers Task batch
89118 execution.
90- :type trigger_num: int
91119 :param trigger_interval: For Async Batched Client only. Time limit which triggers Task batch
92120 execution.
93- :type trigger_interval: float
94121 :return: ReportPortal Client instance.
95122 """
96123 if client_type is ClientType .SYNC :
97- return RPClient (endpoint , project , api_key = api_key , ** kwargs )
124+ return RPClient (endpoint , project , ** kwargs )
98125 if client_type is ClientType .ASYNC :
99- return AsyncRPClient (endpoint , project , api_key = api_key , ** kwargs )
126+ return AsyncRPClient (endpoint , project , ** kwargs )
100127 if client_type is ClientType .ASYNC_THREAD :
101- return ThreadedRPClient (endpoint , project , api_key = api_key , ** kwargs )
128+ return ThreadedRPClient (endpoint , project , ** kwargs )
102129 if client_type is ClientType .ASYNC_BATCHED :
103- return BatchedRPClient (endpoint , project , api_key = api_key , ** kwargs )
104- warnings . warn (f"Unknown ReportPortal Client type requested: { client_type } " , RuntimeWarning , stacklevel = 2 )
130+ return BatchedRPClient (endpoint , project , ** kwargs )
131+ raise ValueError (f"Unknown ReportPortal Client type requested: { client_type } " )
105132
106133
107134__all__ = [
0 commit comments