Exemple #1
0
def following(id):
    form = InterestIdForm(url={'id': id})
    if not form.validate():
        return json({
            'message': 'Validation Failed',
            'errors': form.errors
        }, 422)

    user_id = app.auth.user.id

    if request.method == 'GET':
        if Interest.following(form.id, user_id):
            return json(code=204)
        else:
            return json(code=404)

    elif request.method == 'POST':
        if Interest.follow(form.id, user_id):
            return json(code=201)
        else:
            return json({'message': 'Interest with given ID not found'}, 400)

    elif request.method == 'DELETE':
        if Interest.unfollow(form.id, user_id):
            return json(code=204)
        else:
            return json({'message': 'Interest with given ID not found'}, 400)
Exemple #2
0
def following(id):
    form = InterestIdForm(url={'id': id})
    if not form.validate():
        return json({'message': 'Validation Failed', 'errors': form.errors}, 422)

    user_id = app.auth.user.id

    if request.method == 'GET':
        if Interest.following(form.id, user_id):
            return json(code=204)
        else:
            return json(code=404)

    elif request.method == 'POST':
        if Interest.follow(form.id, user_id):
            return json(code=201)
        else:
            return json({'message': 'Interest with given ID not found'}, 400)

    elif request.method == 'DELETE':
        if Interest.unfollow(form.id, user_id):
            return json(code=204)
        else:
            return json({'message': 'Interest with given ID not found'}, 400)
 def testFollowing(self):
     self.assertTrue(Interest.following(1, 6))