@@ -1009,10 +1009,8 @@ async def test_create_profile_already_exists(
10091009 )
10101010
10111011 assert create .callback
1012- with pytest .raises (SystemExit ) as exc_info :
1013- await create .callback (profile_name = "existing" , config_manager = config_manager )
1012+ await create .callback (profile_name = "existing" , config_manager = config_manager )
10141013
1015- assert exc_info .value .code == 1
10161014 output = capsys .readouterr ().out
10171015 assert "❌ Profile 'existing' already exists" in output
10181016 assert "Use 'workato profiles use' to switch to it" in output
@@ -1034,10 +1032,8 @@ async def test_create_profile_cancelled_region_selection(
10341032 )
10351033
10361034 assert create .callback
1037- with pytest .raises (SystemExit ) as exc_info :
1038- await create .callback (profile_name = "new_profile" , config_manager = config_manager )
1035+ await create .callback (profile_name = "new_profile" , config_manager = config_manager )
10391036
1040- assert exc_info .value .code == 1
10411037 output = capsys .readouterr ().out
10421038 assert "❌ Profile creation cancelled" in output
10431039
@@ -1058,10 +1054,8 @@ async def test_create_profile_empty_token(
10581054 )
10591055
10601056 assert create .callback
1061- with pytest .raises (SystemExit ) as exc_info :
1062- await create .callback (profile_name = "new_profile" , config_manager = config_manager )
1057+ await create .callback (profile_name = "new_profile" , config_manager = config_manager )
10631058
1064- assert exc_info .value .code == 1
10651059 output = capsys .readouterr ().out
10661060 assert "❌ Profile creation cancelled" in output
10671061
@@ -1082,10 +1076,8 @@ async def test_create_profile_authentication_failure(
10821076 )
10831077
10841078 assert create .callback
1085- with pytest .raises (SystemExit ) as exc_info :
1086- await create .callback (profile_name = "new_profile" , config_manager = config_manager )
1079+ await create .callback (profile_name = "new_profile" , config_manager = config_manager )
10871080
1088- assert exc_info .value .code == 1
10891081 output = capsys .readouterr ().out
10901082 assert "❌ Profile creation cancelled" in output
10911083
@@ -1115,11 +1107,53 @@ async def test_create_profile_keyring_failure(
11151107 )
11161108
11171109 assert create .callback
1118- with pytest .raises (SystemExit ) as exc_info :
1119- await create .callback (profile_name = "new_profile" , config_manager = config_manager )
1120-
1121- assert exc_info .value .code == 1
1110+ await create .callback (profile_name = "new_profile" , config_manager = config_manager )
11221111
11231112 output = capsys .readouterr ().out
11241113 assert "❌ Failed to save profile:" in output
11251114 assert "Failed to store token in keyring" in output
1115+
1116+
1117+ @pytest .mark .asyncio
1118+ async def test_create_profile_non_interactive (
1119+ capsys : pytest .CaptureFixture [str ],
1120+ make_config_manager : Callable [..., Mock ],
1121+ ) -> None :
1122+ """Test successful non-interactive profile creation."""
1123+ config_manager = make_config_manager (
1124+ get_profile = Mock (return_value = None ), # Profile doesn't exist yet
1125+ set_profile = Mock (),
1126+ set_current_profile = Mock (),
1127+ )
1128+
1129+ # Mock Workato API client
1130+ mock_client = AsyncMock ()
1131+ mock_user = Mock ()
1132+ mock_user .id = 123
1133+ mock_client .users_api .get_workspace_details = AsyncMock (return_value = mock_user )
1134+ mock_client .__aenter__ = AsyncMock (return_value = mock_client )
1135+ mock_client .__aexit__ = AsyncMock (return_value = None )
1136+
1137+ with patch (
1138+ "workato_platform_cli.cli.commands.profiles.Workato" ,
1139+ return_value = mock_client ,
1140+ ):
1141+ assert create .callback
1142+ await create .callback (
1143+ profile_name = "test_profile" ,
1144+ region = "us" ,
1145+ api_token = "test_token" ,
1146+ api_url = None ,
1147+ non_interactive = True ,
1148+ config_manager = config_manager ,
1149+ )
1150+
1151+ output = capsys .readouterr ().out
1152+ assert "✅ Profile 'test_profile' created successfully" in output
1153+ assert "✅ Set 'test_profile' as the active profile" in output
1154+
1155+ # Verify profile was set and made current
1156+ config_manager .profile_manager .set_profile .assert_called_once ()
1157+ config_manager .profile_manager .set_current_profile .assert_called_once_with (
1158+ "test_profile"
1159+ )
0 commit comments