コード例 #1
0
 def test_serializeML(self):
     ml = FizzBuzzML(int1=1, int2=2, mlimit=4, str1='un', str2='deux')
     jsonToCompareTo = {
         'int1': 1,
         'int2': 2,
         'limit': 4,
         'str1': 'un',
         'str2': 'deux'
     }
     jsonSerialized = ml.serialize()
     self.assertEqual(jsonToCompareTo, jsonSerialized)
コード例 #2
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()
コード例 #3
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)
コード例 #4
0
 def test_constructML(self):
     ml = FizzBuzzML(int1=1, int2=2, mlimit=3, str1='un', str2='deux')
     self.assertEqual(ml.int1, 1)
     self.assertEqual(ml.int2, 2)
     self.assertEqual(ml.mlimit, 3)
     self.assertEqual(ml.str1, 'un')
     self.assertEqual(ml.str2, 'deux')
コード例 #5
0
 def test_ctorMLWostr2(self):
     raised = None
     try:
         ml = FizzBuzzML(int1=1, int2=2, mlimit=3, str1='un')
     except Exception as e:
         raised = e
     self.assertIsInstance(raised, TypeError)
コード例 #6
0
 def test_processFizzbuzzOk(self):
     ml = FizzBuzzML(int1=3, int2=5, mlimit=15, str1='m3', str2='m5')
     lc = FizzBuzzLC()
     compareTo = [
         1, 2, 'm3', 4, 'm5', 'm3', 7, 8, 'm3', 'm5', 11, 'm3', 13, 14,
         'm3m5'
     ]
     self.assertSequenceEqual(lc.processFizzbuzz(ml), compareTo)
コード例 #7
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')
コード例 #8
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)
コード例 #9
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
コード例 #10
0
ファイル: fizzBuzzRQ.py プロジェクト: phenixzr/FizzbuzzApi
    def insertUsersRequest(self, request):
        """ Inserts a new fizzbuzz query

        Inserts a new row in fizzbuzz table, all required fields must be checked before

        Args:
            request: a FizzbuzzML model object that holds all user defined fields
        """

        fzquerydb = FizzBuzzML(int1=request.int1
            , int2=request.int2
            , mlimit=request.mlimit
            , str1=request.str1
            , str2=request.str2)
        
        try:
            db.session.add(fzquerydb)
            db.session.commit()
        except Exception as e:
            logging.error('Cannot insert into database {0}'.format(str(e)))
            return str(e) # only used in test
コード例 #11
0
ファイル: fizzBuzzRQ.py プロジェクト: phenixzr/FizzbuzzApi
    def getTopUsersRequests(self):
        """ Fetches the most frequent query done by users

        check the fizzbuzz table to get the most frequent row

        Returns:
            A tuple containing, first :how many time the most queryed fizzbuzz had, 
            second : what the most queryed fizzbuzz is
        """

        try:
            cnt = func.count('*')
            result = db.session.query(cnt, FizzBuzzML.int1, FizzBuzzML.int2, FizzBuzzML.mlimit, FizzBuzzML.str1, FizzBuzzML.str2).\
                                    group_by(FizzBuzzML.int1, FizzBuzzML.int2, FizzBuzzML.mlimit, FizzBuzzML.str1, FizzBuzzML.str2).\
                                    order_by(cnt.desc()).\
                                    limit(1).all()
            
            if len(result) == 1 and len(result[0]) == 6:
                return result[0][0], FizzBuzzML(result[0][1], result[0][2], result[0][3], result[0][4], result[0][5])
            else:
                return None, None
        except Exception as e:
            logging.error('Cannot read from database {0}'.format(str(e)))
            return None, None
コード例 #12
0
 def test_isValidDataKoMlimitLessInt2(self):
     ml = FizzBuzzML(int1=2, int2=4, mlimit=3, str1='m3', str2='m5')
     lc = FizzBuzzLC()
     res, errStr = lc.isValidData(ml)
     self.assertFalse(res)
     self.assertIsNotNone(errStr)
コード例 #13
0
 def test_isValidDataKoInt2EquInt1(self):
     ml = FizzBuzzML(int1=1, int2=1, mlimit=1, str1='m3', str2='m5')
     lc = FizzBuzzLC()
     res, errStr = lc.isValidData(ml)
     self.assertFalse(res)
     self.assertIsNotNone(errStr)
コード例 #14
0
 def test_isValidDataOk(self):
     ml = FizzBuzzML(int1=1, int2=2, mlimit=3, str1='m3', str2='m5')
     lc = FizzBuzzLC()
     self.assertTrue(lc.isValidData(ml))
コード例 #15
0
 def test_isValidDataKoStr2None(self):
     ml = FizzBuzzML(int1=2, int2=3, mlimit=10, str1='m3', str2=None)
     lc = FizzBuzzLC()
     res, errStr = lc.isValidData(ml)
     self.assertFalse(res)
     self.assertIsNotNone(errStr)