Beispiel #1
0
async def test_receive_command_without_optional_arg():
    mock_channel = MockChannel()
    mock_message = MockMessage("+greet someone", channel=mock_channel)

    assert await receive_command(
        Command("greet", "someone", context=mock_message))
    assert mock_channel.messages[0].content == "hi someone"
Beispiel #2
0
async def test_validate_filter_complex():
    command = Command(name="test", context=MockMessage(channel=MockChannel()))
    assert await validate_filter(
        command        = command,
        _filter        = "type:(nom or qual or reset or dq) and not user:(banchobot or peppy)",
        filter_context = filter_context
    )
Beispiel #3
0
async def test_ping_small():
    mock_client = MockClient(latency=0.00029)
    mock_message = MockMessage(channel=MockChannel())
    mock_command = MockCommand("ping", context=mock_message, client=mock_client)

    assert await receive_command(mock_command)
    assert mock_command.response == "< 1 ms"
Beispiel #4
0
async def test_unsub():
    subs = [
        Subscription(guild_id=2, channel_id=6, _filter="type:nominate"),
        Subscription(guild_id=2, channel_id=4, _filter="user:someone"),
        Subscription(guild_id=1, channel_id=6, _filter="type:nominate")
    ]
    database = Database(BOT_TEST_DB_NAME)
    for sub in subs:
        database.insert_subscription(sub)
    subscriber.load()

    mock_message = MockMessage(
        channel=MockChannel(_id=6, guild=MockGuild(_id=2)))
    mock_command = MockCommand("unsub", context=mock_message)

    assert all(sub in subscriber.cache for sub in subs)

    assert await receive_command(mock_command)
    assert mock_command.response.startswith("✓")
    assert "🔕" in mock_command.response_embed.fields[0].name.lower()
    assert "unsubscribed from" in mock_command.response_embed.fields[
        0].name.lower()
    assert "type:nominate" in mock_command.response_embed.fields[0].value
    assert "`type:nominate`" in mock_command.response_embed.fields[0].value
    assert subs[0] not in subscriber.cache
    assert subs[1] in subscriber.cache
    assert subs[2] in subscriber.cache
Beispiel #5
0
def test_can_execute_admin():
    mock_message = MockMessage(channel=MockChannel(_id=44,
                                                   guild=MockGuild(_id=3)),
                               author=MockUser(_id=2, is_admin=True))
    command = Command(name="test2", context=mock_message)

    assert permissions.can_execute(command)
Beispiel #6
0
async def test_filters_custom_prefix():
    mock_command = MockCommand(
        "filters",
        context=MockMessage(channel=MockChannel(guild=MockGuild(_id=8))))
    set_prefix(guild_id=8, prefix="&")

    assert await receive_command(mock_command)
    assert f"`&filters <key>`" in mock_command.response
Beispiel #7
0
async def test_sub_undefined_type():
    mock_message = MockMessage(
        channel=MockChannel(_id=6, guild=MockGuild(_id=2)))
    mock_command = MockCommand("sub", "type:undefined", context=mock_message)

    assert await receive_command(mock_command)
    assert mock_command.response.startswith("✗")
    assert "`type:undefined`" in mock_command.response.lower()
    assert not subscriber.cache
Beispiel #8
0
async def test_receive_command_missing_arg():
    mock_channel = MockChannel()
    mock_message = MockMessage("+greet", channel=mock_channel)

    assert not await receive_command(Command("greet", context=mock_message))
    assert mock_channel.messages[0].content.startswith("✗")
    assert "missing required argument" in mock_channel.messages[
        0].content.lower()
    assert "`<name>`" in mock_channel.messages[0].content.lower()
Beispiel #9
0
async def test_prefix_very_long_symbol():
    mock_command = MockCommand(
        "prefix",
        "a" * 2000,
        context=MockMessage(channel=MockChannel(guild=MockGuild(_id=8))))

    assert await receive_command(mock_command)
    assert mock_command.response.startswith("✗")
    assert "cannot exceed" in mock_command.response
Beispiel #10
0
async def test_receive_command_lacking_permission():
    mock_channel = MockChannel(guild=MockGuild(_id=3))
    mock_message = MockMessage("+test",
                               channel=mock_channel,
                               author=MockUser(is_admin=False))

    assert not await receive_command(Command("test", context=mock_message))
    assert mock_channel.typing_triggered
    assert "✗ lacking permission" in mock_channel.messages[0].content.lower()
Beispiel #11
0
async def test_prefix_whitespace_in_symbol():
    mock_command = MockCommand(
        "prefix",
        "a b",
        context=MockMessage(channel=MockChannel(guild=MockGuild(_id=8))))

    assert await receive_command(mock_command)
    assert mock_command.response.startswith("✗")
    assert "whitespace" in mock_command.response.lower()
Beispiel #12
0
async def test_ping():
    mock_channel = MockChannel()
    mock_client = MockClient(latency=0.13429)
    mock_message = MockMessage(channel=mock_channel)
    mock_command = MockCommand("ping", context=mock_message, client=mock_client)
    
    assert await receive_command(mock_command)
    assert mock_command.response == "134 ms"
    assert mock_channel.messages[0].content == "134 ms"
