限制一楼活动每次上传最多20张照片并保留历史材料

This commit is contained in:
2026-11-12 14:17:37 +08:00
parent 3404fff5fc
commit ddf3ba32c6
7 changed files with 80 additions and 11 deletions
+52
View File
@@ -62,6 +62,58 @@ class DirectCenterPhotoTests(ApiTestCase):
more=await c.post('/api/center/materials',headers=headers,content=package([('补充.md','补充文档')]))
self.assertEqual((await c.post('/api/activities/'+aid+'/materials',headers=headers,json={'material_id':more.json()['id']})).status_code,200)
async def test_twenty_photo_batch_limit_and_historical_photos_are_preserved(self):
owner=await register(self.client,'batchlimit');headers=auth(owner['token']);c=self.client
photos=await self.upload(owner,21)
body={'title':'照片上限','start_at':self.m.now_ms(),'record_type':'center','photo_ids':photos}
rejected=await c.post('/api/activities',headers=headers,json=body)
self.assertEqual(rejected.status_code,422,rejected.text);self.assertIn('20张',rejected.text)
body['photo_ids']=photos[:20]
result=await c.post('/api/activities',headers=headers,json=body)
self.assertEqual(result.status_code,200,result.text);aid=result.json()['activity']['id']
path='/api/activities/'+aid
rejected=await c.post(path+'/materials',headers=headers,json={'photo_ids':photos})
self.assertEqual(rejected.status_code,422,rejected.text)
result=await c.post(path+'/materials',headers=headers,json={'photo_ids':photos[20:]})
self.assertEqual(result.status_code,200,result.text);self.assertEqual(len(result.json()['activity']['photo_ids']),21)
# 历史记录超过20张,旧页面提交原照片、或只改说明都能保存。
for changes in ({'description':'只改说明'},{'photo_ids':photos}):
result=await c.patch(path,headers=headers,json=changes)
self.assertEqual(result.status_code,200,result.text);self.assertEqual(len(result.json()['activity']['photo_ids']),21)
extra=await self.upload(owner,21)
rejected=await c.patch(path,headers=headers,json={'photo_ids':extra})
self.assertEqual(rejected.status_code,422,rejected.text)
result=await c.patch(path,headers=headers,json={'photo_ids':extra[:20]})
self.assertEqual(result.status_code,200,result.text);self.assertEqual(len(result.json()['activity']['photo_ids']),41)
detail=(await c.get(path,headers=headers)).json()['activity']
self.assertEqual(set(detail['photo_ids']),set(photos+extra[:20]))
async def test_zip_and_direct_photos_share_twenty_photo_batch_limit(self):
owner=await register(self.client,'mixedlimit');headers=auth(owner['token']);c=self.client
raw=package([(f'{i}.png',image_bytes()) for i in range(21)])
rejected=await c.post('/api/center/materials',headers=headers,content=raw)
self.assertEqual(rejected.status_code,422,rejected.text);self.assertIn('20张',rejected.text)
material=(await c.post('/api/center/materials',headers=headers,content=package())).json()
photos=await self.upload(owner,20)
body={'title':'混合上限','start_at':self.m.now_ms(),'record_type':'center','material_id':material['id'],'photo_ids':photos}
rejected=await c.post('/api/activities',headers=headers,json=body)
self.assertEqual(rejected.status_code,422,rejected.text)
body['photo_ids']=photos[:19]
result=await c.post('/api/activities',headers=headers,json=body)
self.assertEqual(result.status_code,200,result.text);aid=result.json()['activity']['id'];path='/api/activities/'+aid
self.assertEqual(len(result.json()['activity']['photo_ids']),20)
new_material=(await c.post('/api/center/materials',headers=headers,content=package())).json()
batch={'material_id':new_material['id'],'photo_ids':photos}
rejected=await c.post(path+'/materials',headers=headers,json=batch)
self.assertEqual(rejected.status_code,422,rejected.text)
batch['photo_ids']=await self.upload(owner,20)
rejected=await c.patch(path,headers=headers,json=batch)
self.assertEqual(rejected.status_code,422,rejected.text)
batch['photo_ids']=batch['photo_ids'][:19]
result=await c.post(path+'/materials',headers=headers,json=batch)
self.assertEqual(result.status_code,200,result.text)
self.assertEqual(len(result.json()['activity']['photo_ids']),40)
async def test_daily_allowance_allows_more_than_100_and_keeps_1000_limit(self):
owner=await register(self.client,'photolimit');uid=owner['user']['id']
async with self.sessions() as db: