All checks were successful
Build and deploy / Validate source (push) Successful in 7s
Build and deploy / Integration suite on a real stack (push) Successful in 3m37s
Build and deploy / Secret scan and release gate (push) Successful in 7s
Build and deploy / Publish images (push) Successful in 1m11s
The Site reads the first bytes when a file is chosen and renames it to its real extension: a .cdr that is a PDF is measured and priced as a PDF, without the manual charge; a JPG called .png is refused, naming the file. The scan does the same on the server and stores the real name, so every decision that reads the name follows the content. A name its content agrees with stays (an .ai is a PDF inside but is still handled by hand). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
57 lines
2.8 KiB
Python
57 lines
2.8 KiB
Python
"""Large sheets: when the original is its own print file, and the format check."""
|
|
import unittest
|
|
|
|
from app.printjobs import whole_sheet
|
|
from app.scanning import check_large, format_matches, real_name
|
|
|
|
ROW = {'id': 'u1', 'name': 'folha.png', 'size': 3 * 1024 ** 3, 'scan_state': 'clean',
|
|
'purged_at': None, 'expired': False}
|
|
|
|
|
|
def sheet(**changes):
|
|
source = {'kind': 'sheet', 'width_cm': 57, 'length_cm': 500, 'copies': 1}
|
|
place = {'x_cm': 0, 'y_cm': 0, 'rotation_degrees': 0, 'mirrored': False}
|
|
for key, value in changes.items():
|
|
(source if key in source else place)[key] = value
|
|
return {'uploads': ['u1'], 'production': {'film_width_cm': 57, 'sources': [source], 'placements': [place]}}
|
|
|
|
|
|
class WholeSheetTest(unittest.TestCase):
|
|
def test_a_finished_sheet_placed_whole_is_its_own_print_file(self):
|
|
self.assertIs(whole_sheet(sheet(), {'u1': ROW}), ROW)
|
|
|
|
def test_anything_else_is_prepared_by_hand(self):
|
|
for changes in ({'copies': 2}, {'kind': 'artwork'}, {'rotation_degrees': 90}, {'mirrored': True},
|
|
{'x_cm': 1}, {'width_cm': 50}):
|
|
with self.subTest(changes=changes):
|
|
self.assertIsNone(whole_sheet(sheet(**changes), {'u1': ROW}))
|
|
self.assertIsNone(whole_sheet(sheet(), {'u1': {**ROW, 'name': 'folha.cdr'}}))
|
|
self.assertIsNone(whole_sheet(sheet(), {'u1': {**ROW, 'scan_state': 'pending'}}))
|
|
self.assertIsNone(whole_sheet(sheet(), {'u1': {**ROW, 'expired': True}}))
|
|
|
|
|
|
class FormatTest(unittest.TestCase):
|
|
def test_bytes_must_match_the_name(self):
|
|
self.assertTrue(format_matches('A.PNG', b'\x89PNG\r\n\x1a\n'))
|
|
self.assertTrue(format_matches('a.tiff', b'MM\x00*'))
|
|
self.assertFalse(format_matches('a.png', b'%PDF-1.4'))
|
|
self.assertFalse(format_matches('semextensao', b'\x89PNG\r\n\x1a\n'))
|
|
|
|
def test_the_content_names_the_file(self):
|
|
# Dropstar's rule D-13: a ".cdr" that is a PDF is a PDF, a JPG called
|
|
# ".png" is a JPG; a name its content agrees with stays (".ai" is a PDF inside).
|
|
self.assertEqual(real_name('folha.cdr', b'%PDF-1.7'), 'folha.pdf')
|
|
self.assertEqual(real_name('arte.png', b'\xff\xd8\xff\xe0'), 'arte.jpg')
|
|
self.assertEqual(real_name('semextensao', b'%PDF-1.4'), 'semextensao.pdf')
|
|
for name, head in (('folha.cdr', b'RIFF\0\0\0\0CDR9'), ('arte.ai', b'%PDF-1.5'), ('arte.ai', b'%!PS-Adobe'),
|
|
('foto.jpeg', b'\xff\xd8\xff'), ('arte.png', b'GIF89a')):
|
|
self.assertEqual(real_name(name, head), name, (name, head))
|
|
|
|
def test_a_large_file_passes_on_its_content(self):
|
|
self.assertEqual(check_large(b'%PDF-1.7', {'name': 'folha.cdr'})[0], 'clean')
|
|
self.assertEqual(check_large(b'MZ\x90\x00', {'name': 'folha.cdr'})[0], 'rejected')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|