限制一楼活动每次上传最多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
+5 -5
View File
@@ -20,20 +20,20 @@ def package(entries=None):
class CenterExportTests(ApiTestCase):
async def test_material_with_over_100_photos_can_be_created_edited_and_downloaded(self):
async def test_material_with_20_photos_can_be_created_edited_and_downloaded(self):
owner=await register(self.client,'manyphotos');headers=auth(owner['token'])
image=io.BytesIO();Image.new('RGB',(20,20),'blue').save(image,'PNG')
raw=package([(f'照片/{i}.png',image.getvalue()) for i in range(101)])
raw=package([(f'照片/{i}.png',image.getvalue()) for i in range(20)])
with tempfile.TemporaryDirectory() as directory,patch.object(self.m,'_db_path',Path(directory)/'test.db'):
response=await self.client.post('/api/center/materials',headers=headers,content=raw)
self.assertEqual(response.status_code,200,response.text)
material=response.json();self.assertEqual(len(material['photo_ids']),101)
material=response.json();self.assertEqual(len(material['photo_ids']),20)
response=await self.client.post('/api/activities',headers=headers,json={
'title':'多照片一楼活动','start_at':self.m.now_ms(),'record_type':'center',
'material_id':material['id'],'photo_ids':material['photo_ids'],
})
self.assertEqual(response.status_code,200,response.text)
activity=response.json()['activity'];self.assertEqual(len(activity['photo_ids']),101)
activity=response.json()['activity'];self.assertEqual(len(activity['photo_ids']),20)
edited=await self.client.patch('/api/activities/'+activity['id'],headers=headers,json={
'description':'更新说明','photo_ids':material['photo_ids'],
})
@@ -43,7 +43,7 @@ class CenterExportTests(ApiTestCase):
self.assertEqual(downloaded.status_code,200);self.assertEqual(downloaded.content,raw)
last_photo=await self.client.get('/api/center/photos/'+material['photo_ids'][-1],headers=headers)
self.assertEqual(last_photo.status_code,200)
# 同一天已有超过100张照片,也可以继续提交ZIP材料。
# 单次20张后仍可继续补充其他材料。
second=await self.client.post('/api/center/materials',headers=headers,content=package())
self.assertEqual(second.status_code,200,second.text)