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'
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
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'
async def confirm_player(request_id, server, user): # Transition user's request to accepted registration anytime_data = persistence.submit(request_id) if anytime_data is None: await user.send( 'I\'m sorry, there was a problem with your registration.' 'Please try again by typing `!enterticket`') return # Retrieve anytime channel anytime_channel = server.get_channel( anytime_data['channel_id']) if 'channel_id' in anytime_data else None if anytime_channel is None: # First submitted player: create channel anytime_channel = await create_anytime_channel(server, anytime_data.doc_id) await anytime_channel.send( f'Hi everyone! This is the channel we\'ll use for the ' f'Anytime Tournament #{anytime_data.doc_id}') anytime_data = persistence.add_channel_id(anytime_channel.id, anytime_data.doc_id) # Notify user in the anytime channel participant_role = await get_participant_role(server, anytime_data.doc_id) await user.add_roles(participant_role) await anytime_channel.send(f'{user.mention} joins the battle!') # Check that everyone still has a ticket, exit the ones that does not for player in anytime_data['players']: discord_player = server.get_member(player['user_id']) if not config.has_ticket(server.name, discord_player): await discord_player.remove_roles(participant_role) persistence.remove_player(anytime_data.doc_id, player['user_id']) await discord_player.send( f'Hey, you don\'t seem to have a ticket anymore, so you were removed from' f' the Anytime #{anytime_data.doc_id}. If you think this is an error,' f'please contact an Anytime Mod!') return anytime_data
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
def test_submit_no_request(): assert persistence.submit('random string') is None