def test_join_full_game():
    iid = test_utils.make_instance_with_players()
    playerid = "*****@*****.**"
    instance = test_utils.get_instance_model(iid)
    players = len(instance.players)

    # Set the maximum membership to the current number of players
    test_utils.post_server_command(iid, "sys_set_max_players", [players])

    # Invite someone new, confirm that they cannot join the instance.
    app.post("/invite", {"gid": gid, "iid": iid, "inv": playerid})
    instance = test_utils.get_instance_model(iid)
    assert instance.full
    assert playerid in instance.invited
    assert playerid not in instance.players
    response = app.post("/joininstance", {"gid": gid, "iid": iid, "pid": playerid}).json
    assert response["e"] is True
    instance = test_utils.get_instance_model(iid)
    assert instance.full
    assert playerid in instance.invited
    assert playerid not in instance.players

    # Increase the maximum membership by one, retry joining
    test_utils.post_server_command(iid, "sys_set_max_players", [players + 1])
    response = app.post("/joininstance", {"gid": gid, "iid": iid, "pid": playerid}).json
    instance = test_utils.get_instance_model(iid)
    assert instance.full
    assert playerid not in instance.invited
    assert playerid in instance.players
    test_utils.post_server_command(iid, "sys_set_max_players", [0])
    instance = test_utils.get_instance_model(iid)
    assert not instance.full
def test_set_public_with_strings():
    # Make sure new games are not public
    iid = test_utils.make_instance_with_players()

    # Set public to true with lowercase string
    test_utils.post_server_command(iid, "sys_set_public", ["true"])
    instance = test_utils.get_instance_model(iid)
    assert instance.public

    # Set public to false with lowercase string
    test_utils.post_server_command(iid, "sys_set_public", ["false"])
    instance = test_utils.get_instance_model(iid)
    assert not instance.public
def test_set_public():
    # Make sure new games are not public
    iid = test_utils.make_instance_with_players()
    instance = test_utils.get_instance_model(iid)
    assert not instance.public

    # Set public to True
    test_utils.post_server_command(iid, "sys_set_public", [True])
    instance = test_utils.get_instance_model(iid)
    assert instance.public

    # Set public to False
    test_utils.post_server_command(iid, "sys_set_public", [False])
    instance = test_utils.get_instance_model(iid)
    assert not instance.public
def test_join_instance_makes_new_instance():
  test_utils.clear_data_store()
  iid = 'new_iid'
  assert not test_utils.get_game_model()
  assert not test_utils.get_instance_model(iid)
  response = app.post('/joininstance',
                      {'gid': gid,
                       'iid' : iid,
                       'pid' : firstpid}).json
  assert response['iid'] == iid
  assert response['gid'] == gid
  assert response['response']['invited'] == []
  assert response['response']['joined'] == [iid]
  assert test_utils.get_game_model()
  assert test_utils.get_instance_model(iid)
Ejemplo n.º 5
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_join_instance_makes_new_instance():
    test_utils.clear_data_store()
    iid = 'new_iid'
    assert not test_utils.get_game_model()
    assert not test_utils.get_instance_model(iid)
    response = app.post('/joininstance', {
        'gid': gid,
        'iid': iid,
        'pid': firstpid
    }).json
    assert response['iid'] == iid
    assert response['gid'] == gid
    assert response['response']['invited'] == []
    assert response['response']['joined'] == [iid]
    assert test_utils.get_game_model()
    assert test_utils.get_instance_model(iid)
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_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_new_public_instance_false():
  test_iid = 'iid_prefix'
  response = app.post('/newinstance',
                      {'gid': gid, 'iid' : test_iid,
                       'pid' : firstpid, 'makepublic' : False}).json

  assert response['e'] is False
  iid = response['iid']
  assert iid.startswith(test_iid)
  assert iid in response['response']['joined']
  assert test_utils.get_instance_model(iid).public == False
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_new_public_instance_false():
    test_iid = 'iid_prefix'
    response = app.post('/newinstance', {
        'gid': gid,
        'iid': test_iid,
        'pid': firstpid,
        'makepublic': False
    }).json

    assert response['e'] is False
    iid = response['iid']
    assert iid.startswith(test_iid)
    assert iid in response['response']['joined']
    assert test_utils.get_instance_model(iid).public == False
def test_new_public_instance():
  test_iid = 'iid_prefix'
  response = app.post('/newinstance',
                      {'gid': gid, 'iid' : test_iid,
                       'pid' : firstpid, 'makepublic' : True}).json

  assert response['e'] is False
  iid = response['iid']
  assert iid.startswith(test_iid)
  assert iid in response['response']['joined']
  assert test_utils.get_instance_model(iid).public == True
  response = app.post('/getinstancelists',
                      {'gid': gid,
                       'iid' : '',
                       'pid' : firstpid}).json
  assert response['response']['invited'] == []
  assert iid in response['response']['joined']
  assert iid in response['response']['public']
def test_get_public_instances_with_player_counts():
    test_utils.clear_data_store()
    iid = test_utils.make_instance_with_players()
    test_utils.post_server_command(iid, "sys_set_public", [True])

    instance = test_utils.get_instance_model(iid)
    players = len(instance.players)

    response = test_utils.post_server_command("", "sys_get_public_instances", [])
    assert [iid, 3, 0] in response["contents"]

    test_utils.post_server_command(iid, "sys_set_max_players", [players + 1])
    response = test_utils.post_server_command(iid, "sys_get_public_instances", [])
    assert [iid, players, players + 1] in response["contents"]

    test_utils.post_server_command(iid, "sys_set_max_players", [0])
    response = test_utils.post_server_command(iid, "sys_get_public_instances", [])
    assert [iid, players, 0] in response["contents"]
def test_new_public_instance():
    test_iid = 'iid_prefix'
    response = app.post('/newinstance', {
        'gid': gid,
        'iid': test_iid,
        'pid': firstpid,
        'makepublic': True
    }).json

    assert response['e'] is False
    iid = response['iid']
    assert iid.startswith(test_iid)
    assert iid in response['response']['joined']
    assert test_utils.get_instance_model(iid).public == True
    response = app.post('/getinstancelists', {
        'gid': gid,
        'iid': '',
        'pid': firstpid
    }).json
    assert response['response']['invited'] == []
    assert iid in response['response']['joined']
    assert iid in response['response']['public']
def get_hands(iid):
    return card_game.get_hand_dictionary(test_utils.get_instance_model(iid))
def get_cards_left(iid):
  return card_game.cards_left(test_utils.get_instance_model(iid))
def get_deck(iid):
  return card_game.get_deck(test_utils.get_instance_model(iid))
Ejemplo n.º 18
0
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_deck(iid):
    return card_game.get_deck(test_utils.get_instance_model(iid))
def get_cards_left(iid):
    return card_game.cards_left(test_utils.get_instance_model(iid))
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_hands(iid):
  return card_game.get_hand_dictionary(test_utils.get_instance_model(iid))