def getPlayer(name): conn = config.getConnection() cur = conn.cursor() cur.execute("SELECT * FROM players where player_name = %s;", (name, )) name,rating,wins,loses = cur.fetchone() cur.close() conn.close() return LeagueManager.Player(name=name, rating=rating, wins=wins, loses=loses)
def setUp(self): self.app = app.app.test_client() db = getConnection() newUser = { "username": "******", "levels": ["SUPERUSER"], "passwordhashed": hashPass('test') } self.entry = createMongoDocument(db.users, newUser)
def __init__(self, lotName, totalSpots): ''' When initializing an instance of ParkingLot, connect to MongoDB ''' self.lotName = lotName.replace(' ', '').lower() self.parkingDataCollectionName = self.lotName self.totalSpots = totalSpots # Connect to mongodb using connection string self.connection = pymongo.MongoClient(getConnection()) # Create/Search for a database called test self.database = self.connection['test'] self.collection = self.database[self.lotName]
def updateRating(name,rating): conn = config.getConnection() cur = conn.cursor() cur.execute("update players set rating=%s where player_name == %s;", (rating,name)) cur.close() conn.close()
def addLoss(name): conn = config.getConnection() cur = conn.cursor() cur.execute("update players set loses=loses+1 where player_name == %s;", (name,)) cur.close() conn.close()
def tearDown(self): db = getConnection() deleteMongoDocument(db.users, self.entry['id'])