feat(입출고): 입고증 사진 왼쪽·오른쪽 회전 — 돌린 상태로 저장

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-02 15:46:18 +09:00
parent b3001c3051
commit f7a3afcebf
13 changed files with 197 additions and 14 deletions
+63
View File
@@ -25,6 +25,69 @@ def _order(**over):
return o
class RotateTests(unittest.TestCase):
"""입고증 사진 돌리기(2026-11-02) — 시계 방향·형식 유지·EXIF 반영."""
@staticmethod
def _image(fmt, size=(40, 20), **save):
from io import BytesIO
from PIL import Image
im = Image.new("RGB", size, (255, 0, 0))
im.paste((0, 0, 255), (0, 0, size[0] // 2, size[1] // 2)) # 왼쪽 위만 파랑
buf = BytesIO()
im.save(buf, format=fmt, **save)
return buf.getvalue()
@staticmethod
def _open(data):
from io import BytesIO
from PIL import Image
return Image.open(BytesIO(data))
def test_right_and_left_turn_corner_the_right_way(self):
right = self._open(s.rotate_image(self._image("PNG"), 90))
self.assertEqual(right.size, (20, 40))
self.assertEqual(right.convert("RGB").getpixel((19, 0)), (0, 0, 255)) # 왼쪽 위 → 시계 방향이면 오른쪽 위
left = self._open(s.rotate_image(self._image("PNG"), 270))
self.assertEqual(left.convert("RGB").getpixel((0, 39)), (0, 0, 255)) # 반시계면 왼쪽 아래
def test_keeps_format(self):
for fmt, kind in (("JPEG", "image/jpeg"), ("PNG", "image/png"), ("WEBP", "image/webp"), ("GIF", "image/gif")):
with self.subTest(fmt=fmt):
out = s.rotate_image(self._image(fmt), 90)
self.assertEqual(s.sniff_image(out), kind)
self.assertEqual(self._open(out).size, (20, 40))
def test_phone_exif_is_applied_then_dropped(self):
"""휴대폰 사진(EXIF 회전 6 = 화면에선 세로) — 돌린 결과는 화면에 보이던 모습 기준이어야 하고 EXIF 회전이 남으면 안 된다."""
from PIL import Image
exif = Image.Exif()
exif[0x0112] = 6
out = self._open(s.rotate_image(self._image("JPEG", exif=exif.tobytes()), 90))
self.assertEqual(out.size, (40, 20)) # 화면 20×40 → 오른쪽으로 돌려 40×20
self.assertNotEqual(out.getexif().get(0x0112), 6)
def test_refuses_what_cannot_be_turned(self):
for bad, msg in ((b"....ftypheic" + b"0" * 20, "HEIC"), (JPEG, "돌릴 수 없")):
with self.subTest(msg=msg), self.assertRaisesRegex(ValueError, msg):
s.rotate_image(bad, 90)
with self.assertRaisesRegex(ValueError, "왼쪽·오른쪽"):
s.rotate_image(self._image("PNG"), 45)
from io import BytesIO
from PIL import Image
buf = BytesIO()
Image.new("RGB", (4, 4), (255, 0, 0)).save(buf, format="GIF", save_all=True, append_images=[Image.new("RGB", (4, 4), (0, 0, 255))])
with self.assertRaisesRegex(ValueError, "움직이는"):
s.rotate_image(buf.getvalue(), 90)
class MailContentTests(unittest.TestCase):
def test_parse_emails(self):
self.assertEqual(s.parse_emails("a@x.com, B@y.co.kr; a@X.com\nc@z.kr"), ["a@x.com", "B@y.co.kr", "c@z.kr"])