def test_cast_vote():
    iid = test_utils.make_instance()
    poll_id = make_poll(iid)
    contents = test_utils.post_server_command(iid, 'vot_cast_vote',
                                              [poll_id, 1])['contents']
    assert contents[1] == [0, 1]
    assert contents[0] == 'Vote accepted.'
def test_with_two_players():
    iid = test_utils.make_instance()
    test_utils.add_player(iid, '*****@*****.**')
    game_id = new_game(iid)
    bob_game_id = new_game(iid, '*****@*****.**')
    assert get_game(iid, game_id)
    assert get_game(iid, bob_game_id)
def test_resend_guess():
    iid = test_utils.make_instance()
    game_id = new_game(iid)
    game = get_game(iid, game_id)
    guess = game.bac_solution[::-1]
    score = game.bac_score
    guesses = game.bac_guesses_remaining
    response = test_utils.post_server_command(iid, 'bac_guess',
                                              [game_id, guess])
    assert response['contents'] == [guesses - 1, score - 4, 0, 4]
    response = test_utils.post_server_command(iid, 'bac_guess',
                                              [game_id, guess])
    assert response['contents'] == [guesses - 1, score - 4, 0, 4]
    guess = [game.bac_solution[0]] * 4
    response = test_utils.post_server_command(iid, 'bac_guess',
                                              [game_id, guess])
    assert response['contents'] == [guesses - 2, score - 7, 1, 3]
    response = test_utils.post_server_command(iid, 'bac_guess',
                                              [game_id, guess])
    assert response['contents'] == [guesses - 2, score - 7, 1, 3]
    guess = game.bac_solution
    response = test_utils.post_server_command(iid, 'bac_guess',
                                              [game_id, guess])
    assert response['contents'] == [[score - 7, score - 7, 1], True]
    response = test_utils.post_server_command(iid, 'bac_guess',
                                              [game_id, guess])
    assert response['contents'] == [[score - 7, score - 7, 1], True]
def test_cast_vote():
  iid = test_utils.make_instance()
  poll_id = make_poll(iid)
  contents = test_utils.post_server_command(iid, 'vot_cast_vote',
                                            [poll_id, 1])['contents']
  assert contents[1] == [0, 1]
  assert contents[0] == 'Vote accepted.'
def test_leave_instance():
    test_utils.clear_data_store()
    iid = test_utils.make_instance()
    other = '*****@*****.**'
    test_utils.add_player(iid, other)
    response = app.post('/leaveinstance', {
        'gid': gid,
        'iid': iid,
        'pid': firstpid
    }).json
    assert response['e'] is False
    assert response['request_type'] == '/leaveinstance'
    assert response['leader'] == ''
    assert response['response']['joined'] == []
    response = app.post('/leaveinstance', {
        'gid': gid,
        'iid': iid,
        'pid': other
    }).json
    assert response['e'] is False
    assert response['request_type'] == '/leaveinstance'
    assert response['leader'] == ''
    assert response['iid'] == ''
    assert response['response']['joined'] == []
    response = app.post('/joininstance', {
        'gid': gid,
        'iid': iid,
        'pid': firstpid
    }).json
    assert response['e'] is True
def test_with_two_players():
    iid = test_utils.make_instance()
    test_utils.add_player(iid, "*****@*****.**")
    game_id = new_game(iid)
    bob_game_id = new_game(iid, "*****@*****.**")
    assert get_game(iid, game_id)
    assert get_game(iid, bob_game_id)
def test_clear_data():
  test_iid = test_utils.make_instance()
  response = app.post('/getinstance', {'gid': gid, 'iid' : test_iid})
  assert response.json['e'] is False
  test_utils.clear_data_store()
  response = app.post('/getinstance', {'gid': gid, 'iid' : test_iid})
  assert response.json['e'] is True
def test_clear_data():
    test_iid = test_utils.make_instance()
    response = app.post('/getinstance', {'gid': gid, 'iid': test_iid})
    assert response.json['e'] is False
    test_utils.clear_data_store()
    response = app.post('/getinstance', {'gid': gid, 'iid': test_iid})
    assert response.json['e'] is True
def test_get_reslts_before_voting_in_closed_poll():
    iid = test_utils.make_instance()
    poll_id = make_poll(iid)
    test_utils.post_server_command(iid, 'vot_close_poll',
                                   [poll_id])['contents']
    contents = test_utils.post_server_command(iid, 'vot_get_results',
                                              [poll_id])['contents']
    assert contents == ['Poll is now closed.', [0, 0]]
