我正在为一个API编写一些单元测试,试图在单元测试中设置一个会话来模拟已经登录的用户。 由于某些原因,它看起来不像会话get通过客户端.get. 有人知道我做错了什么吗?你知道吗
client = app.test_client()
with client.session_transaction() as sess:
sess['username'] = 'bob@example.com'
response = client.get('/users/')
# Looks good
# <SecureCookieSession {'username': 'bob@example.com'}>
print sess
# Nothing in the cookie...
print response.data
# self.assertEquals(
# json.loads(response.data),
# json.loads('{"users": "all"}'))
您需要将
client.get()
移出with
上下文管理器的:会话仅在
with
块末尾“提交”。你知道吗相关问题 更多 >
编程相关推荐