def post(self): try: json_data = request.get_json(force=True) data = authenticate(json_data["username"], json_data["password"]) if data: return get_response(data, 200) else: return get_response("Invalid usernamet/password", 401) except Exception as err: return get_response(err.args, 500)
def put(self): try: json_data = request.get_json(force=True) data = service.update(json_data) return get_response(data, 200) except Exception as err: response = get_error_response(err, 400) abort(response)
def get(self): try: current_user = get_jwt_identity() data = service.find_by_cpf(current_user) return get_response(data, 200) except Exception as err: response = get_error_response(err, 400) abort(response)
def get(self): try: parser = reqparse.RequestParser() parser.add_argument('cpf', type=str, help='CPF for get purchases') args = parser.parse_args() data = service.find_by_cpf(cpf=args["cpf"]) return get_response(data, 200) except Exception as err: response = get_error_response(err, 400) abort(response)
def delete(self): try: parser = reqparse.RequestParser() parser.add_argument('id_purchase', type=int, help='Value id for delete') args = parser.parse_args() data = service.delete(id_purchase=args["id_purchase"]) return get_response(data, 200) except Exception as err: response = get_error_response(err, 400) abort(response)
def test_get_response(self): data = get_response("body", 200) assert data.data != "" assert data.status_code == 200