def test_InsertUsersRequestALot(self): ml = FizzBuzzML(int1=1, int2=2, mlimit=3, str1='un', str2='deux') fzRq = FizzBuzzRQ() for i in range(10): fzRq.insertUsersRequest(ml) insList = FizzBuzzML.query.all() self.assertEqual(len(insList), 10)
def test_InsertUsersRequestStr1(self): ml = FizzBuzzML(int1=1, int2=2, mlimit=3, str1='un', str2='deux') fzRq = FizzBuzzRQ() fzRq.insertUsersRequest(ml) insList = FizzBuzzML.query.all() self.assertEqual(insList[0].int1, 1) self.assertEqual(insList[0].int2, 2) self.assertEqual(insList[0].mlimit, 3) self.assertEqual(insList[0].str1, 'un') self.assertEqual(insList[0].str2, 'deux')
def test_GetTopUsersRequestsNum(self): self.test_InsertUsersRequestALot() ml = FizzBuzzML(int1=2, int2=4, mlimit=6, str1='trois', str2='six') fzRq = FizzBuzzRQ() for i in range(11): fzRq.insertUsersRequest(ml) insList = FizzBuzzML.query.all() self.assertEqual(len(insList), 21) num, rq = fzRq.getTopUsersRequests() self.assertEqual(num, 11)
def get(self): """ Get the most used query Returns the most queryed fizzbuzz request """ fzRq = FizzBuzzRQ() numOfRequest,mostRequested = fzRq.getTopUsersRequests() if mostRequested == None or numOfRequest == None: return {'count' : 0, 'request' : {}} else: return {'count' : numOfRequest, 'request' : mostRequested.serialize()}
def get(self): """ Computes fizzbuzz algorithm Returns the list of fizzbuzz processed """ fzquery = FizzBuzzML(request.args.get('int1', None, int), request.args.get('int2', None, int), request.args.get('limit', None, int), request.args.get('str1', None, str), request.args.get('str2', None, str)) fzlogic = FizzBuzzLC() success, result, errStr = fzlogic.compute(fzquery) if success: #insert into db fzRq = FizzBuzzRQ() fzRq.insertUsersRequest(fzquery) return {'success': success, 'result': result}, 200 else: return {'success': success, 'error': errStr}, 400
def test_GetTopUsersRequestsDBDown(self): fzapi.db.drop_all() fzRq = FizzBuzzRQ() num, rq = fzRq.getTopUsersRequests() self.assertEqual(num, None) self.assertEqual(rq, None)
def test_GetTopUsersRequestsEmpty(self): fzRq = FizzBuzzRQ() num, rq = fzRq.getTopUsersRequests() self.assertEqual(num, None)