def test_get_results():
    iid = test_utils.make_instance()
    poll_id = make_poll(iid)
    test_utils.post_server_command(iid, 'vot_cast_vote',
                                   [poll_id, 1])['contents']
    contents = test_utils.post_server_command(iid, 'vot_get_results',
                                              [poll_id])['contents']
    assert contents == ['You have already voted in this poll.', [0, 1]]
def test_delete_poll():
  iid = test_utils.make_instance()
  poll_id = make_poll(iid)
  contents = test_utils.post_server_command(iid, 'vot_delete_poll',
                                            [poll_id])['contents']
  assert contents == [True]
  poll = get_poll(iid, poll_id)
  assert not poll
def test_delete_poll():
    iid = test_utils.make_instance()
    poll_id = make_poll(iid)
    contents = test_utils.post_server_command(iid, 'vot_delete_poll',
                                              [poll_id])['contents']
    assert contents == [True]
    poll = get_poll(iid, poll_id)
    assert not poll
def test_get_results():
  iid = test_utils.make_instance()
  poll_id = make_poll(iid)
  test_utils.post_server_command(iid, 'vot_cast_vote',
                                 [poll_id, 1])['contents']
  contents = test_utils.post_server_command(iid, 'vot_get_results',
                                            [poll_id])['contents']
  assert contents == ['You have already voted in this poll.', [0, 1]]
def test_get_reslts_before_voting_in_closed_poll():
  iid = test_utils.make_instance()
  poll_id = make_poll(iid)
  test_utils.post_server_command(iid, 'vot_close_poll',
                                 [poll_id])['contents']
  contents = test_utils.post_server_command(iid, 'vot_get_results',
                                            [poll_id])['contents']
  assert contents == ['Poll is now closed.', [0, 0]]
def test_delete_instance():
    test_iid = test_utils.make_instance()
    state = test_utils.get_invited_and_joined_instances(test_iid, firstpid)
    assert test_iid in state["joined"]
    test_utils.post_server_command(test_iid, "sys_delete_instance", [])
    assert not test_utils.get_instance_model(test_iid)
    state = test_utils.get_invited_and_joined_instances("", firstpid)
    assert test_iid not in state["joined"]
def test_out_of_guesses():
    iid = test_utils.make_instance()
    game_id = new_game(iid)
    game = get_game(iid, game_id)
    game.bac_guesses_remaining = 0
    game.put()
    guess = ["Blue", "Yellow", "Green", "Red"]
    test_utils.post_server_command(iid, "bac_guess", [game_id, [guess]], error_expected=True)
def test_get_only_my_polls():
    iid = test_utils.make_instance()
    poll_id = make_poll(iid)
    test_utils.add_player(iid, '*****@*****.**')
    make_poll(iid, pid='*****@*****.**')
    contents = test_utils.post_server_command(iid, 'vot_get_my_polls',
                                              [])['contents']
    assert len(contents) == 1
    assert contents[0] == [poll_id, question]
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_close_poll():
  iid = test_utils.make_instance()
  poll_id = make_poll(iid)
  contents = test_utils.post_server_command(iid, 'vot_close_poll',
                                            [poll_id])['contents']
  assert contents == [question, choices, poll_id, [0] * len(choices), False]
  poll = get_poll(iid, poll_id)
  assert poll.msg_type == 'closed_poll'
  assert poll.open == False
def test_get_only_my_polls():
  iid = test_utils.make_instance()
  poll_id = make_poll(iid)
  test_utils.add_player(iid, '*****@*****.**')
  make_poll(iid, pid = '*****@*****.**')
  contents = test_utils.post_server_command(iid, 'vot_get_my_polls',
                                            [])['contents']
  assert len(contents) == 1
  assert contents[0] == [poll_id, question]
def test_cast_vote_twice():
  iid = test_utils.make_instance()
  poll_id = make_poll(iid)
  test_utils.post_server_command(iid, 'vot_cast_vote',
                                 [poll_id, 1])['contents']
  contents = test_utils.post_server_command(iid, 'vot_cast_vote',
                                            [poll_id, 1])['contents']
  assert contents[1] == [0, 1]
  assert contents[0] == 'Your vote was already counted in this poll.'
def test_cast_vote_to_closed_poll():
  iid = test_utils.make_instance()
  poll_id = make_poll(iid)
  test_utils.post_server_command(iid, 'vot_close_poll',
                                 [poll_id])['contents']
  contents = test_utils.post_server_command(iid, 'vot_cast_vote',
                                            [poll_id, 1])['contents']
  assert contents[1] == [0, 0]
  assert contents[0] == 'Poll closed to new votes.'
