Esempio n. 1
0
def test_is_join_request_still_valid_false():
    request_id = persistence.add_to_waiting_list(
        TEST_SERVER_ID, MockUser(name=TEST_USER_NAME, id=TEST_USER_NAME),
        TEST_TOURNAMENT_SIZE)

    request_id2 = persistence.add_to_waiting_list(
        TEST_SERVER_ID, MockUser(name=TEST_USER_NAME, id=TEST_USER_NAME),
        TEST_TOURNAMENT_SIZE)

    assert not persistence.is_join_request_still_valid(request_id)
    assert persistence.is_join_request_still_valid(request_id2)
Esempio n. 2
0
def test_add_to_waiting_list_empty_db():
    persistence.add_to_waiting_list(
        TEST_SERVER_ID, MockUser(name=TEST_USER_NAME, id=TEST_USER_NAME),
        TEST_TOURNAMENT_SIZE)

    all_requests = persistence.join_requests.all()
    assert len(all_requests) == 1
    request = all_requests[0]
    assert request['server_id'] == TEST_SERVER_ID
    assert request['user_id'] == TEST_USER_NAME
    assert request['user_name'] == TEST_USER_NAME
    assert request['tournament_size'] == TEST_TOURNAMENT_SIZE
    assert len(request['decks']) == 0
Esempio n. 3
0
def test_add_to_waiting_list_previous_req_diff_server():
    persistence.join_requests.insert({
        'server_id': TEST_SERVER_ID + 'a',
        'user_id': TEST_USER_NAME,
        'user_name': TEST_USER_NAME,
        'tournament_size': TEST_TOURNAMENT_SIZE,
        'decks': ['trash']
    })

    persistence.add_to_waiting_list(
        TEST_SERVER_ID, MockUser(name=TEST_USER_NAME, id=TEST_USER_NAME),
        TEST_TOURNAMENT_SIZE)

    all_requests = persistence.join_requests.all()
    assert len(all_requests) == 2
Esempio n. 4
0
async def add_player(client, user, server, size):
    # Register user and ask for decks
    request_id = persistence.add_to_waiting_list(server.id, user, size)
    await user.send(
        config.get_server_config(server.name, 'wait_for_decks_message'))

    def he_replied(message):
        return message.author == user and isinstance(
            message.channel, discord.abc.PrivateChannel)

    request = None
    while True:
        reply = await client.wait_for('message', check=he_replied)

        if not persistence.is_join_request_still_valid(request_id):
            # While waiting, the user performed the command again and subscribed to a new tournament format:
            # We'll let that coroutine to handle it, and this will terminate here
            print('submission invalidated: terminating')
            break

        if reply.content != '!submit':
            # Add deck
            urls = [attachment.url for attachment in reply.attachments]
            request = persistence.add_deck(request_id, reply.content, urls)
        elif request is None:
            # !submit used, but no decks submitted yet
            await user.send(
                'At least one deck is needed to complete registration, please send at least one and try '
                'again with `!submit`')
        else:
            # He's finished
            print(f'Submitting player: {user.name}')
            return await confirm_player(request_id, server, user)
Esempio n. 5
0
def test_remove_player_happy_path():
    req1 = persistence.add_to_waiting_list(
        TEST_SERVER_ID,
        MockUser(name=TEST_USER_NAME + '1', id=TEST_USER_NAME + '1'),
        TEST_TOURNAMENT_SIZE)
    persistence.add_deck(req1, TEST_DECK_DESCRIPTION, [TEST_DECK_URL])
    persistence.submit(req1)
    req2 = persistence.add_to_waiting_list(
        TEST_SERVER_ID,
        MockUser(name=TEST_USER_NAME + '2', id=TEST_USER_NAME + '2'),
        TEST_TOURNAMENT_SIZE)
    persistence.add_deck(req2, TEST_DECK_DESCRIPTION, [TEST_DECK_URL])
    anytime = persistence.submit(req2)

    anytime = persistence.remove_player(anytime.doc_id, TEST_USER_NAME + '1')

    assert len(anytime['players']) == 1
    player = anytime['players'][0]
    assert player['user_id'] == TEST_USER_NAME + '2'
Esempio n. 6
0
def test_add_deck():
    request_id = persistence.add_to_waiting_list(
        TEST_SERVER_ID, MockUser(name=TEST_USER_NAME, id=TEST_USER_NAME),
        TEST_TOURNAMENT_SIZE)
    request = persistence.join_requests.get(doc_id=request_id)
    assert len(request['decks']) == 0

    persistence.add_deck(request_id, TEST_DECK_DESCRIPTION, TEST_DECK_URL)
    request = persistence.join_requests.get(doc_id=request_id)
    assert len(request['decks']) == 1
Esempio n. 7
0
def test_add_channel_id_happy_path():
    request_id = persistence.add_to_waiting_list(
        TEST_SERVER_ID, MockUser(name=TEST_USER_NAME, id=TEST_USER_NAME),
        TEST_TOURNAMENT_SIZE)
    persistence.add_deck(request_id, TEST_DECK_DESCRIPTION, [TEST_DECK_URL])
    anytime = persistence.submit(request_id)

    updated_anytime = persistence.add_channel_id(TEST_CHANNEL_ID,
                                                 anytime.doc_id)

    assert updated_anytime is not None
    assert updated_anytime['channel_id'] == TEST_CHANNEL_ID
Esempio n. 8
0
def test_tournament_started_happy_path():
    request_id = persistence.add_to_waiting_list(
        TEST_SERVER_ID, MockUser(name=TEST_USER_NAME, id=TEST_USER_NAME),
        TEST_TOURNAMENT_SIZE)
    persistence.add_deck(request_id, TEST_DECK_DESCRIPTION, [TEST_DECK_URL])
    anytime = persistence.submit(request_id)

    started_anytime = persistence.tournament_started(anytime.doc_id,
                                                     TEST_TOURNAMENT_ID)

    assert started_anytime is not None
    assert started_anytime['status'] == persistence.AnytimeStatus.RUNNING
    assert started_anytime['tournament_id'] == TEST_TOURNAMENT_ID
Esempio n. 9
0
def test_submit_existing_anytime():
    req1 = persistence.add_to_waiting_list(
        TEST_SERVER_ID,
        MockUser(name=TEST_USER_NAME + '1', id=TEST_USER_NAME + '1'),
        TEST_TOURNAMENT_SIZE)
    persistence.add_deck(req1, TEST_DECK_DESCRIPTION, [TEST_DECK_URL])
    persistence.submit(req1)

    req2 = persistence.add_to_waiting_list(
        TEST_SERVER_ID,
        MockUser(name=TEST_USER_NAME + '2', id=TEST_USER_NAME + '2'),
        TEST_TOURNAMENT_SIZE)
    persistence.add_deck(req2, TEST_DECK_DESCRIPTION, [TEST_DECK_URL])
    anytime = persistence.submit(req2)

    assert len(persistence.join_requests.all()) == 0
    assert len(persistence.anytimes.all()) == 1
    assert len(anytime['players']) == 2
    player1 = anytime['players'][0]
    player2 = anytime['players'][1]
    assert player1['user_name'] == TEST_USER_NAME + '1'
    assert player2['user_name'] == TEST_USER_NAME + '2'
Esempio n. 10
0
def test_submit_no_anytimes():
    request_id = persistence.add_to_waiting_list(
        TEST_SERVER_ID, MockUser(name=TEST_USER_NAME, id=TEST_USER_NAME),
        TEST_TOURNAMENT_SIZE)
    persistence.add_deck(request_id, TEST_DECK_DESCRIPTION, [TEST_DECK_URL])

    anytime = persistence.submit(request_id)

    assert len(persistence.join_requests.all()) == 0
    assert len(persistence.anytimes.all()) == 1
    assert anytime['server_id'] == TEST_SERVER_ID
    assert anytime['size'] == TEST_TOURNAMENT_SIZE
    assert anytime['status'] == persistence.AnytimeStatus.RECRUITING
    assert len(anytime['players']) == 1
    player = anytime['players'][0]
    assert player['user_id'] == TEST_USER_NAME
    assert player['user_name'] == TEST_USER_NAME
    assert len(player['decks']) == 1
    deck = player['decks'][0]
    assert deck['text'] == TEST_DECK_DESCRIPTION
    assert len(deck['urls']) == 1
    assert deck['urls'][0] == TEST_DECK_URL