Files
meshcore-bot/tests/commands/test_ping_command.py
agessaman d699ea1cf1 Update configuration handling and validation for bot sections
- Enhanced .gitignore to allow test files in the tests/ directory and committed pytest.ini for test discovery.
- Added checks for missing sections in configuration files, specifically for Admin_ACL and Banned_Users, to prevent errors during bot startup.
- Updated generate_website.py and command_manager.py to handle cases where required sections are absent, returning empty lists instead of raising exceptions.
- Introduced optional dependencies for testing in pyproject.toml, ensuring a smoother development experience.
- Improved localization handling in core.py to default to English when the Localization section is missing, enhancing user experience.
2026-02-12 19:23:35 -08:00

39 lines
1.6 KiB
Python

"""Tests for modules.commands.ping_command."""
import pytest
from modules.commands.ping_command import PingCommand
from tests.conftest import command_mock_bot, mock_message
class TestPingCommand:
"""Tests for PingCommand."""
def test_can_execute_when_enabled(self, command_mock_bot):
command_mock_bot.config.add_section("Ping_Command")
command_mock_bot.config.set("Ping_Command", "enabled", "true")
cmd = PingCommand(command_mock_bot)
msg = mock_message(content="ping", is_dm=True)
assert cmd.can_execute(msg) is True
def test_can_execute_when_disabled(self, command_mock_bot):
command_mock_bot.config.add_section("Ping_Command")
command_mock_bot.config.set("Ping_Command", "enabled", "false")
cmd = PingCommand(command_mock_bot)
msg = mock_message(content="ping", is_dm=True)
assert cmd.can_execute(msg) is False
@pytest.mark.asyncio
async def test_execute_returns_keyword_response(self, command_mock_bot):
command_mock_bot.config.add_section("Ping_Command")
command_mock_bot.config.set("Ping_Command", "enabled", "true")
command_mock_bot.config.set("Keywords", "ping", "Pong!")
cmd = PingCommand(command_mock_bot)
msg = mock_message(content="ping", is_dm=True)
result = await cmd.execute(msg)
assert result is True
call_args = command_mock_bot.command_manager.send_response.call_args
assert call_args is not None
response = call_args[0][1]
assert "Pong" in response or "pong" in response.lower()