def test_cast_vote_to_closed_poll():
    iid = test_utils.make_instance()
    poll_id = make_poll(iid)
    test_utils.post_server_command(iid, 'vot_close_poll',
                                   [poll_id])['contents']
    contents = test_utils.post_server_command(iid, 'vot_cast_vote',
                                              [poll_id, 1])['contents']
    assert contents[1] == [0, 0]
    assert contents[0] == 'Poll closed to new votes.'
def test_cast_vote_twice():
    iid = test_utils.make_instance()
    poll_id = make_poll(iid)
    test_utils.post_server_command(iid, 'vot_cast_vote',
                                   [poll_id, 1])['contents']
    contents = test_utils.post_server_command(iid, 'vot_cast_vote',
                                              [poll_id, 1])['contents']
    assert contents[1] == [0, 1]
    assert contents[0] == 'Your vote was already counted in this poll.'
def test_close_poll():
    iid = test_utils.make_instance()
    poll_id = make_poll(iid)
    contents = test_utils.post_server_command(iid, 'vot_close_poll',
                                              [poll_id])['contents']
    assert contents == [question, choices, poll_id, [0] * len(choices), False]
    poll = get_poll(iid, poll_id)
    assert poll.msg_type == 'closed_poll'
    assert poll.open == False
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_leader_fails_at_submitting():
  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', [])
  test_utils.post_server_command(iid, 'ata_submit_card',
                                 [current_round, ''],
                                 pid = firstpid, error_expected = True)
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_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_not_your_game():
    bob = '*****@*****.**'
    iid = test_utils.make_instance()
    test_utils.add_player(iid, bob)
    game_id = new_game(iid)
    response = test_utils.post_server_command(iid,
                                              'bac_guess',
                                              [game_id, ['Blue'] * 4],
                                              pid=bob,
                                              error_expected=True)
def test_out_of_guesses():
    iid = test_utils.make_instance()
    game_id = new_game(iid)
    game = get_game(iid, game_id)
    game.bac_guesses_remaining = 0
    game.put()
    guess = ['Blue', 'Yellow', 'Green', 'Red']
    test_utils.post_server_command(iid,
                                   'bac_guess', [game_id, [guess]],
                                   error_expected=True)
def test_new_leader_must_be_in_game():
  test_iid = test_utils.make_instance()
  fake_player = '*****@*****.**'

  response = app.post('/setleader', {'gid': gid, 'iid' : test_iid,
                                     'pid' : firstpid,
                                     'leader' : fake_player}).json
  assert response['e'] is True
  assert response['leader'] == ''
  assert response['request_type'] == '/setleader'
示例#33
0
def test_leader_fails_at_submitting():
    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', [])
    test_utils.post_server_command(iid,
                                   'ata_submit_card', [current_round, ''],
                                   pid=firstpid,
                                   error_expected=True)
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_got_solution():
    iid = test_utils.make_instance()
    game_id = new_game(iid)
    game = get_game(iid, game_id)
    guess = game.bac_solution
    score = game.bac_score
    guesses = game.bac_guesses_remaining
    response = test_utils.post_server_command(iid, "bac_guess", [game_id, guess])
    assert response["contents"] == [[score, score, 1], True]
    game = get_game(iid, game_id)
    assert game.bac_guesses_remaining == 0
def test_email_parse():
  invitee = '<Invitee> [email protected]'
  invitee_email = '*****@*****.**'
  test_iid = test_utils.make_instance()
  response = app.post('/invite', {'gid': gid, 'iid' : test_iid,
                                  'inv' : invitee}).json
  assert response['response']['inv'] == invitee_email
  state = test_utils.get_invited_and_joined_instances(test_iid, invitee_email)
  assert test_iid in state['invited']
  state = test_utils.get_invited_and_joined_instances(test_iid, invitee)
  assert test_iid in state['invited']
def test_delete_instance_and_messages():
    test_iid = test_utils.make_instance()
    instance = test_utils.get_instance_model(test_iid)
    for i in xrange(10):
        message = Message(parent=instance, sender=firstpid, msg_type="blah", recipient=firstpid, content="%d" % i)
        message.put()
    messages = Message.all(keys_only=True).ancestor(instance.key()).fetch(1000)
    assert len(messages) == 10
    test_utils.post_server_command(test_iid, "sys_delete_instance", [])
    messages = Message.all(keys_only=True).ancestor(instance.key()).fetch(1000)
    assert len(messages) == 0
def test_invite_player():
  test_iid = test_utils.make_instance()
  invitee = '*****@*****.**'
  response = app.post('/invite', {'gid': gid, 'iid' : test_iid,
                                  'inv' : invitee}).json
  assert response['e'] is False
  assert response['response']['inv'] == invitee
  assert response['request_type'] == '/invite'

  state = test_utils.get_invited_and_joined_instances(test_iid, invitee)
  assert test_iid in state['invited']
