From 2a9518c9e771c9eec67aa25ee0d1e2e8b8195892 Mon Sep 17 00:00:00 2001 From: neodarz Date: Sun, 19 Aug 2018 13:10:04 +0200 Subject: Use status code instead of simple message for testing --- src/lb_app/api.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/lb_app/api.py') diff --git a/src/lb_app/api.py b/src/lb_app/api.py index 9827828..9ac2bef 100644 --- a/src/lb_app/api.py +++ b/src/lb_app/api.py @@ -27,7 +27,11 @@ user_model = api.model('User', { class Users(Resource): def get(self): """ Get user list """ - return loads(dumps(user.all())) + users = loads(dumps(user.all())) + if not users: + return loads('{"msg": "No users"}'), 404 + print(users) + return loads(dumps(user.all())), 200 @api.route('/user/register') @@ -38,9 +42,7 @@ class Register(Resource): args = request.get_json(force=True) status = user.register(args.get('username')) - if status is None: - return loads('{"msg": "done"}'), 201 - return loads('{"msg": "'+status+'"}'), 200 + return loads('{"msg": "'+status['msg']+'"}'), status['code'] @api.route('/users/') @api.doc(params={'username': 'Jean'}) @@ -49,6 +51,4 @@ class Remove(Resource): """ Remove a user """ status = user.remove(username) - if status is None: - return loads('{"msg": "done"}'), 201 - return loads('{"msg": "'+status+'"}'), 200 + return loads('{"msg": "'+status['msg']+'"}'), status['code'] -- cgit v1.2.1