def get_user(user_id=None):
    try:
        users = get_model_users(user_id=user_id)
    except DataError:
        return jsonify(result="error", message="Invalid user id"), 400
    except NoResultFound:
        return jsonify(result="error", message="User not found"), 404
    result = users_schema.dump(users) if isinstance(users, list) else user_schema.dump(users)
    return jsonify(data=result.data)
Exemple #2
0
def get_user(user_id=None):
    try:
        users = get_model_users(user_id=user_id)
    except DataError:
        return jsonify(result="error", message="Invalid user id"), 400
    except NoResultFound:
        return jsonify(result="error", message="User not found"), 404
    result = users_schema.dump(users) if isinstance(
        users, list) else user_schema.dump(users)
    return jsonify(data=result.data)
 def test_get_users(self):
     response = self.client.get(
         url_for('api.user_list'), headers=self.user1_token_auth_headers)
     self.assertEqual(response.status_code, 200)
     data = json.loads(response.data)
     data1 = users_schema.dump(User.query.all())
     self.assertEqual(data, data1)
     self.assertEqual(len(data), 2)
     self.assertIn(user_schema.dump(self.user1), data)
     self.assertIn(user_schema.dump(self.user2), data)
Exemple #4
0
 def get(self):
     all_users = User.query.all()
     return users_schema.dump(all_users)
Exemple #5
0
def get_users():
    users = User.query.all()
    return jsonify(users_schema.dump(users).data)
Exemple #6
0
def users_get():
    users = User.query.all()
    result = users_schema.dump(users)
    return jsonify({'users': result.data})
Exemple #7
0
 def get(self):
     users = User.query.all()
     return { 'users': users_schema.dump(users).data }
Exemple #8
0
    def index(self):
        users = User.all()

        return jsonify({"users": users_schema.dump(users)})