@@ -25,22 +25,11 @@ def test_whoami_with_env_token(self, mock_settings, mock_console) -> None:
2525 with patch ("cforge.commands.settings.whoami.get_console" , return_value = mock_console ):
2626 with patch ("cforge.commands.settings.whoami.get_settings" , return_value = mock_settings ):
2727 with patch ("cforge.commands.settings.whoami.load_token" , return_value = None ):
28- with patch ("cforge.commands.settings.whoami.get_active_profile" , return_value = None ):
29- whoami ()
30-
31- # Verify console output
32- assert mock_console .print .call_count == 2
33-
34- # Check first call - authentication status
35- first_call = mock_console .print .call_args_list [0 ][0 ][0 ]
36- assert "Authenticated via MCPGATEWAY_BEARER_TOKEN" in first_call
37- assert "[green]" in first_call
28+ whoami ()
3829
39- # Check second call - token preview
40- second_call = mock_console .print .call_args_list [1 ][0 ][0 ]
41- assert "Token:" in second_call
42- assert "env_token_" in second_call
43- assert "..." in second_call
30+ call_messages = [call [0 ][0 ] for call in mock_console .print .call_args_list if call and call [0 ]]
31+ assert any ("Authenticated via MCPGATEWAY_BEARER_TOKEN" in call for call in call_messages )
32+ assert any ("env_token_" in call for call in call_messages )
4433
4534 def test_whoami_with_stored_token (self , mock_settings , mock_console ) -> None :
4635 """Test whoami when authenticated via stored token file."""
@@ -50,22 +39,11 @@ def test_whoami_with_stored_token(self, mock_settings, mock_console) -> None:
5039 with patch ("cforge.commands.settings.whoami.get_console" , return_value = mock_console ):
5140 with patch ("cforge.commands.settings.whoami.get_settings" , return_value = mock_settings ):
5241 with patch ("cforge.commands.settings.whoami.load_token" , return_value = stored_token ):
53- with patch ("cforge.commands.settings.whoami.get_active_profile" , return_value = None ):
54- whoami ()
55-
56- # Verify console output
57- assert mock_console .print .call_count == 2
58-
59- # Check first call - authentication status with file path
60- first_call = mock_console .print .call_args_list [0 ][0 ][0 ]
61- assert "Authenticated via stored token" in first_call
62- assert "[green]" in first_call
42+ whoami ()
6343
64- # Check second call - token preview
65- second_call = mock_console .print .call_args_list [1 ][0 ][0 ]
66- assert "Token:" in second_call
67- assert "stored_tok" in second_call
68- assert "..." in second_call
44+ call_messages = [call [0 ][0 ] for call in mock_console .print .call_args_list if call and call [0 ]]
45+ assert any ("Authenticated via stored token" in call for call in call_messages )
46+ assert any ("stored_tok" in call for call in call_messages )
6947
7048 def test_whoami_not_authenticated (self , mock_settings , mock_console ) -> None :
7149 """Test whoami when not authenticated."""
@@ -75,17 +53,11 @@ def test_whoami_not_authenticated(self, mock_settings, mock_console) -> None:
7553 with patch ("cforge.commands.settings.whoami.get_console" , return_value = mock_console ):
7654 with patch ("cforge.commands.settings.whoami.get_settings" , return_value = mock_settings ):
7755 with patch ("cforge.commands.settings.whoami.load_token" , return_value = None ):
78- with patch ("cforge.commands.settings.whoami.get_active_profile" , return_value = None ):
79- whoami ()
80-
81- # Verify console output
82- mock_console .print .assert_called_once ()
56+ whoami ()
8357
84- # Check output message
85- call_args = mock_console .print .call_args [0 ][0 ]
86- assert "Not authenticated" in call_args
87- assert "cforge login" in call_args
88- assert "[yellow]" in call_args
58+ call_messages = [call [0 ][0 ] for call in mock_console .print .call_args_list if call and call [0 ]]
59+ assert any ("Not authenticated" in call for call in call_messages )
60+ assert any ("cforge login" in call for call in call_messages )
8961
9062 def test_whoami_env_token_takes_precedence (self , mock_settings , mock_console ) -> None :
9163 """Test that env token takes precedence over stored token."""
@@ -96,13 +68,11 @@ def test_whoami_env_token_takes_precedence(self, mock_settings, mock_console) ->
9668 with patch ("cforge.commands.settings.whoami.get_console" , return_value = mock_console ):
9769 with patch ("cforge.commands.settings.whoami.get_settings" , return_value = mock_settings ):
9870 with patch ("cforge.commands.settings.whoami.load_token" , return_value = stored_token ):
99- with patch ("cforge.commands.settings.whoami.get_active_profile" , return_value = None ):
100- whoami ()
71+ whoami ()
10172
102- # Should show env token, not stored token
103- first_call = mock_console .print .call_args_list [0 ][0 ][0 ]
104- assert "MCPGATEWAY_BEARER_TOKEN" in first_call
105- assert "stored token" not in first_call
73+ call_messages = [call [0 ][0 ] for call in mock_console .print .call_args_list if call and call [0 ]]
74+ assert any ("MCPGATEWAY_BEARER_TOKEN" in call for call in call_messages )
75+ assert not any ("stored token" in call for call in call_messages )
10676
10777
10878class TestWhoamiWithProfiles :
0 commit comments