def test_got_solution():
    iid = test_utils.make_instance()
    game_id = new_game(iid)
    game = get_game(iid, game_id)
    guess = game.bac_solution
    score = game.bac_score
    guesses = game.bac_guesses_remaining
    response = test_utils.post_server_command(iid, 'bac_guess',
                                              [game_id, guess])
    assert response['contents'] == [[score, score, 1], True]
    game = get_game(iid, game_id)
    assert game.bac_guesses_remaining == 0
def test_guesses():
    iid = test_utils.make_instance()
    game_id = new_game(iid)
    game = get_game(iid, game_id)
    guess = game.bac_solution[::-1]
    score = game.bac_score
    guesses = game.bac_guesses_remaining
    response = test_utils.post_server_command(iid, "bac_guess", [game_id, guess])
    assert response["contents"] == [guesses - 1, score - 4, 0, 4]
    guess = [game.bac_solution[0]] * 4
    response = test_utils.post_server_command(iid, "bac_guess", [game_id, guess])
    assert response["contents"] == [guesses - 2, score - 7, 1, 3]
def test_new_leader_must_be_in_game():
    test_iid = test_utils.make_instance()
    fake_player = '*****@*****.**'

    response = app.post('/setleader', {
        'gid': gid,
        'iid': test_iid,
        'pid': firstpid,
        'leader': fake_player
    }).json
    assert response['e'] is True
    assert response['leader'] == ''
    assert response['request_type'] == '/setleader'
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_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_invite_player_already_joined():
  test_iid = test_utils.make_instance()
  invitee = '*****@*****.**'
  test_utils.add_player(test_iid, invitee)
  response = app.post('/invite', {'gid': gid, 'iid' : test_iid,
                                  'inv' : invitee}).json
  assert response['e'] is False
  assert response['response']['inv'] == ''
  assert response['request_type'] == '/invite'

  instance_lists = test_utils.get_invited_and_joined_instances(test_iid,
                                                               invitee)
  assert test_iid in instance_lists['joined']
  assert test_iid not in instance_lists['invited']
def test_invite_player():
    test_iid = test_utils.make_instance()
    invitee = '*****@*****.**'
    response = app.post('/invite', {
        'gid': gid,
        'iid': test_iid,
        'inv': invitee
    }).json
    assert response['e'] is False
    assert response['response']['inv'] == invitee
    assert response['request_type'] == '/invite'

    state = test_utils.get_invited_and_joined_instances(test_iid, invitee)
    assert test_iid in state['invited']
def test_decline_invite():
    test_iid = test_utils.make_instance()
    invitee = "*****@*****.**"
    response = app.post("/invite", {"gid": gid, "iid": test_iid, "inv": invitee}).json
    assert response["e"] is False
    assert response["response"]["inv"] == invitee
    assert response["request_type"] == "/invite"

    state = test_utils.get_invited_and_joined_instances(test_iid, invitee)
    assert test_iid in state["invited"]

    test_utils.post_server_command(test_iid, "sys_decline_invite", [], pid=invitee)
    state = test_utils.get_invited_and_joined_instances(test_iid, invitee)
    assert test_iid not in state["invited"]
def test_email_parse():
    invitee = '<Invitee> [email protected]'
    invitee_email = '*****@*****.**'
    test_iid = test_utils.make_instance()
    response = app.post('/invite', {
        'gid': gid,
        'iid': test_iid,
        'inv': invitee
    }).json
    assert response['response']['inv'] == invitee_email
    state = test_utils.get_invited_and_joined_instances(
        test_iid, invitee_email)
    assert test_iid in state['invited']
    state = test_utils.get_invited_and_joined_instances(test_iid, invitee)
    assert test_iid in state['invited']
示例#49
0
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_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_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_two_games_at_once():
    bob = "*****@*****.**"
    iid = test_utils.make_instance()
    test_utils.add_player(iid, bob)
    game_id = new_game(iid)
    bob_game_id = new_game(iid, bob)
    game = get_game(iid, game_id)
    bob_game = get_game(iid, bob_game_id)
    guess = game.bac_solution[::-1]
    score = game.bac_score
    response = test_utils.post_server_command(iid, "bac_guess", [game_id, guess])
    guess = bob_game.bac_solution
    response = test_utils.post_server_command(iid, "bac_guess", [bob_game_id, guess], pid=bob)
    assert response["contents"] == [[score, score, 1], True]
    guess = game.bac_solution
    response = test_utils.post_server_command(iid, "bac_guess", [game_id, guess])
    assert response["contents"] == [[score - 4, score - 4, 1], True]
