def create_player(self, name=None, password=None, workfactor=None, location=None, admin=False, sadmin=False, owner=False): """ Creates a new instance of a Player. Keyword arguments: name -- The name of the new Player instance to be used. password -- The password that is to be used for the Player. workfactor -- The work factor # to be used when hasing the Player's password. location -- The ID or instance of Room that the new Player is to be created at. admin -- A boolean representing whether or not this new Player is an administrator. sadmin -- A boolean representing whether or not this new Player is a super administrator. owner -- A boolean representing whether or not this new Player is an owner. """ if (name is None or password is None or workfactor is None or location is None): raise exception.WorldArgumentError('All of the arguments to create_player are mandatory! (or None was passed in)') try: if (type(location) is int): location = self.find_room(id=location) player_inventory = self.create_room('%s\'s Inventory' % (name)) player = Player(name, password, workfactor, location.id, 0, admin=admin, sadmin=sadmin, owner=owner) player.inventory_id = player_inventory.id connection = self.connect() self.session.add(player) location.players.append(player) self.session.add(location) self.session.add(player_inventory) self.session.commit() self.session.refresh(player) self.session.refresh(player_inventory) player.location = location player.inventory = player_inventory player.session = self.session player.engine = self.engine player.location.session = self.session player.location.engine = self.engine player.inventory = player_inventory player_inventory.session = self.session player_inventory.engine = self.engine connection.close() return player except exception.DatabaseError: self.session.rollback() self.database_status.send(sender=self, status=False)
def test_going_thru_red_light(self): player_1 = Player('Player 1') player_1.location = 3 player_1.in_motion = True self.assertTrue(player_1.in_motion)