2727import httpx
2828import pytest
2929
30+ from uipath ._cli ._auth ._auth_service import AuthService
3031from uipath ._cli ._auth ._portal_service import PortalService
3132
3233
@@ -58,7 +59,7 @@ class TestPortalServiceRefreshToken:
5859 """Test class for PortalService refresh token functionality."""
5960
6061 @pytest .mark .parametrize (
61- "domain , expected_token_url" ,
62+ "environment , expected_token_url" ,
6263 [
6364 # Standard UiPath domains
6465 ("https://cloud.uipath.com" , "https://cloud.uipath.com/identity_/connect/token" ),
@@ -85,7 +86,7 @@ class TestPortalServiceRefreshToken:
8586 ],
8687 )
8788 def test_post_refresh_token_request_different_domains (
88- self , domain , expected_token_url , mock_auth_config , sample_token_data
89+ self , environment , expected_token_url , mock_auth_config , sample_token_data
8990 ):
9091 """Test refresh token request with different domain configurations."""
9192
@@ -100,8 +101,11 @@ def test_post_refresh_token_request_different_domains(
100101 mock_response .json .return_value = sample_token_data
101102 mock_client .post .return_value = mock_response
102103
104+ # Create AuthService instance
105+ auth_service = AuthService (environment = environment , force = False )
106+
103107 # Create PortalService instance
104- portal_service = PortalService (domain )
108+ portal_service = PortalService (auth_service . _domain )
105109 portal_service ._client = mock_client
106110
107111 # Test refresh token request
@@ -123,7 +127,7 @@ def test_post_refresh_token_request_different_domains(
123127 assert result == sample_token_data
124128
125129 @pytest .mark .parametrize (
126- "env_var_url, domain , expected_token_url" ,
130+ "env_var_url, environment , expected_token_url" ,
127131 [
128132 # UIPATH_URL should be used when domain is "cloud" (default)
129133 (
@@ -152,7 +156,7 @@ def test_post_refresh_token_request_different_domains(
152156 def test_post_refresh_token_request_with_uipath_url_env (
153157 self ,
154158 env_var_url ,
155- domain ,
159+ environment ,
156160 expected_token_url ,
157161 mock_auth_config ,
158162 sample_token_data ,
@@ -175,8 +179,11 @@ def test_post_refresh_token_request_with_uipath_url_env(
175179 mock_response .json .return_value = sample_token_data
176180 mock_client .post .return_value = mock_response
177181
182+ # Create AuthService instance
183+ auth_service = AuthService (environment = environment , force = False )
184+
178185 # Create PortalService instance
179- portal_service = PortalService (domain )
186+ portal_service = PortalService (auth_service . _domain )
180187 portal_service ._client = mock_client
181188
182189 # Test refresh token request
@@ -211,15 +218,21 @@ def test_post_refresh_token_request_unauthorized(self, mock_auth_config):
211218 "uipath._cli._auth._oidc_utils.OidcUtils.get_auth_config" ,
212219 return_value = mock_auth_config ,
213220 ):
214- with patch ("uipath._cli._auth._portal_service.console" ) as mock_console :
221+ with patch ("uipath._cli._auth._portal_service.ConsoleLogger" ) as mock_logger_cls :
222+ mock_console = Mock ()
223+ mock_logger_cls .return_value = mock_console
224+
215225 # Create a mock HTTP client
216226 mock_client = Mock (spec = httpx .Client )
217227 mock_response = Mock ()
218228 mock_response .status_code = 401
219229 mock_client .post .return_value = mock_response
220230
231+ # Create AuthService instance
232+ auth_service = AuthService (environment = "cloud" , force = False )
233+
221234 # Create PortalService instance
222- portal_service = PortalService ("cloud" )
235+ portal_service = PortalService (auth_service . _domain )
223236 portal_service ._client = mock_client
224237
225238 # Test refresh token request - should raise exception due to console.error
@@ -236,15 +249,21 @@ def test_post_refresh_token_request_server_error(self, mock_auth_config):
236249 "uipath._cli._auth._oidc_utils.OidcUtils.get_auth_config" ,
237250 return_value = mock_auth_config ,
238251 ):
239- with patch ("uipath._cli._auth._portal_service.console" ) as mock_console :
252+ with patch ("uipath._cli._auth._portal_service.ConsoleLogger" ) as mock_logger_cls :
253+ mock_console = Mock ()
254+ mock_logger_cls .return_value = mock_console
255+
240256 # Create a mock HTTP client
241257 mock_client = Mock (spec = httpx .Client )
242258 mock_response = Mock ()
243259 mock_response .status_code = 500
244260 mock_client .post .return_value = mock_response
245261
262+ # Create AuthService instance
263+ auth_service = AuthService (environment = "cloud" , force = False )
264+
246265 # Create PortalService instance
247- portal_service = PortalService ("cloud" )
266+ portal_service = PortalService (auth_service . _domain )
248267 portal_service ._client = mock_client
249268
250269 # Test refresh token request - should raise exception due to console.error
@@ -259,8 +278,11 @@ def test_post_refresh_token_request_server_error(self, mock_auth_config):
259278 def test_post_refresh_token_request_client_not_initialized (self ):
260279 """Test refresh token request when HTTP client is not initialized."""
261280
281+ # Create AuthService instance
282+ auth_service = AuthService (environment = "cloud" , force = False )
283+
262284 # Create PortalService instance without initializing client
263- portal_service = PortalService ("cloud" )
285+ portal_service = PortalService (auth_service . _domain )
264286 portal_service ._client = None
265287
266288 # Test should raise RuntimeError
@@ -283,8 +305,11 @@ def test_post_refresh_token_request_success_response_format(
283305 mock_response .json .return_value = sample_token_data
284306 mock_client .post .return_value = mock_response
285307
308+ # Create AuthService instance
309+ auth_service = AuthService (environment = "cloud" , force = False )
310+
286311 # Create PortalService instance
287- portal_service = PortalService ("cloud" )
312+ portal_service = PortalService (auth_service . _domain )
288313 portal_service ._client = mock_client
289314
290315 # Test refresh token request
@@ -319,7 +344,7 @@ def test_post_refresh_token_request_malformed_domain_handling(
319344 ),
320345 ]
321346
322- for domain , expected_url in test_cases :
347+ for environment , expected_url in test_cases :
323348 with patch (
324349 "uipath._cli._auth._oidc_utils.OidcUtils.get_auth_config" ,
325350 return_value = mock_auth_config ,
@@ -331,8 +356,11 @@ def test_post_refresh_token_request_malformed_domain_handling(
331356 mock_response .json .return_value = sample_token_data
332357 mock_client .post .return_value = mock_response
333358
359+ # Create AuthService instance
360+ auth_service = AuthService (environment = environment , force = False )
361+
334362 # Create PortalService instance
335- portal_service = PortalService (domain )
363+ portal_service = PortalService (auth_service . _domain )
336364 portal_service ._client = mock_client
337365
338366 # Test refresh token request
@@ -353,7 +381,7 @@ def test_post_refresh_token_request_malformed_domain_handling(
353381 mock_client .reset_mock ()
354382
355383 @pytest .mark .parametrize (
356- "scenario_name, env_vars, domain , expected_token_url" ,
384+ "scenario_name, env_vars, environment , expected_token_url" ,
357385 [
358386 # These scenarios mirror the test_auth.py test cases but focus on the refresh token endpoint
359387 (
@@ -398,7 +426,7 @@ def test_post_refresh_token_request_auth_scenarios_integration(
398426 self ,
399427 scenario_name ,
400428 env_vars ,
401- domain ,
429+ environment ,
402430 expected_token_url ,
403431 mock_auth_config ,
404432 sample_token_data ,
@@ -426,9 +454,12 @@ def test_post_refresh_token_request_auth_scenarios_integration(
426454 mock_response .json .return_value = sample_token_data
427455 mock_client .post .return_value = mock_response
428456
457+ # Create AuthService instance
458+ auth_service = AuthService (environment = environment , force = False )
459+
429460 # Create PortalService instance with the domain that would be determined
430461 # by the auth command logic
431- portal_service = PortalService (domain )
462+ portal_service = PortalService (auth_service . _domain )
432463 portal_service ._client = mock_client
433464
434465 # Test refresh token request
0 commit comments