Beispiel #13
0
def test_prefix_custom():
    command = Command("test",
                      context=MockMessage(
                          channel=MockChannel(_id=6, guild=MockGuild(_id=7))))

    set_prefix(guild_id=7, prefix="&")
    assert command.prefix() == "&"

    set_prefix(guild_id=7, prefix=None)
    assert command.prefix() == DEFAULT_PREFIX
Beispiel #14
0
async def test_disable():
    mock_command = MockCommand("disable", "disable", context=MockMessage(channel=MockChannel(guild=MockGuild(_id=3))))
    set_permission_filter(guild_id=3, command_wrapper=get_wrapper("disable"), permission_filter="user:<@0>")

    assert await receive_command(mock_command)
    assert "✓" in mock_command.response
    expected_embed = permissions_embed(guild_id=3, command_wrappers=[get_wrapper("disable")])
    assert mock_command.response_embed.fields[0].name == expected_embed.fields[0].name
    assert mock_command.response_embed.fields[0].value == expected_embed.fields[0].value
    assert not get_permission_filter(guild_id=3, command_wrapper=get_wrapper("disable"))
Beispiel #15
0
async def test_command_respond():
    mock_channel = MockChannel()
    mock_message = MockMessage("+test 1 2 3", channel=mock_channel)
    command = Command("test", "1", "2", "3", context=mock_message)

    assert await command.respond("success")
    assert command.response == "success"
    assert command.response_embed is None
    assert mock_channel.messages[0].content == "success"
    assert mock_channel.messages[0].embed is None
Beispiel #16
0
async def test_help():
    mock_command = MockCommand("help",
                               context=MockMessage(channel=MockChannel()))

    assert await receive_command(mock_command)
    assert f"`{DEFAULT_PREFIX}help <command>`" in mock_command.response  # Should suggest using this for more details of a specific command.
    assert mock_command.response_embed.fields[0].name == general_help_embed(
    ).fields[0].name
    assert mock_command.response_embed.fields[0].value == general_help_embed(
    ).fields[0].value
Beispiel #17
0
async def test_recent_invalid_word():
    mock_message = MockMessage(
        channel=MockChannel(_id=6, guild=MockGuild(_id=2)))
    mock_command = MockCommand("recent",
                               "type:nominate eand type:qualify",
                               context=mock_message)

    assert await receive_command(mock_command)
    assert mock_command.response.startswith("✗")
    assert "invalid word" in mock_command.response.lower()
Beispiel #18
0
async def test_recent_invalid_value():
    mock_message = MockMessage(
        channel=MockChannel(_id=6, guild=MockGuild(_id=2)))
    mock_command = MockCommand("recent",
                               "type:undefined",
                               context=mock_message)

    assert await receive_command(mock_command)
    assert mock_command.response.startswith("✗")
    assert "invalid value" in mock_command.response.lower()
Beispiel #19
0
async def test_sub_undefined_key():
    mock_message = MockMessage(
        channel=MockChannel(_id=6, guild=MockGuild(_id=2)))
    mock_command = MockCommand("sub",
                               "undefined:nominate or undefined:qualify",
                               context=mock_message)

    assert await receive_command(mock_command)
    assert mock_command.response.startswith("✗")
    assert mock_command.response.lower().count("`undefined`") == 1
    assert not subscriber.cache
Beispiel #20
0
async def test_sub_typoed_and():
    mock_message = MockMessage(
        channel=MockChannel(_id=6, guild=MockGuild(_id=2)))
    mock_command = MockCommand("sub",
                               "type:qualify annd type:nominate",
                               context=mock_message)

    assert await receive_command(mock_command)
    assert mock_command.response.startswith("✗")
    assert "`annd`" in mock_command.response
    assert not subscriber.cache
Beispiel #21
0
async def test_help_with_arg():
    mock_command = MockCommand("help",
                               "name",
                               context=MockMessage(channel=MockChannel()))

    assert await receive_command(mock_command)
    assert f"`{DEFAULT_PREFIX}help`" in mock_command.response  # Should suggest using this for a list of commands.
    assert mock_command.response_embed.fields[0].name == help_embed(
        "name").fields[0].name
    assert mock_command.response_embed.fields[0].value == help_embed(
        "name").fields[0].value
Beispiel #22
0
async def test_prefix():
    mock_command = MockCommand(
        "prefix",
        "&",
        context=MockMessage(channel=MockChannel(guild=MockGuild(_id=8))))

    assert await receive_command(mock_command)
    assert mock_command.response.startswith("✓")
    assert "`+`" in mock_command.response
    assert "`&`" in mock_command.response
    assert mock_command.prefix() == "&"
