"""Empty strips cut from a ready sheet (Marcus, 2026-11-18): only a measured finished sheet may carry them, and they never change what is placed. Run from the repository root: python3 -m unittest tests.test_sheet_trim -v. """ import unittest from uuid import uuid4 from pydantic import ValidationError from app.core.models import Item def sheet_item(mode='file', kind='sheet', measurement='file', top=10, bottom=40): upload = str(uuid4()) width = 27 if mode in ('uvfile', 'uv') else 57 return {'mode': mode, 'metres': '4.6', 'grade': 100, 'uploads': [upload], 'quality_status': 'ok', 'quality_acknowledged': False, 'production': {'version': 3, 'film_width_cm': width, 'height_cm': '453.8', 'sources': [{'upload_id': upload, 'kind': kind, 'width_cm': width, 'length_cm': '453.8', 'copies': 1, 'measurement': measurement, 'trim_top_cm': top, 'trim_bottom_cm': bottom}], 'placements': [{'source_index': 0, 'copy_index': 0, 'x_cm': 0, 'y_cm': 0, 'width_cm': width, 'length_cm': '453.8', 'rotation_degrees': 0, 'mirrored': False}]}} class SheetTrimTests(unittest.TestCase): def test_a_measured_ready_sheet_carries_its_cut_strips(self): item = Item.model_validate(sheet_item(mode='uvfile')) source = item.production.sources[0] self.assertEqual((source.trim_top_cm, source.trim_bottom_cm), (10, 40)) def test_no_strips_by_default(self): data = sheet_item() del data['production']['sources'][0]['trim_top_cm'], data['production']['sources'][0]['trim_bottom_cm'] source = Item.model_validate(data).production.sources[0] self.assertEqual((source.trim_top_cm, source.trim_bottom_cm), (0, 0)) def test_only_a_measured_ready_sheet_is_trimmed(self): with self.assertRaises(ValidationError): Item.model_validate(sheet_item(measurement='customer')) with self.assertRaises(ValidationError): Item.model_validate(sheet_item(mode='avulsa', kind='artwork')) with self.assertRaises(ValidationError): Item.model_validate(sheet_item(top=-1)) if __name__ == '__main__': unittest.main()