I wrote a POST endpoint in Python Flask to get the response OK as a string value (without quotes). However, when the API is tested the API responds with "OK" (with quotes). The results in Ipkiss Tester is the following:
*❌ Reset state before starting tests
POST /reset
Expected: 200 OK
Got: 200 "OK"
Any suggestions to fix this issue?.
Thanks.
Below the code:
from flask import Flask, request, jsonify
from flask_restful import abort, Api, reqparse, Resource
from flask_api import status
class AccountModel:
def __init__(self, accnum):
# We will automatically generate the new id
self.id = accnum
self.balance = 0
class AccountManager():
def __init__(self):
self.accounts = {}
def delete_accounts(self):
if not bool(self.accounts):
del self.accounts
self.accounts = {}
account_manager = AccountManager()
class ResetAccount(Resource):
def post(self):
if str(request.url_rule) =="/reset":
account_manager.delete_accounts()
return "OK", status.HTTP_200_OK
else:
abort(
status.HTTP_404_NOT_FOUND,
message=str(status.HTTP_404_NOT_FOUND) + " " + "0".format())
app = Flask(__name__)
service = Api(app)
service.add_resource(ResetAccount, '/reset', endpoint='reset_endpoint')
if __name__ == '__main__':
app.run(debug=True)