Beispiel #23
0
async def test_sub_no_arg_no_sub():
    mock_message = MockMessage(
        channel=MockChannel(_id=6, guild=MockGuild(_id=2)))
    mock_command = MockCommand("sub", context=mock_message)

    assert await receive_command(mock_command)
    assert f"`{DEFAULT_PREFIX}sub <filter>`" in mock_command.response  # Should suggest these for if the user intended something else.
    assert f"`{DEFAULT_PREFIX}unsub`" not in mock_command.response  # Don't need to suggest unsubscribing if we don't have a sub.
    assert "🔔\u2000Current Subscription" in mock_command.response_embed.fields[
        0].name
    assert "None" in mock_command.response_embed.fields[0].value
Beispiel #24
0
def test_can_execute_user_perm_fail():
    command_wrapper = get_wrapper(name="test1")
    mock_message = MockMessage(channel=MockChannel(_id=44,
                                                   guild=MockGuild(_id=3)),
                               author=MockUser(_id=2, is_admin=False))
    command = Command(name="test2", context=mock_message)

    set_permission_filter(guild_id=3,
                          command_wrapper=command_wrapper,
                          permission_filter="user:<@88>")

    assert not permissions.can_execute(command)
Beispiel #25
0
async def test_filters_unrecognized_command():
    mock_command = MockCommand("filters",
                               "undefined",
                               context=MockMessage(channel=MockChannel()))

    assert await receive_command(mock_command)
    assert mock_command.response.startswith("✗")
    assert "`undefined`" in mock_command.response
    assert mock_command.response_embed.fields[0].name == help_embed(
        "filters").fields[0].name
    assert mock_command.response_embed.fields[0].value == help_embed(
        "filters").fields[0].value
Beispiel #26
0
async def test_validate_filter_invalid_key():
    command = Command(name="test", context=MockMessage(channel=MockChannel()))
    assert not await validate_filter(command=command, _filter="undefined:undefined", filter_context=filter_context)
    assert "✗" in command.response
    assert "invalid key" in command.response.lower()

    embed = filters_embed(filter_context=filter_context)
    assert command.response_embed.title == embed.title
    assert command.response_embed.description == embed.description
    assert command.response_embed.fields[0].name == embed.fields[0].name
    assert command.response_embed.fields[0].value == embed.fields[0].value
    assert command.response_embed.fields[1].name == embed.fields[1].name
    assert command.response_embed.fields[1].value == embed.fields[1].value
Beispiel #27
0
async def test_perms():
    mock_command = MockCommand(
        "perms",
        context=MockMessage(channel=MockChannel(guild=MockGuild(_id=3))))

    assert await receive_command(mock_command)
    assert f"`{DEFAULT_PREFIX}enable`" in mock_command.response
    assert f"`{DEFAULT_PREFIX}disable`" in mock_command.response
    assert "permissions" in mock_command.response_embed.fields[0].name.lower()
    assert mock_command.response_embed.fields[0].value.lower().startswith(
        "***admin-only***")
    assert f"`{DEFAULT_PREFIX}perms/{DEFAULT_PREFIX}permissions [command(s)]`" in mock_command.response_embed.fields[
        0].value.lower()
Beispiel #28
0
async def test_validate_filter_invalid_word():
    command = Command(name="test", context=MockMessage(channel=MockChannel()))
    assert not await validate_filter(command=command, _filter="user:sometwo annd type:qualify", filter_context=filter_context)
    assert "✗" in command.response
    assert "invalid word" in command.response.lower()

    embed = filters_embed(filter_context=filter_context)
    assert command.response_embed.title == embed.title
    assert command.response_embed.description == embed.description
    assert command.response_embed.fields[0].name == embed.fields[0].name
    assert command.response_embed.fields[0].value == embed.fields[0].value
    assert command.response_embed.fields[1].name == embed.fields[1].name
    assert command.response_embed.fields[1].value == embed.fields[1].value
Beispiel #29
0
async def test_validate_filter_invalid_value():
    command = Command(name="test", context=MockMessage(channel=MockChannel()))
    assert not await validate_filter(command=command, _filter="type:undefined", filter_context=filter_context)
    assert "✗" in command.response
    assert "invalid value" in command.response.lower()

    embed = filter_embed(key="type", filter_context=filter_context)
    assert command.response_embed.fields[0].name == embed.fields[0].name
    assert command.response_embed.fields[0].value == embed.fields[0].value
    assert command.response_embed.fields[1].name == embed.fields[1].name
    assert command.response_embed.fields[1].value == embed.fields[1].value
    assert command.response_embed.fields[2].name == embed.fields[2].name
    assert command.response_embed.fields[2].value == embed.fields[2].value
Beispiel #30
0
async def test_command_respond_embed():
    mock_channel = MockChannel()
    mock_message = MockMessage("+test 1 2 3", channel=mock_channel)
    command = Command("test", "1", "2", "3", context=mock_message)

    embed = Embed()
    embed.add_field(name="test", value="success")

    assert await command.respond("", embed=embed)
    assert command.response == ""
    assert command.response_embed == embed
    assert mock_channel.messages[0].content == ""
    assert mock_channel.messages[0].embed == embed