Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/gw2/cogs/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/gw2/cogs/characters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/gw2/cogs/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down
6 changes: 2 additions & 4 deletions tests/unit/gw2/cogs/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,15 @@ 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:
await account(mock_ctx)

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):
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/gw2/cogs/test_characters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 4 additions & 8 deletions tests/unit/gw2/cogs/test_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down