def test_OBJECT(self): dictionary = {"Producator":"Mercedes","Caroserie":"Sedan","Model":"C180","AnProductie":1999,"VolumMotor":1800, "Pret":8000,"Carburant":"Benzina","Link":"http://www.google.ro"} object = CarObject.carObject(dictionary) self.assertItemsEqual(dictionary.values(),[object._Producator,object._Caroserie, object._Model,object._AnProductie,object._VolumMotor ,object._Pret,object._Carburant,object._Link])
def test_client(self): request = 'GET /AutomobileVanzare?Producator=Mercedes&Model=C180&Caroserie=hatchback' db = DatabaseManager('localhost') # Get SQL Query from REST sqlQuery = DatabaseManager.getSQLqueryFromREST(restQuery) # Get the result from SQL Server carObjects = db.SelectFromDatabase(sqlQuery) #the object which i expect to receive is dictionary = {"Producator":"Mercedes","Caroserie":"Sedan","Model":"C180","AnProductie":1999,"VolumMotor":1800, "Pret":8000,"Carburant":"Benzina","Link":"http://www.google.ro"} object = CarObject.carObject(dictionary) self.assertEqual(dictionary.values(),carObjects[0].values())
def SelectFromDatabase(self,query): logging.warning("DatabaseManager - Querrying database with "+query) try: #execute the db query self.cursor.execute(query) #get the answers into a list ListOfCars = self.cursor.fetchall() except: logging.error('DatabaseManager - Error Executing SQL query '+query) #retunrn the list of cars #answer is a list of car objects answer = [] for carArray in ListOfCars: dictionary= {"Caroserie":carArray[1],"Model":carArray[3],"Producator":carArray[2], "AnProductie":carArray[4],"VolumMotor":carArray[5], "Pret":carArray[6],"Carburant":carArray[7], "Link":carArray[8]} answer.append(CarObject.carObject(dictionary)) return answer