测试多个用户的身份验证过程需要多个会话/客户端。我尝试使用以下代码测试app.test_client(...)
,它可以测试单用户的登录/注销功能,但是当多个用户在自己的会话中登录/注销时,我无法确定它是否仍然有效。
setUp, tearDown, and other branche tests...
def test_login(self):
"""Check if server can handle login successfully.
"""
with self.client as c:
login_res = c.post(API.login, data=self.valid_user)
assert_equals(login_res.get_json(), {
'data': {'userName': 'user'}, 'status': 200,
'msg': 'login success.'
})
def test_logout(self):
"""Check if server can handle user logout.
"""
with self.client as c:
# login user first
c.post(API.login, data=self.valid_user)
# then log out.
res = c.get(API.logout)
assert_equals(res.get_json(), {
'data': {'userName': 'user'}, 'status': 200,
'msg': 'logout success.'
})