我有这个休息功能:
class digitalNumbers(Resource):
def get(self, first_number, second_number):
return {'data': directSum.sumTwoNumberss(first_number,second_number)}
api.add_resource(digitalNumbers, '/sumtwonumbers/<first_number>/<second_number>')
此函数以API方式返回浏览器上查询的两个数字的和,例如:localhost:5000/80/80
原始数据中的结果:{"data": 160}
现在,我想使用相同的总和来对此进行测试,如下所示:
with app.test_request_context('/sumtwonumbers/<first_number>/<second_number>'):
assert flask.request.path == '/sumtwonumbers/80/80'
assert flask.request.args['first_number']['second_number'] == '{"data": 160}'
但是它返回:
Traceback (most recent call last):
File "app.py", line 16, in <module>
assert flask.request.path == '/sumtwonumbers/80/80'
AssertionError
因此,url
路径工作正常,但是在测试中,我仍在尝试找出此错误的原因,我认为url
响应中有些内容,也许我应该指出响应是json而不仅仅是生成的数字吗?