feat: update medical training case and auth modules
This commit is contained in:
+16
-19
@@ -16,6 +16,7 @@ from .conftest import (
|
||||
USER_SEND_CODE_URL, USER_REGISTER_URL, USER_LOGIN_URL,
|
||||
USER_LOGIN_CODE_URL, USER_CHANGE_PWD_URL, USER_RESET_PWD_URL, USER_ME_URL,
|
||||
USER_LIST_URL, user_detail_url,
|
||||
DEFAULT_INSTITUTION_CODE, DEFAULT_INSTITUTION_NAME,
|
||||
inject_sms_code, create_test_user, get_auth_client, get_tokens,
|
||||
create_teacher_student_relation,
|
||||
)
|
||||
@@ -38,40 +39,32 @@ class UserAuthHappyPathTest(CacheTestCase):
|
||||
# ── HP-1: 注册 → 密码登录 → /me ──────────────────────────────────────
|
||||
|
||||
def test_flow_register_login_me(self):
|
||||
"""HP-1: U1 send-code(register) → U2 register → U3 login → GET /me"""
|
||||
"""HP-1: U2 register(管理员代注册,默认密码) → U3 login(默认密码) → GET /me"""
|
||||
phone = '13900000001'
|
||||
password = 'Abc12345'
|
||||
default_password = f'Pass{phone}'
|
||||
real_name = '张三'
|
||||
|
||||
with ExitStack() as stack:
|
||||
_bypass_all_auth_throttles(stack)
|
||||
|
||||
# U1: send-code (register)
|
||||
resp = self.client.post(USER_SEND_CODE_URL, {
|
||||
'phone': phone, 'scene': 'register',
|
||||
})
|
||||
self.assertEqual(resp.status_code, 200, resp.content)
|
||||
|
||||
# 从 cache 读验证码
|
||||
code = cache.get(f'sms:register:{phone}')
|
||||
self.assertIsNotNone(code, '验证码未写入缓存')
|
||||
|
||||
# U2: register
|
||||
# U2: register(管理员代注册,无需验证码,密码自动为 Pass+手机号)
|
||||
resp = self.client.post(USER_REGISTER_URL, {
|
||||
'phone': phone,
|
||||
'code': str(code),
|
||||
'password': password,
|
||||
'real_name': real_name,
|
||||
'institution_code': DEFAULT_INSTITUTION_CODE,
|
||||
'institution_name': DEFAULT_INSTITUTION_NAME,
|
||||
})
|
||||
self.assertEqual(resp.status_code, 201, resp.content)
|
||||
data = resp.json()
|
||||
self.assertIn('tokens', data)
|
||||
self.assertEqual(data['user']['phone'], phone)
|
||||
self.assertEqual(data['user']['real_name'], real_name)
|
||||
self.assertEqual(data['user']['institution_name'], DEFAULT_INSTITUTION_NAME)
|
||||
self.assertEqual(data['user']['institution_code'], DEFAULT_INSTITUTION_CODE)
|
||||
|
||||
# U3: login (password) — 限流 bypass 已退出,login 无限流
|
||||
# U3: login (默认密码 Pass+手机号)
|
||||
resp = self.client.post(USER_LOGIN_URL, {
|
||||
'phone': phone, 'password': password,
|
||||
'phone': phone, 'password': default_password,
|
||||
})
|
||||
self.assertEqual(resp.status_code, 200, resp.content)
|
||||
tokens = resp.json()['tokens']
|
||||
@@ -102,14 +95,18 @@ class UserAuthHappyPathTest(CacheTestCase):
|
||||
code = cache.get(f'sms:login:{phone}')
|
||||
self.assertIsNotNone(code)
|
||||
|
||||
# U4: login-code
|
||||
# U4: login-code(需要 institution 字段)
|
||||
resp = self.client.post(USER_LOGIN_CODE_URL, {
|
||||
'phone': phone, 'code': str(code),
|
||||
'phone': phone,
|
||||
'code': str(code),
|
||||
'institution_name': DEFAULT_INSTITUTION_NAME,
|
||||
'institution_code': DEFAULT_INSTITUTION_CODE,
|
||||
})
|
||||
self.assertEqual(resp.status_code, 200, resp.content)
|
||||
tokens = resp.json()['tokens']
|
||||
self.assertIn('access', tokens)
|
||||
self.assertIn('refresh', tokens)
|
||||
self.assertFalse(resp.json()['is_new_user'])
|
||||
|
||||
# GET /me
|
||||
self.client.credentials(HTTP_AUTHORIZATION=f'Bearer {tokens["access"]}')
|
||||
|
||||
Reference in New Issue
Block a user