def test_instance_creation():
    iid = 'instance_create_iid'
    player = '*****@*****.**'
    game = Game.get_or_insert(key_name=gid)
    instance = GameInstance(parent=game,
                            key_name=iid,
                            players=[player],
                            leader=player)
    assert not instance.full
    assert not instance.public
    assert instance.max_players == 0
def test_instance_creation():
  iid = 'instance_create_iid'
  player = '*****@*****.**'
  game = Game.get_or_insert(key_name = gid)
  instance = GameInstance(parent = game,
                          key_name = iid,
                          players = [player],
                          leader = player)
  assert not instance.full
  assert not instance.public
  assert instance.max_players == 0
def get_game_model(gameid=gid):
    """ Return a Game model for the given game id.

  Args:
    gameid: The game id of the Game.

  Returns:
    The database model for the specified id or None if no such model
    exists.
  """
    return Game.get(Key.from_path('Game', gameid))
def get_game_model(gameid = gid):
  """ Return a Game model for the given game id.

  Args:
    gameid: The game id of the Game.

  Returns:
    The database model for the specified id or None if no such model
    exists.
  """
  return Game.get(Key.from_path('Game', gameid))
def test_instance_public():
  iid = 'instance_public_iid'
  player = '*****@*****.**'
  game = Game.get_or_insert(key_name = 'public_game')
  instance = GameInstance(parent = game,
                          key_name = iid,
                          players = [player],
                          leader = player)
  instance.put()
  assert instance not in game.get_public_instances_query().fetch(1000)
  instance.public = True
  instance.put()
  public_game = game.get_public_instances_query().fetch(1)[0]
  assert public_game.to_dictionary() == instance.to_dictionary()
  instance.public = False
  instance.put()
  assert len(game.get_public_instances_query().fetch(1000)) == 0
def test_instance_public():
    iid = 'instance_public_iid'
    player = '*****@*****.**'
    game = Game.get_or_insert(key_name='public_game')
    instance = GameInstance(parent=game,
                            key_name=iid,
                            players=[player],
                            leader=player)
    instance.put()
    assert instance not in game.get_public_instances_query().fetch(1000)
    instance.public = True
    instance.put()
    public_game = game.get_public_instances_query().fetch(1)[0]
    assert public_game.to_dictionary() == instance.to_dictionary()
    instance.public = False
    instance.put()
    assert len(game.get_public_instances_query().fetch(1000)) == 0
def test_delete_messages():
  iid = 'instance_messages_iid'
  player = '*****@*****.**'
  game = Game.get_or_insert(key_name = gid)
  instance = GameInstance.get_or_insert(parent = game,
                                        key_name = iid,
                                        players = [player],
                                        leader = player)
  for i in xrange(50):
    message = Message(parent = instance,
                      sender = player,
                      msg_type = 'blah',
                      recipient = player,
                      content = '%d' % i)
    message.put()
  messages = Message.all(keys_only = True).ancestor(instance.key()).fetch(1000)
  assert len(messages) == 50

  instance.delete_messages('blah')
  messages = Message.all(keys_only = True).ancestor(instance.key()).fetch(1000)
  assert len(messages) == 0
def test_delete_messages():
    iid = 'instance_messages_iid'
    player = '*****@*****.**'
    game = Game.get_or_insert(key_name=gid)
    instance = GameInstance.get_or_insert(parent=game,
                                          key_name=iid,
                                          players=[player],
                                          leader=player)
    for i in xrange(50):
        message = Message(parent=instance,
                          sender=player,
                          msg_type='blah',
                          recipient=player,
                          content='%d' % i)
        message.put()
    messages = Message.all(keys_only=True).ancestor(instance.key()).fetch(1000)
    assert len(messages) == 50

    instance.delete_messages('blah')
    messages = Message.all(keys_only=True).ancestor(instance.key()).fetch(1000)
    assert len(messages) == 0
def test_instance_full():
  iid = 'instance_full_iid'
  player = '*****@*****.**'
  game = Game.get_or_insert(key_name = gid)
  instance = GameInstance(parent = game,
                          key_name = iid,
                          players = [player],
                          leader = player)
  assert not instance.full
  instance.max_players = 1
  assert not instance.full
  instance.put()
  assert instance.full
  instance.max_players = 2
  instance.put()
  assert not instance.full
  instance.players = [player, '*****@*****.**']
  instance.put()
  assert instance.full
  instance.max_players = 0
  instance.put()
  assert not instance.full
def test_instance_full():
    iid = 'instance_full_iid'
    player = '*****@*****.**'
    game = Game.get_or_insert(key_name=gid)
    instance = GameInstance(parent=game,
                            key_name=iid,
                            players=[player],
                            leader=player)
    assert not instance.full
    instance.max_players = 1
    assert not instance.full
    instance.put()
    assert instance.full
    instance.max_players = 2
    instance.put()
    assert not instance.full
    instance.players = [player, '*****@*****.**']
    instance.put()
    assert instance.full
    instance.max_players = 0
    instance.put()
    assert not instance.full
def test_game_creation():
  game = Game.get_or_insert(key_name = gid)
  assert game.instance_count == 0
  assert len(game.get_public_instances_query().fetch(1)) == 0
def test_game_creation():
    game = Game.get_or_insert(key_name=gid)
    assert game.instance_count == 0
    assert len(game.get_public_instances_query().fetch(1)) == 0