コード例 #1
0
    def test_resolve_client(self, mock_sg_request_get, mock_tf_request_get, mock_sm_request_get):
        mock_sg_request_get.return_value.ok = True
        mock_sg_request_get.return_value.text = '{"id": "1","name": "Thiago Dias", "CPF":"59865377691", ' \
                                                '"birth": "1991-05-21"}'

        mock_tf_request_get.return_value.ok = True
        mock_tf_request_get.return_value.text = '{"id": "15","financial_movement": 68.6,' \
                                                '"last_query": "2017-11-22T21:13:28Z",' \
                                                '"last_buy":{"id": "15","value": 60.6,"credit_card":{"id": 21,' \
                                                '"number": "5547-7221-7804-6353","validity":"07/11/2019"}}}'

        mock_sm_request_get.return_value.ok = True
        mock_sm_request_get.return_value.text = '{"id": "15","pointing": 68.6,"last_query": "2017-11-22T21:13:28Z"}'

        query = Query()

        actual = query.resolve_client({'teste': 'teste'}, '10387595612')

        mock_sm_request_get.assert_called_once_with(resource='5af099f2310000610096c6ee',
                                                    params={'CPF': '10387595612'})

        mock_tf_request_get.assert_called_once_with(resource='5af0bb973100004a0096c74d',
                                                    params={'CPF': '10387595612'})

        mock_sg_request_get.assert_called_once_with(resource='5af076bc3100004d0096c66b',
                                                    params={'CPF': '10387595612'})

        self.assertIsNotNone(actual)
        self.assertIsInstance(actual._fields, tuple)
コード例 #2
0
def search():
    print "in search"
    name = request.form['cname']
    query = Query()
    courses = query.getCourseInfoByName(name)
    cid = courses[0][0]
    reviews = query.getReviewsByCid(cid)
    revList = [r[5] for r in reviews]
    if len(revList) == 0:
        revList.append("")
    # print revList
    combinedRev = ReviewSummarizer(revList).getSummarizedText()
    revTags = SentimentAnalyser(revList).senti_pretrained()
    # print revTags

    try:
        stat = roundVals(query.get_stats(cid)[0])
    except Exception:
        stat = (0,0,0)

    print reviews

    if request.method == 'POST':

        if len(reviews) != 0 and len(revTags) !=0:
            taggedRevs = tagRevs(reviews,revTags)
        else:
            taggedRevs = tagRevs(reviews,[])
        return render_template('course.html', course=courses[0], revs=reviews, stat=stat,
                               combRev=combinedRev, taggedRevs=taggedRevs, session = session)
    return "what"
コード例 #3
0
def authenticate(user, passw):
    print "add code to check user and pass"
    print user
    print passw
    q = Query()
    retL= q.check_auth(user,passw)
    print(retL)
    return retL
コード例 #4
0
def addUser(user, passw, name):
    print "adding new user"
    q = Query()
    retL = q.checkIfUserExist(user)
    if len(retL) == 0:
        q.ins_new_user(user, passw, name)
        return True
    return False
コード例 #5
0
    def test_resolve_score(self, mock_superman_request_get):
        mock_superman_request_get.return_value.ok = True
        mock_superman_request_get.return_value.text = '{"id": "15","pointing": 68.6,"last_query": "2017-11-22T21:13:28Z"}'

        query = Query()

        actual = query.resolve_score({'teste': 'teste'}, '10387595612')

        mock_superman_request_get.assert_called_once_with(resource='5af099f2310000610096c6ee',
                                                          params={'CPF': '10387595612'})

        self.assertIsNotNone(actual)
        self.assertIsInstance(actual._fields, tuple)
コード例 #6
0
    def test_resolve_event(self, mock_tf_request_get):
        mock_tf_request_get.return_value.ok = True
        mock_tf_request_get.return_value.text = '{"id": "15","financial_movement": 68.6,' \
                                                '"last_query": "2017-11-22T21:13:28Z",' \
                                                '"last_buy":{"id": "15","value": 60.6,"credit_card":{"id": 21,' \
                                                '"number": "5547-7221-7804-6353","validity":"07/11/2019"}}}'

        query = Query()

        actual = query.resolve_event({'teste': 'teste'}, '10387595612')

        mock_tf_request_get.assert_called_once_with(resource='5af0bb973100004a0096c74d',
                                                    params={'CPF': '10387595612'})

        self.assertIsNotNone(actual)
        self.assertIsInstance(actual._fields, tuple)
コード例 #7
0
def addCom():
    print "in add com"
    print request.method
    cid = request.args.get('courseId')
    print cid
    if request.method == 'POST':
        query = Query()
        cid2 = request.form['cid']

        query.ins_review_replWrd(session['email'], request.form['toughness'], request.form['work'], request.form['rating'],
                                 request.form['rev'], cid2,"f**k","fudge")

        reviews = query.getReviewsByCid(cid2)
        course = query.getCourseInfoByCid(cid2)
        stat = roundVals(query.get_stats(cid2)[0])

        # reviews = query.getReviewsByCid(cid2)
        revList = [r[5] for r in reviews]
        combinedRev = ReviewSummarizer(revList).getSummarizedText()
        revTags = SentimentAnalyser(revList).senti_pretrained()
        taggedRevs = tagRevs(reviews, revTags)
        return render_template('course.html', course=course[0], revs=reviews, stat=stat,
                               combRev=combinedRev, session = session, taggedRevs=taggedRevs)

    return render_template('comment.html', type='com', cid=cid, session = session)
コード例 #8
0
def delete():
    print "in delete"
    postId = request.args.get('postId')
    print postId
    query = Query()
    query.deleteReview(postId)
    cid = request.args.get('cid')
    reviews = query.getReviewsByCid(cid)
    courses = query.getCourseInfoByCid(cid)
    stat = roundVals(query.get_stats(cid)[0])

    revList = [r[5] for r in reviews]
    combinedRev = ReviewSummarizer(revList).getSummarizedText()
    revTags = SentimentAnalyser(revList).senti_pretrained()
    taggedRevs = tagRevs(reviews, revTags)

    return render_template('course.html', course=courses[0], revs=reviews, stat=stat,
                           session = session, combRev=combinedRev, taggedRevs=taggedRevs)
コード例 #9
0
def update():
    print "in update"
    query = Query()


    cid = request.args.get('cid')
    rev = []

    if request.method == 'GET':
        postId = request.args.get('postId')
        rev = query.getReviewById(postId)
        print postId
        print rev

    if request.method == 'POST':
        cid2 = request.form['cid']
        postId2 = request.form['revid']


        query.updateRev(postId2, request.form['rev'], request.form['toughness'],
                                 request.form['work'],
                                 request.form['rating'])

        reviews = query.getReviewsByCid(cid2)
        course = query.getCourseInfoByCid(cid2)
        stat = roundVals(query.get_stats(cid2)[0])

        revList = [r[5] for r in reviews]
        combinedRev = ReviewSummarizer(revList).getSummarizedText()
        revTags = SentimentAnalyser(revList).senti_pretrained()
        taggedRevs = tagRevs(reviews, revTags)

        return render_template('course.html', course=course[0], revs=reviews, stat=stat,
                               session = session, combRev=combinedRev, taggedRevs=taggedRevs)

    if len(rev) <= 0:
        rev = [""]
    return render_template('comment.html', type='up', cid=cid, rev=rev[0], revid=postId, session = session)