feat: update medical training case and auth modules

This commit is contained in:
2026-06-03 17:34:47 +08:00
parent b4bb38b7be
commit fd0b3e1982
45 changed files with 1459 additions and 812 deletions
+9 -12
View File
@@ -12,6 +12,7 @@ from .conftest import (
USER_RESET_PWD_URL, USER_CHANGE_PWD_URL, USER_ME_URL,
USER_LOGOUT_URL, USER_REFRESH_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,
)
@@ -59,38 +60,34 @@ class UserNegativeTest(CacheTestCase):
with patch.object(RegisterIpThrottle, 'allow_request', return_value=True):
resp = self.client.post(USER_REGISTER_URL, {
'phone': '123',
'code': '123456',
'password': 'Abc12345',
'real_name': '测试',
'institution_code': DEFAULT_INSTITUTION_CODE,
'institution_name': DEFAULT_INSTITUTION_NAME,
})
self.assertEqual(resp.status_code, 400, resp.content)
self.assertEqual(resp.json()['code'], 'SMS_INVALID_PHONE')
def test_register_weak_password_400(self):
"""N5: 弱密码 → 400 AUTH_PASSWORD_WEAK"""
def test_register_missing_institution_400(self):
"""N5: 注册缺少机构编码 → 400 USER_INSTITUTION_CODE_REQUIRED"""
phone = '13800001002'
inject_sms_code(phone, 'register')
with patch.object(RegisterIpThrottle, 'allow_request', return_value=True):
resp = self.client.post(USER_REGISTER_URL, {
'phone': phone,
'code': '123456',
'password': '123',
'real_name': '测试弱密码',
'real_name': '测试缺机构',
})
self.assertEqual(resp.status_code, 400, resp.content)
self.assertEqual(resp.json()['code'], 'AUTH_PASSWORD_WEAK')
self.assertEqual(resp.json()['code'], 'USER_INSTITUTION_CODE_REQUIRED')
def test_register_duplicate_phone_400(self):
"""N6: 已注册手机号再注册 → 400 AUTH_PHONE_REGISTERED"""
phone = '13800001003'
create_test_user(phone=phone)
inject_sms_code(phone, 'register')
with patch.object(RegisterIpThrottle, 'allow_request', return_value=True):
resp = self.client.post(USER_REGISTER_URL, {
'phone': phone,
'code': '123456',
'password': 'Abc12345',
'real_name': '重复注册',
'institution_code': DEFAULT_INSTITUTION_CODE,
'institution_name': DEFAULT_INSTITUTION_NAME,
})
self.assertEqual(resp.status_code, 400, resp.content)
self.assertEqual(resp.json()['code'], 'AUTH_PHONE_REGISTERED')