This commit is contained in:
csj
2026-09-16 21:02:44 +08:00
parent 7fea2063aa
commit 45b6f693d6
11 changed files with 320 additions and 86 deletions
+13 -4
View File
@@ -1,4 +1,5 @@
import copy
import io
import json
import os
import subprocess
@@ -65,7 +66,12 @@ class ApprovedPPTTests(unittest.TestCase):
second = Image.new('RGB', (300, 200), 'blue')
first.save(pdf, save_all=True, append_images=[second])
self.record['materials'] = [self.material('invoice', pdf)]
self.assertEqual(len(self.export([self.record]).slides), 1)
deck = self.export([self.record])
self.assertEqual(len(deck.slides), 2)
pictures = [shape for page in deck.slides for shape in page.shapes if shape.shape_type == 13]
self.assertEqual(len(pictures), 1)
with Image.open(io.BytesIO(pictures[0].image.blob)) as preview:
self.assertEqual(preview.convert('RGB').getpixel((0, 0)), (255, 255, 255))
def test_preserves_selected_order_without_merging_people(self):
other = copy.deepcopy(self.record)
@@ -79,7 +85,7 @@ class ApprovedPPTTests(unittest.TestCase):
self.assertEqual(deck.slides[0].shapes[0].image.blob, self.image.read_bytes())
self.assertEqual(deck.slides[2].shapes[0].image.blob, blue.read_bytes())
def test_no_added_metadata_and_same_simple_batch_layout(self):
def test_no_added_metadata_and_same_per_group_layout(self):
self.record['note'] = '采购备注' * 250
self.record['materials'] = [self.material('invoice'), self.material('payment')]
deck = self.export([self.record, copy.deepcopy(self.record)])
@@ -108,7 +114,7 @@ class ApprovedPPTTests(unittest.TestCase):
self.record.update(groupId=1, userId='1', materials=[self.material('invoice'), self.material('payment')])
other = copy.deepcopy(self.record)
other.update(userId='2')
self.assertEqual(len(self.export([self.record, other]).slides), 6)
self.assertEqual(len(self.export([self.record, other]).slides), 2)
def test_failure_keeps_existing_output(self):
destination = self.root / 'original.pptx'
@@ -135,7 +141,10 @@ class ApprovedPPTTests(unittest.TestCase):
events = [json.loads(line) for line in process.stdout.splitlines()]
self.assertEqual(events[-1]['event'], 'result')
self.assertEqual(events[-1]['result']['destination'], str(destination))
self.assertEqual(len(Presentation(destination).slides), 3)
deck = Presentation(destination)
self.assertEqual(len(deck.slides), 1)
self.assertEqual((deck.slide_width, deck.slide_height), (720 * 12700, 960 * 12700))
self.assertEqual(events[-1]['result']['pptLayout'], 'portrait-receipts-v1')
if __name__ == '__main__':