Esempio n. 1
0
def test_save_guild_not_exists(kudos: ChatKudos) -> None:
    """Save changes to a guild that does't exist"""
    kudos.save_guild("999", max=-1, gain_message="TEST")
    kudos.save_guild("999", loss_message="TEST02")

    assert kudos.get_guild("999").max == -1
    assert kudos.get_guild("999").gain_message == "TEST"
    assert kudos.get_guild("999").loss_message == "TEST02"
Esempio n. 2
0
def test_save_guild_exists(kudos: ChatKudos) -> None:
    """Save explict changes, confirm existing don't change"""
    kudos.save_guild("111", max=-1, gain_message="TEST")
    kudos.save_guild("111", loss_message="TEST02")

    assert kudos.get_guild("111").max == -1
    assert kudos.get_guild("111").gain_message == "TEST"
    assert kudos.get_guild("111").loss_message == "TEST02"
Esempio n. 3
0
def test_lock_toggle(kudos: ChatKudos, message: Mock) -> None:
    """Turn the lock on and off again, fixture starts locked"""
    message.content = "kudos!lock"

    result = kudos.parse_command(message)
    assert result == "ChatKudos is now unlocked. **Everyone** can use it!"
    assert not kudos.get_guild("111").lock

    result = kudos.parse_command(message)
    assert result == "ChatKudos is now locked. Only allowed users/roles can use it!"
    assert kudos.get_guild("111").lock
Esempio n. 4
0
def test_adjust_loss_messages(kudos: ChatKudos, message: Mock) -> None:
    """Adjust the loss messages on existing and non-existing guilds"""
    message.content = "kudos!loss This is loss"
    result = kudos.parse_command(message)
    assert "Message has been set." in result
    assert kudos.get_guild("111").loss_message == "This is loss"

    message.guild.id = "999"
    result = kudos.parse_command(message)
    assert "Message has been set." in result
    assert kudos.get_guild("999").loss_message == "This is loss"
Esempio n. 5
0
def test_add_remove_role_list(kudos: ChatKudos, message: Mock) -> None:
    """Add, then remove, a role from role list"""
    message.mentions = []  # Clear to focus test scope
    message.content = "kudos!role @Cool Kats"  # role_mention provided by fixture

    result = kudos.parse_command(message)
    assert "**+**Cool Kats" in result
    assert "987" in kudos.get_guild("111").roles

    result = kudos.parse_command(message)
    assert "**-**Cool Kats" in result
    assert "987" not in kudos.get_guild("111").roles
Esempio n. 6
0
def test_add_remove_user_list(kudos: ChatKudos, message: Mock) -> None:
    """Add, then remove, a user from user list"""
    message.role_mentions = []  # Clear to focus test scope
    message.content = "kudos!user @Tester"  # mention is provided by fixture

    result = kudos.parse_command(message)
    assert "**+**Tester" in result
    assert "111" in kudos.get_guild("111").users

    result = kudos.parse_command(message)
    assert "**-**Tester" in result
    assert "111" not in kudos.get_guild("111").users
Esempio n. 7
0
async def test_onmessage_kudos(kudos: ChatKudos,
                               async_message: AsyncMock) -> None:
    """Give two Kudos. Config should update"""
    await kudos.on_message(async_message)

    scores = kudos.get_guild("111").scores
    assert scores["111"] == -37
    assert scores["222"] == 1

    async_message.channel.send.assert_called()
    assert async_message.channel.send.call_count == 2
Esempio n. 8
0
def test_adjust_max(kudos: ChatKudos, message: Mock) -> None:
    """Change max for existing and non-existing guild"""
    message.content = "kudos!max 10"
    result = kudos.parse_command(message)
    assert "Max points now: 10" in result

    message.content = "kudos!max -1"
    message.guild.id = "999"
    result = kudos.parse_command(message)
    assert "Max points now: unlimited" in result

    assert kudos.get_guild("111").max == 10
    assert kudos.get_guild("999").max == -1
Esempio n. 9
0
def test_load_guild_found(kudos: ChatKudos) -> None:
    """Load a guild that exists, check values"""
    result = kudos.get_guild("111")
    assert result.max == -1
    assert result.users
    assert not result.roles
Esempio n. 10
0
def test_load_guild_not_found(kudos: ChatKudos) -> None:
    """Load a guild that doesn't exist, check defaults"""
    result = kudos.get_guild("999")
    assert result.max == 5
    assert not result.users