From f5c5b328272cc4725791bafa07948a09db8a9f44 Mon Sep 17 00:00:00 2001 From: ddc <34492089+ddc@users.noreply.github.com> Date: Wed, 25 Feb 2026 21:07:57 -0300 Subject: [PATCH] v3.0.6 --- src/gw2/cogs/account.py | 2 +- src/gw2/cogs/characters.py | 2 +- src/gw2/cogs/key.py | 2 +- tests/unit/gw2/cogs/test_account.py | 6 ++---- tests/unit/gw2/cogs/test_characters.py | 3 +-- tests/unit/gw2/cogs/test_key.py | 12 ++++-------- 6 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/gw2/cogs/account.py b/src/gw2/cogs/account.py index 5a73a0c..5398377 100644 --- a/src/gw2/cogs/account.py +++ b/src/gw2/cogs/account.py @@ -74,7 +74,7 @@ async def account(ctx): # Validate API key is_valid_key = await gw2_api.check_api_key(api_key) if not isinstance(is_valid_key, dict): - msg = f"{is_valid_key.args[1]}\n" + msg = f"{is_valid_key.message}\n" msg += gw2_messages.INVALID_API_KEY_HELP_MESSAGE msg += gw2_messages.key_add_info_help(ctx.prefix) msg += gw2_messages.key_more_info_help(ctx.prefix) diff --git a/src/gw2/cogs/characters.py b/src/gw2/cogs/characters.py index 8207816..2f9eac8 100644 --- a/src/gw2/cogs/characters.py +++ b/src/gw2/cogs/characters.py @@ -41,7 +41,7 @@ async def characters(ctx): gw2_api = Gw2Client(ctx.bot) is_valid_key = await gw2_api.check_api_key(api_key) if not isinstance(is_valid_key, dict): - msg = f"{is_valid_key.args[1]}\n" + msg = f"{is_valid_key.message}\n" msg += gw2_messages.INVALID_API_KEY_HELP_MESSAGE msg += gw2_messages.key_add_info_help(ctx.prefix) msg += gw2_messages.key_more_info_help(ctx.prefix) diff --git a/src/gw2/cogs/key.py b/src/gw2/cogs/key.py index e29b4ba..c79d064 100644 --- a/src/gw2/cogs/key.py +++ b/src/gw2/cogs/key.py @@ -39,7 +39,7 @@ async def _validate_api_key(bot, api_key): gw2_api = Gw2Client(bot) is_valid_key = await gw2_api.check_api_key(api_key) if not isinstance(is_valid_key, dict): - raise ValueError(f"{is_valid_key.args[1]}\n`{api_key}`") + raise ValueError(f"{is_valid_key.message}\n`{api_key}`") key_name = is_valid_key["name"] permissions = ",".join(is_valid_key["permissions"]) diff --git a/tests/unit/gw2/cogs/test_account.py b/tests/unit/gw2/cogs/test_account.py index 1bce677..aaee876 100644 --- a/tests/unit/gw2/cogs/test_account.py +++ b/tests/unit/gw2/cogs/test_account.py @@ -122,9 +122,7 @@ async def test_account_command_invalid_api_key(self, mock_ctx, sample_api_key_da with patch("src.gw2.cogs.account.Gw2Client") as mock_client: mock_client_instance = mock_client.return_value - invalid_key_error = APIInvalidKey(mock_ctx.bot, "Invalid API key") - # Make the error have an args attribute like a real exception - invalid_key_error.args = ("error", "Invalid API key message") + invalid_key_error = APIInvalidKey(mock_ctx.bot, f"(400) {gw2_messages.INVALID_API_KEY}") mock_client_instance.check_api_key = AsyncMock(return_value=invalid_key_error) with patch("src.gw2.cogs.account.bot_utils.send_error_msg") as mock_error: @@ -132,7 +130,7 @@ async def test_account_command_invalid_api_key(self, mock_ctx, sample_api_key_da mock_error.assert_called_once() error_msg = mock_error.call_args[0][1] - assert "Invalid API key message" in error_msg + assert gw2_messages.INVALID_API_KEY in error_msg @pytest.mark.asyncio async def test_account_command_insufficient_permissions(self, mock_ctx, sample_account_data): diff --git a/tests/unit/gw2/cogs/test_characters.py b/tests/unit/gw2/cogs/test_characters.py index b518a9a..919edf6 100644 --- a/tests/unit/gw2/cogs/test_characters.py +++ b/tests/unit/gw2/cogs/test_characters.py @@ -111,8 +111,7 @@ async def test_characters_invalid_api_key_sends_error_with_help(self, mock_ctx, mock_instance.get_api_key_by_user = AsyncMock(return_value=sample_api_key_data) with patch("src.gw2.cogs.characters.Gw2Client") as mock_client: mock_client_instance = mock_client.return_value - invalid_error = APIInvalidKey(mock_ctx.bot, "Invalid key") - invalid_error.args = ("error", gw2_messages.INVALID_API_KEY) + invalid_error = APIInvalidKey(mock_ctx.bot, f"(400) {gw2_messages.INVALID_API_KEY}") mock_client_instance.check_api_key = AsyncMock(return_value=invalid_error) with patch("src.gw2.cogs.characters.bot_utils.send_error_msg") as mock_error: mock_error.return_value = None diff --git a/tests/unit/gw2/cogs/test_key.py b/tests/unit/gw2/cogs/test_key.py index 00c68bb..8dc0d92 100644 --- a/tests/unit/gw2/cogs/test_key.py +++ b/tests/unit/gw2/cogs/test_key.py @@ -105,8 +105,7 @@ async def test_add_deletes_message_for_privacy(self, mock_ctx): with patch("src.gw2.cogs.key.bot_utils.delete_message") as mock_delete: with patch("src.gw2.cogs.key.Gw2Client") as mock_client: mock_client_instance = mock_client.return_value - invalid_error = APIInvalidKey(mock_ctx.bot, "Invalid key") - invalid_error.args = ("error", "Invalid API key") + invalid_error = APIInvalidKey(mock_ctx.bot, f"(400) {gw2_messages.INVALID_API_KEY}") mock_client_instance.check_api_key = AsyncMock(return_value=invalid_error) with patch("src.gw2.cogs.key.bot_utils.send_error_msg") as mock_error: mock_error.return_value = None @@ -120,8 +119,7 @@ async def test_add_invalid_api_key_sends_error(self, mock_ctx): with patch("src.gw2.cogs.key.bot_utils.delete_message"): with patch("src.gw2.cogs.key.Gw2Client") as mock_client: mock_client_instance = mock_client.return_value - invalid_error = APIInvalidKey(mock_ctx.bot, "Invalid key") - invalid_error.args = ("error", gw2_messages.INVALID_API_KEY) + invalid_error = APIInvalidKey(mock_ctx.bot, f"(400) {gw2_messages.INVALID_API_KEY}") mock_client_instance.check_api_key = AsyncMock(return_value=invalid_error) with patch("src.gw2.cogs.key.bot_utils.send_error_msg") as mock_error: mock_error.return_value = None @@ -364,8 +362,7 @@ async def test_update_invalid_api_key_sends_error(self, mock_ctx): mock_instance.get_api_key_by_user = AsyncMock(return_value=[{"name": "OldKey", "key": "old-key-12345"}]) with patch("src.gw2.cogs.key.Gw2Client") as mock_client: mock_client_instance = mock_client.return_value - invalid_error = APIInvalidKey(mock_ctx.bot, "Invalid key") - invalid_error.args = ("error", gw2_messages.INVALID_API_KEY) + invalid_error = APIInvalidKey(mock_ctx.bot, f"(400) {gw2_messages.INVALID_API_KEY}") mock_client_instance.check_api_key = AsyncMock(return_value=invalid_error) with patch("src.gw2.cogs.key.bot_utils.send_error_msg") as mock_error: mock_error.return_value = None @@ -681,8 +678,7 @@ async def test_info_invalid_api_key_on_check_shows_no_valid(self, mock_ctx): ) with patch("src.gw2.cogs.key.Gw2Client") as mock_client: mock_client_instance = mock_client.return_value - invalid_error = APIInvalidKey(mock_ctx.bot, "Invalid key") - invalid_error.args = ("error", "Invalid key") + invalid_error = APIInvalidKey(mock_ctx.bot, f"(400) {gw2_messages.INVALID_API_KEY}") mock_client_instance.check_api_key = AsyncMock(return_value=invalid_error) with patch("src.gw2.cogs.key.bot_utils.send_embed") as mock_send: with patch("src.gw2.cogs.key.bot_utils.get_current_date_time_str_long") as mock_time: