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
def test_remove_player_missing_player(): 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) anytime = persistence.remove_player(anytime.doc_id, TEST_USER_NAME + '2') assert len(anytime['players']) == 1 player = anytime['players'][0] assert player['user_id'] == TEST_USER_NAME
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
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
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)
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'
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