def test_only_get_new_messages(): test_iid = test_utils.make_instance() mtype = 'test' contents = ['quack', 'duck'] test_utils.send_new_message(test_iid, mtype, [firstpid], contents) response = test_utils.get_messages(test_iid, mtype, '', 1) date = response[0]['mtime'] assert date response = test_utils.get_messages(test_iid, mtype, date, 1) assert len(response) == 0 test_utils.send_new_message(test_iid, mtype, [firstpid], contents) response = test_utils.get_messages(test_iid, mtype, date, 1) assert len(response) == 1
def test_send_message_to_multiple_people(): test_iid = test_utils.make_instance() mtype = 'test' contents = ['quack', 'duck'] player2 = '*****@*****.**' test_utils.add_player(test_iid, player2) test_utils.send_new_message(test_iid, 'type1', [firstpid, player2], contents) test_utils.send_new_message(test_iid, 'type2', [firstpid, player2], contents) response = test_utils.get_messages(test_iid, '', '', 2) assert response[0]['type'] == 'type1' assert response[1]['type'] == 'type2' response = test_utils.get_messages(test_iid, '', '', 2, pid = player2) assert response[0]['type'] == 'type1' assert response[1]['type'] == 'type2'
def test_send_message_to_multiple_people(): test_iid = test_utils.make_instance() mtype = 'test' contents = ['quack', 'duck'] player2 = '*****@*****.**' test_utils.add_player(test_iid, player2) test_utils.send_new_message(test_iid, 'type1', [firstpid, player2], contents) test_utils.send_new_message(test_iid, 'type2', [firstpid, player2], contents) response = test_utils.get_messages(test_iid, '', '', 2) assert response[0]['type'] == 'type1' assert response[1]['type'] == 'type2' response = test_utils.get_messages(test_iid, '', '', 2, pid=player2) assert response[0]['type'] == 'type1' assert response[1]['type'] == 'type2'
def test_get_all_types(): test_iid = test_utils.make_instance() mtype = 'test' contents = ['quack', 'duck'] test_utils.send_new_message(test_iid, 'type1', [firstpid], contents) test_utils.send_new_message(test_iid, 'type2', [firstpid], contents) response = test_utils.get_messages(test_iid, '', '', 2) assert response[0]['type'] == 'type1' assert response[1]['type'] == 'type2'
def test_send_message_to_empty(): test_iid = test_utils.make_instance() mtype = 'test' contents = ['quack', 'duck'] test_utils.send_new_message(test_iid, mtype, '', contents) response = test_utils.get_messages(test_iid, mtype, '', 1) assert response[0]['type'] == mtype assert response[0]['contents'] == ['quack', 'duck']
def test_messages_email_strip(): test_iid = test_utils.make_instance() mtype = 'test' contents = ['quack', 'duck'] recipient = ['"Bob Jones" <*****@*****.**>'] test_utils.send_new_message(test_iid, mtype, recipient, contents, pid = '"Frank Lloyd" <*****@*****.**>') response = test_utils.get_messages(test_iid, mtype, '', 1, pid = '"Bob Johnson" <*****@*****.**>') assert response[0]['type'] == mtype
def test_player_left(): iid = test_utils.make_instance() for player in init_players: test_utils.add_player(iid, player) # Start the game current_round = 1 response = test_utils.post_server_command(iid, 'ata_new_game', []) instance = test_utils.get_instance_model(iid) noun_cards_left = card_game.cards_left(instance) assert instance.ata_round == current_round # Get the cards for player in players: hand = test_utils.get_messages(iid, 'crd_hand', '', 1, pid=player)[0] assert len(hand['contents']) == 7 player_cards[player] = hand['contents'] player_submissions = {} instance = test_utils.get_instance_model(iid) removed_player = instance.players[2] instance.players.remove(removed_player) instance.put() card = player_cards[player].pop() response = test_utils.post_server_command(iid, 'ata_submit_card', [current_round, card], pid=instance.players[1]) assert len(response['contents']) == 1 instance = test_utils.get_instance_model(iid) assert removed_player in instance.invited test_utils.add_player(iid, removed_player) # Submit cards for player in players: if player != instance.leader: card = player_cards[player].pop() response = test_utils.post_server_command(iid, 'ata_submit_card', [current_round, card], pid=player) player_cards[player] = response['contents'][2] player_submissions[player] = card for c in player_submissions.values(): assert c in response['contents'][1] assert len(player_cards[player]) == 7
def test_player_left(): iid = test_utils.make_instance() for player in init_players: test_utils.add_player(iid, player) # Start the game current_round = 1 response = test_utils.post_server_command(iid, 'ata_new_game', []) instance = test_utils.get_instance_model(iid) noun_cards_left = card_game.cards_left(instance) assert instance.ata_round == current_round # Get the cards for player in players: hand = test_utils.get_messages(iid, 'crd_hand', '', 1, pid = player)[0] assert len(hand['contents']) == 7 player_cards[player] = hand['contents'] player_submissions = {} instance = test_utils.get_instance_model(iid) removed_player = instance.players[2] instance.players.remove(removed_player) instance.put() card = player_cards[player].pop() response = test_utils.post_server_command(iid, 'ata_submit_card', [current_round, card], pid = instance.players[1]) assert len(response['contents']) == 1 instance = test_utils.get_instance_model(iid) assert removed_player in instance.invited test_utils.add_player(iid, removed_player) # Submit cards for player in players: if player != instance.leader: card = player_cards[player].pop() response = test_utils.post_server_command(iid, 'ata_submit_card', [current_round, card], pid = player) player_cards[player] = response['contents'][2] player_submissions[player] = card for c in player_submissions.values(): assert c in response['contents'][1] assert len(player_cards[player]) == 7
def test_messages_email_strip(): test_iid = test_utils.make_instance() mtype = 'test' contents = ['quack', 'duck'] recipient = ['"Bob Jones" <*****@*****.**>'] test_utils.send_new_message(test_iid, mtype, recipient, contents, pid='"Frank Lloyd" <*****@*****.**>') response = test_utils.get_messages(test_iid, mtype, '', 1, pid='"Bob Johnson" <*****@*****.**>') assert response[0]['type'] == mtype
def test_full_game(): iid = test_utils.make_instance() for player in init_players: test_utils.add_player(iid, player) # Start the game current_round = 1 response = test_utils.post_server_command(iid, 'ata_new_game', []) instance = test_utils.get_instance_model(iid) noun_cards_left = card_game.cards_left(instance) assert instance.ata_round == current_round # Get the cards for player in players: hand = test_utils.get_messages(iid, 'crd_hand', '', 1, pid = player)[0] assert len(hand['contents']) == 7 player_cards[player] = hand['contents'] player_submissions = {} # Submit cards for player in players: if player != instance.leader: card = player_cards[player].pop() response = test_utils.post_server_command(iid, 'ata_submit_card', [current_round, card], pid = player) player_cards[player] = response['contents'][2] player_submissions[player] = card for c in player_submissions.values(): assert c in response['contents'][1] assert len(player_cards[player]) == 7 instance = test_utils.get_instance_model(iid) assert noun_cards_left - len(players) + 1 == card_game.cards_left(instance) for player in players: response = test_utils.get_messages(iid, 'ata_submissions', '', 1, pid = player)[0] for c in player_submissions.values(): assert c in response['contents'][1] assert response['contents'][0] == current_round # Choose a winner winner = [x for x in players if x != instance.leader][0] contents = test_utils.post_server_command(iid, 'ata_end_turn', [current_round, player_submissions[winner]], pid = instance.leader)['contents'] assert contents[2] == 2 assert contents[3] == winner assert contents[4] == player_submissions[winner] assert [1, winner] in contents[1] current_round = current_round + 1 instance = test_utils.get_instance_model(iid) assert instance.ata_round == current_round # Check for next round messages for player in players: new_round_msg = test_utils.get_messages(iid, 'ata_new_round', '', 1, pid = player)[0]['contents'] assert new_round_msg[2] == 2 assert new_round_msg[3] == winner assert new_round_msg[4] == player_submissions[winner] # Accelerate the game, next point wins for player in players: scoreboard.set_score(instance, player, 4) instance.put() winner = [x for x in players if x != instance.leader][0] winning_card = player_cards[winner][0] test_utils.post_server_command(iid, 'ata_submit_card', [current_round, winning_card], pid = winner) contents = test_utils.post_server_command(iid, 'ata_end_turn', [current_round, winning_card], pid = instance.leader)['contents'] assert contents[0] == current_round assert contents[1] == winning_card assert [5, winner] in contents[2] # Check for game over messages for player in players: contents = test_utils.get_messages(iid, 'ata_game_over', '', 1, pid = player)[0]['contents'] assert contents[0] == current_round assert contents[1] == winning_card assert [5, winner] in contents[2] instance = test_utils.get_instance_model(iid) assert 'ata_round' not in instance.dynamic_properties() assert 'ata_char_card' not in instance.dynamic_properties() assert 'ata_submissions' not in instance.dynamic_properties()
def test_full_game(): iid = test_utils.make_instance() for player in init_players: test_utils.add_player(iid, player) # Start the game current_round = 1 response = test_utils.post_server_command(iid, 'ata_new_game', []) instance = test_utils.get_instance_model(iid) noun_cards_left = card_game.cards_left(instance) assert instance.ata_round == current_round # Get the cards for player in players: hand = test_utils.get_messages(iid, 'crd_hand', '', 1, pid=player)[0] assert len(hand['contents']) == 7 player_cards[player] = hand['contents'] player_submissions = {} # Submit cards for player in players: if player != instance.leader: card = player_cards[player].pop() response = test_utils.post_server_command(iid, 'ata_submit_card', [current_round, card], pid=player) player_cards[player] = response['contents'][2] player_submissions[player] = card for c in player_submissions.values(): assert c in response['contents'][1] assert len(player_cards[player]) == 7 instance = test_utils.get_instance_model(iid) assert noun_cards_left - len(players) + 1 == card_game.cards_left(instance) for player in players: response = test_utils.get_messages(iid, 'ata_submissions', '', 1, pid=player)[0] for c in player_submissions.values(): assert c in response['contents'][1] assert response['contents'][0] == current_round # Choose a winner winner = [x for x in players if x != instance.leader][0] contents = test_utils.post_server_command( iid, 'ata_end_turn', [current_round, player_submissions[winner]], pid=instance.leader)['contents'] assert contents[2] == 2 assert contents[3] == winner assert contents[4] == player_submissions[winner] assert [1, winner] in contents[1] current_round = current_round + 1 instance = test_utils.get_instance_model(iid) assert instance.ata_round == current_round # Check for next round messages for player in players: new_round_msg = test_utils.get_messages(iid, 'ata_new_round', '', 1, pid=player)[0]['contents'] assert new_round_msg[2] == 2 assert new_round_msg[3] == winner assert new_round_msg[4] == player_submissions[winner] # Accelerate the game, next point wins for player in players: scoreboard.set_score(instance, player, 4) instance.put() winner = [x for x in players if x != instance.leader][0] winning_card = player_cards[winner][0] test_utils.post_server_command(iid, 'ata_submit_card', [current_round, winning_card], pid=winner) contents = test_utils.post_server_command(iid, 'ata_end_turn', [current_round, winning_card], pid=instance.leader)['contents'] assert contents[0] == current_round assert contents[1] == winning_card assert [5, winner] in contents[2] # Check for game over messages for player in players: contents = test_utils.get_messages(iid, 'ata_game_over', '', 1, pid=player)[0]['contents'] assert contents[0] == current_round assert contents[1] == winning_card assert [5, winner] in contents[2] instance = test_utils.get_instance_model(iid) assert 'ata_round' not in instance.dynamic_properties() assert 'ata_char_card' not in instance.dynamic_properties() assert 'ata_submissions' not in instance.dynamic_properties()
def get_player_hand(iid, pid): response = test_utils.get_messages(iid, 'crd_hand', '', 1, pid) return response[0]['contents']