def test_pass_cards(): iid = test_utils.make_instance_with_players() args = [7, True, True, False, players] response = test_utils.post_server_command(iid, 'crd_deal_cards', args) hands = get_hands(iid) # Player 2 passes four cards to player 1 passing_player = check_playerid(players[1]) initial_hand = hands[passing_player] args = [firstpid, initial_hand[3:]] response = test_utils.post_server_command(iid, 'crd_pass_cards', args, pid = passing_player) assert response['contents'] == initial_hand[:3] hands = get_hands(iid) assert len(hands[firstpid]) == 11 assert hands[firstpid][7:] == initial_hand[3:] # Player 1 passes all cards to player 3 receiving_player = check_playerid(players[2]) args = [receiving_player, hands[firstpid]] response = test_utils.post_server_command(iid, 'crd_pass_cards', args) assert response['contents'] == [] hands = get_hands(iid) assert len(hands[firstpid]) == 0 assert len(hands[receiving_player]) == 18
def test_pass_cards(): iid = test_utils.make_instance_with_players() args = [7, True, True, False, players] response = test_utils.post_server_command(iid, 'crd_deal_cards', args) hands = get_hands(iid) # Player 2 passes four cards to player 1 passing_player = check_playerid(players[1]) initial_hand = hands[passing_player] args = [firstpid, initial_hand[3:]] response = test_utils.post_server_command(iid, 'crd_pass_cards', args, pid=passing_player) assert response['contents'] == initial_hand[:3] hands = get_hands(iid) assert len(hands[firstpid]) == 11 assert hands[firstpid][7:] == initial_hand[3:] # Player 1 passes all cards to player 3 receiving_player = check_playerid(players[2]) args = [receiving_player, hands[firstpid]] response = test_utils.post_server_command(iid, 'crd_pass_cards', args) assert response['contents'] == [] hands = get_hands(iid) assert len(hands[firstpid]) == 0 assert len(hands[receiving_player]) == 18
def test_set_score(): iid = test_utils.make_instance_with_players() response = set_score(iid, firstpid, 100) assert [100, firstpid] == response['contents'][0] set_score(iid, firstpid, 200) response = set_score(iid, players[1], 400) assert [400, check_playerid(players[1])] == response['contents'][0] assert [200, firstpid] == response['contents'][1]
def check_leader(self, pid): """ Confirm that a player is the leader of the instance. Args: pid: A string containing the player's email address. Returns: The email address of the leader if pid contains it. Raises: ValueError if the player is not the leader of this instance. """ player = utils.check_playerid(pid) if player == self.leader: return player raise ValueError("You must be the leader to perform this operation.")
def check_player(self, pid): """ Confirm that a player is currently in the instance. Args: pid: A string containing the player's email address. Returns: The email address of the player. Raises: ValueError if the player is not in this instance. """ player = utils.check_playerid(pid) if player in self.players: return player raise ValueError("%s is not in instance %s" % (pid, self.key().name()))
def test_add_to_score(): iid = test_utils.make_instance_with_players() score = 100 # Add the first player to the scoreboard change_response = add_to_score(iid, firstpid, score) response = test_utils.post_server_command(iid, 'scb_get_scoreboard', []) assert response['contents'] == change_response['contents'] assert [score, firstpid] in response['contents'] # Increment first players score and add another player add_to_score(iid, firstpid, score) add_to_score(iid, players[1], score) response = test_utils.post_server_command(iid, 'scb_get_scoreboard', []) assert [score * 2, players[0]] in response['contents'] assert [score, check_playerid(players[1])] in response['contents']
def test_add_to_score(): iid = test_utils.make_instance_with_players() score = 100 # Add the first player to the scoreboard change_response = add_to_score(iid, firstpid, score) response = test_utils.post_server_command(iid, 'scb_get_scoreboard', []) assert response['contents']==change_response['contents'] assert [score, firstpid] in response['contents'] # Increment first players score and add another player add_to_score(iid, firstpid, score) add_to_score(iid, players[1], score) response = test_utils.post_server_command(iid, 'scb_get_scoreboard', []) assert [score * 2, players[0]] in response['contents'] assert [score, check_playerid(players[1])] in response['contents']
def test_pass_cards_not_present(): iid = test_utils.make_instance_with_players() args = [7, True, True, False, players] response = test_utils.post_server_command(iid, 'crd_deal_cards', args) hands = get_hands(iid) # Player 2 passes four cards to player 1 that she has and two cards that # she doesn't have. passing_player = check_playerid(players[1]) initial_hand = hands[passing_player] args = [firstpid, ['fake_card_1'] + initial_hand[3:] + ['fake_card_2']] response = test_utils.post_server_command(iid, 'crd_pass_cards', args, pid = passing_player) assert response['contents'] == initial_hand[:3] hands = get_hands(iid) assert len(hands[firstpid]) == 11 assert hands[firstpid][7:] == initial_hand[3:]
def test_pass_cards_not_present(): iid = test_utils.make_instance_with_players() args = [7, True, True, False, players] response = test_utils.post_server_command(iid, 'crd_deal_cards', args) hands = get_hands(iid) # Player 2 passes four cards to player 1 that she has and two cards that # she doesn't have. passing_player = check_playerid(players[1]) initial_hand = hands[passing_player] args = [firstpid, ['fake_card_1'] + initial_hand[3:] + ['fake_card_2']] response = test_utils.post_server_command(iid, 'crd_pass_cards', args, pid=passing_player) assert response['contents'] == initial_hand[:3] hands = get_hands(iid) assert len(hands[firstpid]) == 11 assert hands[firstpid][7:] == initial_hand[3:]
""" __authors__ = ['"Bill Magnuson" <*****@*****.**>'] from game_server import utils from game_server.extensions import scoreboard from game_server.extensions import card_game from custom_modules.androids_to_androids import decks from tests import test_utils gid = test_utils.gid firstpid = test_utils.firstpid app = test_utils.app init_players = [firstpid, '"Bob Jones" <*****@*****.**>', '<*****@*****.**>', '*****@*****.**'] players = [utils.check_playerid(pid) for pid in init_players] player_cards = {} def setUp(): test_utils.clear_data_store() def test_wrong_round(): iid = test_utils.make_instance() for player in init_players: test_utils.add_player(iid, player) current_round = 1 response = test_utils.post_server_command(iid, 'ata_new_game', []) char_card = response['contents'][0] contents = test_utils.post_server_command(iid, 'ata_submit_card', [2, ''], pid = firstpid)['contents'] assert isinstance(contents[0], basestring)
__authors__ = ['"Bill Magnuson" <*****@*****.**>'] from game_server import utils from game_server.extensions import scoreboard from game_server.extensions import card_game from custom_modules.androids_to_androids import decks from tests import test_utils gid = test_utils.gid firstpid = test_utils.firstpid app = test_utils.app init_players = [ firstpid, '"Bob Jones" <*****@*****.**>', '<*****@*****.**>', '*****@*****.**' ] players = [utils.check_playerid(pid) for pid in init_players] player_cards = {} def setUp(): test_utils.clear_data_store() def test_wrong_round(): iid = test_utils.make_instance() for player in init_players: test_utils.add_player(iid, player) current_round = 1 response = test_utils.post_server_command(iid, 'ata_new_game', []) char_card = response['contents'][0] contents = test_utils.post_server_command(iid,
def test_check_playerid(): assert utils.check_playerid(players[0]) == '*****@*****.**' assert utils.check_playerid(players[1]) == '*****@*****.**' assert utils.check_playerid(players[2]) == '*****@*****.**'