feat: update personal stats and cms change reuqest method
This commit is contained in:
@@ -31,6 +31,14 @@ def inst_detail_url(pk):
|
||||
return f'/api/cms/institutions/{pk}/'
|
||||
|
||||
|
||||
def inst_update_url(pk):
|
||||
return f'/api/cms/institutions/{pk}/update/' # 编辑:POST(原 PATCH /{id}/)
|
||||
|
||||
|
||||
def inst_disable_url(pk):
|
||||
return f'/api/cms/institutions/{pk}/disable/' # 停用:POST(原 DELETE /{id}/)
|
||||
|
||||
|
||||
def inst_banner_url(pk):
|
||||
return f'/api/cms/institutions/{pk}/banner/'
|
||||
|
||||
@@ -113,9 +121,9 @@ class CmsInstitutionCrudTest(CacheTestCase):
|
||||
self.assertEqual(resp.status_code, 200, resp.content)
|
||||
self.assertEqual(resp.json()['id'], inst.id)
|
||||
|
||||
def test_update_patch(self):
|
||||
def test_update_post(self):
|
||||
inst = ensure_institution(name='旧名', code='CMS-UPD')
|
||||
resp = self.client.patch(inst_detail_url(inst.id), {'name': '新名', 'level': '二甲'})
|
||||
resp = self.client.post(inst_update_url(inst.id), {'name': '新名', 'level': '二甲'})
|
||||
self.assertEqual(resp.status_code, 200, resp.content)
|
||||
self.assertEqual(resp.json()['name'], '新名')
|
||||
inst.refresh_from_db()
|
||||
@@ -125,21 +133,21 @@ class CmsInstitutionCrudTest(CacheTestCase):
|
||||
def test_update_duplicate_code(self):
|
||||
ensure_institution(name='A', code='CMS-A')
|
||||
inst_b = ensure_institution(name='B', code='CMS-B')
|
||||
resp = self.client.patch(inst_detail_url(inst_b.id), {'code': 'CMS-A'})
|
||||
resp = self.client.post(inst_update_url(inst_b.id), {'code': 'CMS-A'})
|
||||
self.assertEqual(resp.status_code, 400, resp.content)
|
||||
self.assertEqual(resp.json()['code'], 'CMS_INSTITUTION_CODE_EXISTS')
|
||||
|
||||
def test_update_same_code_ok(self):
|
||||
"""编辑时传自己原 code 不算冲突。"""
|
||||
inst = ensure_institution(name='自身', code='CMS-SELF')
|
||||
resp = self.client.patch(inst_detail_url(inst.id), {'code': 'CMS-SELF', 'name': '改名'})
|
||||
resp = self.client.post(inst_update_url(inst.id), {'code': 'CMS-SELF', 'name': '改名'})
|
||||
self.assertEqual(resp.status_code, 200, resp.content)
|
||||
|
||||
def test_delete_is_soft(self):
|
||||
"""停用 = 逻辑删除:默认管理器查不到,但库里仍在(all_objects 可见)。"""
|
||||
inst = ensure_institution(name='可停用', code='CMS-DEL')
|
||||
resp = self.client.delete(inst_detail_url(inst.id))
|
||||
self.assertEqual(resp.status_code, 204, resp.content)
|
||||
resp = self.client.post(inst_disable_url(inst.id))
|
||||
self.assertEqual(resp.status_code, 200, resp.content)
|
||||
# 默认管理器(已过滤 is_deleted)查不到
|
||||
self.assertFalse(Institution.objects.filter(id=inst.id).exists())
|
||||
# 实际未物理删除
|
||||
@@ -150,7 +158,7 @@ class CmsInstitutionCrudTest(CacheTestCase):
|
||||
def test_deleted_not_in_list(self):
|
||||
"""软删后不出现在列表。"""
|
||||
inst = ensure_institution(name='停用后隐藏', code='CMS-HIDE')
|
||||
self.client.delete(inst_detail_url(inst.id))
|
||||
self.client.post(inst_disable_url(inst.id))
|
||||
resp = self.client.get(CMS_INST_URL, {'search': 'CMS-HIDE'})
|
||||
codes = {i['code'] for i in resp.json()['results']}
|
||||
self.assertNotIn('CMS-HIDE', codes)
|
||||
@@ -166,7 +174,7 @@ class CmsInstitutionCrudTest(CacheTestCase):
|
||||
编码唯一约束对软删行仍生效,须按 all_objects 校验,避免写库时撞约束抛 500。
|
||||
"""
|
||||
inst = ensure_institution(name='待停用', code='CMS-SOFT-DUP')
|
||||
self.client.delete(inst_detail_url(inst.id))
|
||||
self.client.post(inst_disable_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)
|
||||
|
||||
Reference in New Issue
Block a user