Example #1
0
async def test_alert_silence(mocker, monkeypatch):
    send_spy = mocker.spy(MockMessage.channel, 'send')

    client = DiscordClient(None, ':memory:', False)

    await client.on_message(MockMessage('svetlana alert 2'))
    args, kwargs = send_spy.call_args
    assert args[0] == 'OK, I will alert 2 hours before a deadline.'

    await client.on_message(MockMessage('svetlana alert 3'))
    args, kwargs = send_spy.call_args
    assert args[0] == 'OK, I will alert 3 hours before a deadline.'

    await client.on_message(MockMessage('svetlana alert 2'))
    args, kwargs = send_spy.call_args
    assert args[0] == "I'm already alerting 2 hours before a deadline!"

    await client.on_message(MockMessage('svetlana silence 2'))
    args, kwargs = send_spy.call_args
    assert args[0] == 'Understood, I will stop alerting T-2h..'

    await client.on_message(MockMessage('svetlana silence 2'))
    args, kwargs = send_spy.call_args
    assert args[0] == "I already don't alert 2 hours before a deadline?!"

    await client.on_message(MockMessage('svetlana alert list'))
    args, kwargs = send_spy.call_args
    assert args[0] == "I'm alerting at: T-3h"

    await client.on_message(MockMessage('svetlana silence 3'))
    args, kwargs = send_spy.call_args
    assert args[0] == 'Understood, I will stop alerting T-3h..'
Example #2
0
async def test_help(mocker, monkeypatch):
    send_spy = mocker.spy(MockMessage.channel, 'send')

    client = DiscordClient(None, ':memory:', False)

    await client.on_message(MockMessage('svetlana help'))
    args, kwargs = send_spy.call_args
    assert args[0] == f'Hello, jhartog!\n{DESCRIPTION}'
Example #3
0
async def test_poll_new_round(mocker, monkeypatch):
    game = DiplomacyGame(
        1, {
            'name': ['Mock'],
            'date': ['Spring, 1901'],
            'phase': ['Diplomacy'],
            'deadline': [str(int(datetime.now().timestamp()) + DAY)],
            'defeated': [],
            'not_ready': [],
            'ready': [],
            'won': [],
            'drawn': [],
            'pregame': [],
            'map_link': ['foo.jpg'],
        }, '', '')

    client = DiscordClient(None, ':memory:', False)

    msg = client._poll(game, 1, 10, 0)
    assert msg == 'Starting new round! Good luck :)'
Example #4
0
async def test_poll_won(mocker, monkeypatch):
    game = DiplomacyGame(
        1, {
            'name': ['Mock'],
            'date': ['Spring, 1901'],
            'phase': ['Diplomacy'],
            'deadline': [str(int(datetime.now().timestamp()))],
            'defeated': [],
            'not_ready': [],
            'ready': [],
            'won': ['Russia'],
            'drawn': [],
            'pregame': [],
            'map_link': ['foo.jpg'],
        }, '', '')

    client = DiscordClient(None, ':memory:', False)

    msg = client._poll(game, 1, None, 0)
    assert msg == 'Russia has won!'
Example #5
0
async def test_follow_unfollow_list(mocker, monkeypatch):
    send_spy = mocker.spy(MockMessage.channel, 'send')
    monkeypatch.setattr(time, 'time', lambda *args: 12345)

    wd_client = MockWebDiplomacyClient({
        'name': ['Mock'],
        'date': ['Spring, 1901'],
        'phase': ['Diplomacy'],
        'deadline': [str(int(datetime.now().timestamp()))],
        'defeated': [],
        'not_ready': [],
        'ready': [],
        'won': [],
        'drawn': [],
        'pregame': ['foo'],
        'map_link': ['foo.jpg'],
    })
    client = DiscordClient(wd_client, ':memory:', False)

    await client.on_message(MockMessage('svetlana list'))
    args, kwargs = send_spy.call_args
    assert args[0] == "I'm following: "

    await client.on_message(MockMessage('svetlana follow 1234'))
    args, kwargs = send_spy.call_args
    assert kwargs['embed'].description == 'Now following 1234!'
    assert kwargs['embed'].url == 'https://foo.bar/game.php'
    assert kwargs['embed'].title == 'Mock - Spring, 1901 - Diplomacy phase'

    await client.on_message(MockMessage('svetlana follow 1234'))
    args, kwargs = send_spy.call_args
    assert kwargs['embed'].image.url == 'https://foo.bar/foo.jpg&time=12345'
    assert kwargs['embed'].description == "I'm already following that game!"

    await client.on_message(MockMessage('svetlana follow 1337'))
    args, kwargs = send_spy.call_args
    assert kwargs['embed'].description == 'Now following 1337!'

    await client.on_message(MockMessage('svetlana list'))
    args, kwargs = send_spy.call_args
    assert args[0] == "I'm following: 1234, 1337"

    await client.on_message(MockMessage('svetlana unfollow 1234'))
    args, kwargs = send_spy.call_args
    assert args[0] == 'Consider it done!'

    await client.on_message(MockMessage('svetlana unfollow 1234'))
    args, kwargs = send_spy.call_args
    assert args[0] == 'Huh? What game?'

    await client.on_message(MockMessage('svetlana follow 1234a'))
    args, kwargs = send_spy.call_args
    assert args[0] == 'Huh?'
Example #6
0
async def test_poll_two_hours_left_not_ready(mocker, monkeypatch):
    game = DiplomacyGame(
        1, {
            'name': ['Mock'],
            'date': ['Spring, 1901'],
            'phase': ['Diplomacy'],
            'deadline': [str(int(datetime.now().timestamp()) + HOUR)],
            'defeated': [],
            'not_ready': ['Turkey', 'France'],
            'ready': [],
            'won': [],
            'drawn': [],
            'pregame': [],
            'map_link': ['foo.jpg'],
        }, '', '')

    client = DiscordClient(None, ':memory:', False)
    await client.on_message(MockMessage('svetlana alert 2'))

    msg = client._poll(game, 1, 3 * HOUR, 0)
    assert msg == "2h left! These countries aren't ready: Turkey, France"
Example #7
0
    def _test_days(N):
        game = DiplomacyGame(
            1, {
                'name': ['Mock'],
                'date': ['Spring, 1901'],
                'phase': ['Diplomacy'],
                'deadline':
                [str(int(datetime.now().timestamp()) + N * DAY + MINUTE)],
                'defeated': [],
                'not_ready': [],
                'ready': [],
                'won': [],
                'drawn': [],
                'pregame': ['foo'],
                'map_link': ['foo.jpg'],
            }, '', '')

        client = DiscordClient(None, ':memory:', False)

        msg = client._poll(game, 1, None, 0)
        assert msg == f'The game starts in {N} days!'