def test_invite_player_already_joined():
    test_iid = test_utils.make_instance()
    invitee = '*****@*****.**'
    test_utils.add_player(test_iid, invitee)
    response = app.post('/invite', {
        'gid': gid,
        'iid': test_iid,
        'inv': invitee
    }).json
    assert response['e'] is False
    assert response['response']['inv'] == ''
    assert response['request_type'] == '/invite'

    instance_lists = test_utils.get_invited_and_joined_instances(
        test_iid, invitee)
    assert test_iid in instance_lists['joined']
    assert test_iid not in instance_lists['invited']
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_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)
  assert len(contents[1]) == 7
  assert contents[2] == current_round
  assert contents[3] == char_card
  contents = test_utils.post_server_command(iid, 'ata_end_turn', [2, ''],
                                            pid = firstpid)['contents']
  assert isinstance(contents[0], basestring)
  assert len(contents[1]) == 7
  assert contents[2] == current_round
  assert contents[3] == char_card
def test_only_leader_can_set_new_leader():
  test_iid = test_utils.make_instance()
  new_player = '*****@*****.**'
  test_utils.add_player(test_iid, new_player)

  response = app.post('/setleader', {'gid': gid, 'iid' : test_iid,
                                     'pid' : new_player,
                                     'leader' : new_player}).json
  assert response['e'] is False
  assert response['leader'] == firstpid
  assert response['response']['leader_changed'] == False
  assert response['response']['current_leader'] == firstpid
  assert response['request_type'] == '/setleader'

  response = app.post('/getinstancelists',
                      {'gid': gid,
                       'iid' : test_iid,
                       'pid' : firstpid}).json
  assert response['leader'] == firstpid
示例#57
0
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)
    assert len(contents[1]) == 7
    assert contents[2] == current_round
    assert contents[3] == char_card
    contents = test_utils.post_server_command(iid,
                                              'ata_end_turn', [2, ''],
                                              pid=firstpid)['contents']
    assert isinstance(contents[0], basestring)
    assert len(contents[1]) == 7
    assert contents[2] == current_round
    assert contents[3] == char_card
def test_two_games_at_once():
    bob = '*****@*****.**'
    iid = test_utils.make_instance()
    test_utils.add_player(iid, bob)
    game_id = new_game(iid)
    bob_game_id = new_game(iid, bob)
    game = get_game(iid, game_id)
    bob_game = get_game(iid, bob_game_id)
    guess = game.bac_solution[::-1]
    score = game.bac_score
    response = test_utils.post_server_command(iid, 'bac_guess',
                                              [game_id, guess])
    guess = bob_game.bac_solution
    response = test_utils.post_server_command(iid,
                                              'bac_guess',
                                              [bob_game_id, guess],
                                              pid=bob)
    assert response['contents'] == [[score, score, 1], True]
    guess = game.bac_solution
    response = test_utils.post_server_command(iid, 'bac_guess',
                                              [game_id, guess])
    assert response['contents'] == [[score - 4, score - 4, 1], True]
def test_join_instance():
    test_utils.clear_data_store()
    test_iid = test_utils.make_instance()
    invitee = '*****@*****.**'
    app.post('/invite', {'gid': gid, 'iid': test_iid, 'inv': invitee})
    instances = test_utils.get_invited_and_joined_instances(test_iid, invitee)
    assert instances['invited'] == [test_iid]
    assert instances['joined'] == []

    response = app.post('/joininstance', {
        'gid': gid,
        'iid': test_iid,
        'pid': invitee
    }).json
    assert response['e'] is False
    assert response['request_type'] == '/joininstance'

    instances = test_utils.get_invited_and_joined_instances(test_iid, invitee)
    assert instances['invited'] == response['response']['invited']
    assert instances['joined'] == response['response']['joined']
    assert test_iid not in instances['invited']
    assert test_iid in instances['joined']
def test_only_leader_can_set_new_leader():
    test_iid = test_utils.make_instance()
    new_player = '*****@*****.**'
    test_utils.add_player(test_iid, new_player)

    response = app.post('/setleader', {
        'gid': gid,
        'iid': test_iid,
        'pid': new_player,
        'leader': new_player
    }).json
    assert response['e'] is False
    assert response['leader'] == firstpid
    assert response['response']['leader_changed'] == False
    assert response['response']['current_leader'] == firstpid
    assert response['request_type'] == '/setleader'

    response = app.post('/getinstancelists', {
        'gid': gid,
        'iid': test_iid,
        'pid': firstpid
    }).json
    assert response['leader'] == firstpid