@@ -137,6 +137,149 @@ def test_clone():
137137 )
138138
139139
140+ @mock .patch ("reportportal_client.aio.client.warnings.warn" )
141+ def test_deprecated_token_argument (warn ):
142+ """Test that deprecated token argument works and issues a warning."""
143+ api_key = "api_key"
144+ client = Client (endpoint = "http://endpoint" , project = "project" , token = api_key )
145+
146+ assert warn .call_count == 1
147+ assert client .api_key == api_key
148+
149+
150+ @mock .patch ("reportportal_client.aio.client.warnings.warn" )
151+ def test_api_key_argument (warn ):
152+ """Test that normal api_key argument works without warning."""
153+ api_key = "api_key"
154+ client = Client (endpoint = "http://endpoint" , project = "project" , api_key = api_key )
155+
156+ assert warn .call_count == 0
157+ assert client .api_key == api_key
158+
159+
160+ def test_empty_api_key_argument ():
161+ """Test that empty api_key raises ValueError."""
162+ api_key = ""
163+ with pytest .raises (ValueError ) as exc_info :
164+ Client (endpoint = "http://endpoint" , project = "project" , api_key = api_key )
165+
166+ assert "Authentication credentials are required" in str (exc_info .value )
167+
168+
169+ def test_oauth_authentication_parameters ():
170+ """Test that OAuth 2.0 authentication parameters work correctly."""
171+ client = Client (
172+ endpoint = "http://endpoint" ,
173+ project = "project" ,
174+ oauth_oauth_uri = "https://example.com/oauth/token" ,
175+ oauth_username = "test_user" ,
176+ oauth_password = "test_password" ,
177+ oauth_client_id = "test_client_id" ,
178+ oauth_client_secret = "test_client_secret" ,
179+ oauth_scope = "read write" ,
180+ )
181+
182+ assert client is not None
183+ assert client .oauth_uri == "https://example.com/oauth/token"
184+ assert client .oauth_username == "test_user"
185+ assert client .oauth_password == "test_password"
186+ assert client .oauth_client_id == "test_client_id"
187+ assert client .oauth_client_secret == "test_client_secret"
188+ assert client .oauth_scope == "read write"
189+ assert client .api_key is None
190+
191+
192+ def test_oauth_authentication_without_optional_parameters ():
193+ """Test OAuth authentication with only required parameters."""
194+ client = Client (
195+ endpoint = "http://endpoint" ,
196+ project = "project" ,
197+ oauth_oauth_uri = "https://example.com/oauth/token" ,
198+ oauth_username = "test_user" ,
199+ oauth_password = "test_password" ,
200+ oauth_client_id = "test_client_id" ,
201+ )
202+
203+ assert client is not None
204+ assert client .oauth_uri == "https://example.com/oauth/token"
205+ assert client .oauth_username == "test_user"
206+ assert client .oauth_password == "test_password"
207+ assert client .oauth_client_id == "test_client_id"
208+ assert client .oauth_client_secret is None
209+ assert client .oauth_scope is None
210+ assert client .api_key is None
211+
212+
213+ def test_no_authentication_parameters ():
214+ """Test that missing authentication parameters raises ValueError."""
215+ with pytest .raises (ValueError ) as exc_info :
216+ Client (endpoint = "http://endpoint" , project = "project" )
217+
218+ assert "Authentication credentials are required" in str (exc_info .value )
219+ assert "OAuth 2.0 parameters" in str (exc_info .value )
220+ assert "api_key parameter" in str (exc_info .value )
221+
222+
223+ def test_partial_oauth_parameters ():
224+ """Test that missing authentication parameters raises ValueError."""
225+ with pytest .raises (ValueError ) as exc_info :
226+ Client (
227+ endpoint = "http://endpoint" ,
228+ project = "project" ,
229+ oauth_oauth_uri = "https://example.com/oauth/token" ,
230+ oauth_username = "test_user" ,
231+ oauth_password = "test_password" ,
232+ )
233+
234+ assert "Authentication credentials are required" in str (exc_info .value )
235+ assert "OAuth 2.0 parameters" in str (exc_info .value )
236+ assert "api_key parameter" in str (exc_info .value )
237+
238+
239+ def test_clone_with_oauth ():
240+ """Test cloning a client with OAuth authentication."""
241+ args = ["http://endpoint" , "project" ]
242+ kwargs = {
243+ "oauth_oauth_uri" : "https://example.com/oauth/token" ,
244+ "oauth_username" : "test_user" ,
245+ "oauth_password" : "test_password" ,
246+ "oauth_client_id" : "test_client_id" ,
247+ "oauth_client_secret" : "test_secret" ,
248+ "oauth_scope" : "read write" ,
249+ "is_skipped_an_issue" : False ,
250+ "verify_ssl" : False ,
251+ "retries" : 5 ,
252+ "max_pool_size" : 30 ,
253+ "http_timeout" : (30 , 30 ),
254+ "keepalive_timeout" : 25 ,
255+ "mode" : "DEBUG" ,
256+ "launch_uuid_print" : True ,
257+ "print_output" : OutputType .STDERR ,
258+ }
259+ client = Client (* args , ** kwargs )
260+ cloned = client .clone ()
261+
262+ assert cloned is not None and client is not cloned
263+ assert cloned .endpoint == args [0 ] and cloned .project == args [1 ]
264+ assert (
265+ cloned .oauth_uri == kwargs ["oauth_oauth_uri" ]
266+ and cloned .oauth_username == kwargs ["oauth_username" ]
267+ and cloned .oauth_password == kwargs ["oauth_password" ]
268+ and cloned .oauth_client_id == kwargs ["oauth_client_id" ]
269+ and cloned .oauth_client_secret == kwargs ["oauth_client_secret" ]
270+ and cloned .oauth_scope == kwargs ["oauth_scope" ]
271+ and cloned .is_skipped_an_issue == kwargs ["is_skipped_an_issue" ]
272+ and cloned .verify_ssl == kwargs ["verify_ssl" ]
273+ and cloned .retries == kwargs ["retries" ]
274+ and cloned .max_pool_size == kwargs ["max_pool_size" ]
275+ and cloned .http_timeout == kwargs ["http_timeout" ]
276+ and cloned .keepalive_timeout == kwargs ["keepalive_timeout" ]
277+ and cloned .mode == kwargs ["mode" ]
278+ and cloned .launch_uuid_print == kwargs ["launch_uuid_print" ]
279+ and cloned .print_output == kwargs ["print_output" ]
280+ )
281+
282+
140283LAUNCH_ID = 333
141284EXPECTED_DEFAULT_URL = f"http://endpoint/ui/#project/launches/all/{ LAUNCH_ID } "
142285EXPECTED_DEBUG_URL = f"http://endpoint/ui/#project/userdebug/all/{ LAUNCH_ID } "
0 commit comments