Esempio n. 1
0
 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)
Esempio n. 2
0
 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')
Esempio n. 3
0
    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)
Esempio n. 4
0
 def test_InsertUsersRequestDBDown(self):
     fzapi.db.drop_all()
     ml = FizzBuzzML(int1=1, int2=2, mlimit=3, str1='un', str2='deux')
     fzRq = FizzBuzzRQ()
     res = fzRq.insertUsersRequest(ml)
     self.assertTrue('sqlite3.OperationalError' in res)
     fzapi.db.session.rollback()
Esempio n. 5
0
    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