feat: cms softdelet bug fix
This commit is contained in:
@@ -68,6 +68,19 @@ class CmsDepartmentTest(CacheTestCase):
|
||||
self.assertFalse(Department.objects.filter(id=d.id).exists())
|
||||
self.assertTrue(Department.all_objects.get(id=d.id).is_deleted)
|
||||
|
||||
def test_recreate_soft_deleted_name_returns_400(self):
|
||||
"""软删后用相同名称重建:返回 400 CMS_DEPARTMENT_NAME_EXISTS(不产生重复行)。
|
||||
|
||||
按 all_objects 校验,避免与已停用科室同名而静默新建重复记录。
|
||||
"""
|
||||
d = Department.objects.create(name='康复科', category='临床')
|
||||
self.client.delete(d_detail(d.id))
|
||||
self.assertFalse(Department.objects.filter(name='康复科').exists())
|
||||
resp = self.client.post(CMS_DEPT_URL, {'name': '康复科', 'category': '临床'})
|
||||
self.assertEqual(resp.status_code, 400, resp.content)
|
||||
self.assertEqual(resp.json()['code'], 'CMS_DEPARTMENT_NAME_EXISTS')
|
||||
self.assertEqual(Department.all_objects.filter(name='康复科').count(), 1)
|
||||
|
||||
def test_import_and_export(self):
|
||||
f = make_xlsx(['科室名称', '分类'], [['心内科', '临床'], ['', 'x'], ['心内科', '临床']])
|
||||
resp = self.client.post('/api/cms/departments/import/', {'file': f}, format='multipart')
|
||||
|
||||
@@ -160,6 +160,20 @@ class CmsInstitutionCrudTest(CacheTestCase):
|
||||
resp = self.client.put(inst_detail_url(inst.id), {'code': 'CMS-PUT', 'name': 'Y'})
|
||||
self.assertEqual(resp.status_code, 405, resp.content)
|
||||
|
||||
def test_recreate_soft_deleted_code_returns_400(self):
|
||||
"""软删后用相同编码重建:返回 400 CMS_INSTITUTION_CODE_EXISTS(而非 500)。
|
||||
|
||||
编码唯一约束对软删行仍生效,须按 all_objects 校验,避免写库时撞约束抛 500。
|
||||
"""
|
||||
inst = ensure_institution(name='待停用', code='CMS-SOFT-DUP')
|
||||
self.client.delete(inst_detail_url(inst.id))
|
||||
self.assertFalse(Institution.objects.filter(code='CMS-SOFT-DUP').exists())
|
||||
resp = self.client.post(CMS_INST_URL, {'code': 'CMS-SOFT-DUP', 'name': '重建'})
|
||||
self.assertEqual(resp.status_code, 400, resp.content)
|
||||
self.assertEqual(resp.json()['code'], 'CMS_INSTITUTION_CODE_EXISTS')
|
||||
# 不应产生重复行(仍只有那条已软删的)
|
||||
self.assertEqual(Institution.all_objects.filter(code='CMS-SOFT-DUP').count(), 1)
|
||||
|
||||
|
||||
# ── Banner 上传(写临时静态目录,避免污染仓库)─────────────────────────────────
|
||||
|
||||
|
||||
@@ -127,6 +127,18 @@ class CmsUserCrudTest(CacheTestCase):
|
||||
obj = User.all_objects.get(id=u.id)
|
||||
self.assertTrue(obj.is_deleted) # 实际未物删
|
||||
|
||||
def test_recreate_soft_deleted_phone_returns_400(self):
|
||||
"""软删后用相同手机号重建:返回 400 CMS_USER_PHONE_EXISTS(不产生重复行)。"""
|
||||
u = create_test_user(phone='13922200061', role_type='student', institution=self.inst)
|
||||
self.client.delete(u_detail(u.id))
|
||||
self.assertFalse(User.objects.filter(phone='13922200061').exists())
|
||||
resp = self.client.post(CMS_USER_URL, {
|
||||
'phone': '13922200061', 'real_name': '重建', 'role_type': 'student',
|
||||
'institution': self.inst.id})
|
||||
self.assertEqual(resp.status_code, 400, resp.content)
|
||||
self.assertEqual(resp.json()['code'], 'CMS_USER_PHONE_EXISTS')
|
||||
self.assertEqual(User.all_objects.filter(phone='13922200061').count(), 1)
|
||||
|
||||
def test_reset_password(self):
|
||||
u = create_test_user(phone='13922200070', password='OldPass1', role_type='student')
|
||||
resp = self.client.post(f'/api/cms/users/{u.id}/reset-password/', {})
|
||||
|
||||
Reference in New Issue
Block a user