from flask import Flask, request
from flask_restful import Api, Resource
app = Flask(__name__)
api = Api(app)
class Echo(Resource):
def get(self, me):
return { "res": f"Text: {me}" }
def post(self, me):
return { "Answer": f"You said: {me}" }
api.add_resource(Echo, '/echo/<me>')
import api
def test_echo():
web = api.app.test_client()
rv = web.get('/echo/hello')
assert rv.status == '200 OK'
assert rv.headers['Content-Type'] == 'application/json'
assert rv.json == {'res': 'Text: hello'}
rv = web.post('/echo/ciao')
assert rv.status == '200 OK'
assert rv.headers['Content-Type'] == 'application/json'
assert rv.json == {'Answer': 'You said: ciao'}