feat(입출고): 입고증 사진 왼쪽·오른쪽 회전 — 돌린 상태로 저장
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+15
-1
@@ -197,9 +197,23 @@ class InoutDbTests(unittest.TestCase):
|
||||
self.st.add_receipt_photos(o["id"], rid, [("e.jpg", jpeg)], by="w@x")
|
||||
with self.assertRaisesRegex(ValueError, "찾을 수 없"):
|
||||
self.st.add_receipt_photos(o["id"], 999999, [("e.jpg", jpeg)], by="w@x")
|
||||
o2 = self.order([("MT-Q", 1)])
|
||||
# 돌리기(2026-11-02) — 저장된 내용·크기가 바뀌고, 다른 발주서 id 로는 못 돌린다(내용이 가짜 JPEG 이면 원본 그대로)
|
||||
with self.assertRaisesRegex(ValueError, "찾을 수 없"):
|
||||
self.st.rotate_receipt_photo(o2["id"], ph[1]["id"], 90)
|
||||
from io import BytesIO
|
||||
|
||||
from PIL import Image
|
||||
|
||||
buf = BytesIO()
|
||||
Image.new("RGB", (40, 20), (255, 0, 0)).save(buf, format="JPEG")
|
||||
with self.st._pool.connection() as conn:
|
||||
conn.execute("UPDATE inout_receipt_photos SET data=%s WHERE id=%s", (buf.getvalue(), ph[1]["id"]))
|
||||
self.st.rotate_receipt_photo(o["id"], ph[1]["id"], 90)
|
||||
turned = self.st.get_photo(ph[1]["id"])
|
||||
self.assertEqual(Image.open(BytesIO(bytes(turned["data"]))).size, (20, 40))
|
||||
self.st.delete_receipt_photo(o["id"], ph[0]["id"])
|
||||
self.assertIsNone(self.st.get_photo(ph[0]["id"]))
|
||||
o2 = self.order([("MT-Q", 1)])
|
||||
with self.assertRaisesRegex(ValueError, "찾을 수 없"): # 다른 발주서의 사진 id 로는 못 지운다
|
||||
self.st.delete_receipt_photo(o2["id"], ph[1]["id"])
|
||||
self.st.delete_receipt(o["id"], rid, by="w@x") # 입고를 지우면 사진도 함께
|
||||
|
||||
@@ -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"])
|
||||
|
||||
@@ -225,6 +225,12 @@ def body(c):
|
||||
img = c.get("/inout/photos/%d" % pids[0])
|
||||
assert img.status_code == 200 and img.content == JPEG and img.headers["content-type"] == "image/jpeg"
|
||||
assert img.headers["x-content-type-options"] == "nosniff" and "sandbox" in img.headers["content-security-policy"]
|
||||
# 돌린 사진이 캐시에 남지 않게 — 매번 확인(no-cache + ETag), 같으면 304
|
||||
assert "no-cache" in img.headers["cache-control"] and img.headers["etag"]
|
||||
assert c.get("/inout/photos/%d" % pids[0], headers={"If-None-Match": img.headers["etag"]}).status_code == 304
|
||||
# 내용이 가짜 JPEG 이면 원본 그대로, 안내만(400)
|
||||
r = c.post("/inout/orders/%d/photos/%d/rotate?degrees=90" % (oid3, pids[0]))
|
||||
assert r.status_code == 400 and r.json()["error"] and c.get("/inout/photos/%d" % pids[0]).content == JPEG, r.text
|
||||
page = c.get("/inout/orders/%d" % oid3).text
|
||||
assert 'data-photo="%d"' % pids[0] in page and 'src="/inout/photos/%d"' % pids[0] in page
|
||||
rid3 = got["receipts"][0]["id"]
|
||||
@@ -234,6 +240,7 @@ def body(c):
|
||||
who["u"] = viewer
|
||||
assert c.get("/inout/photos/%d" % pids[0]).status_code == 200 # 모듈 권한이면 보기는 됨
|
||||
assert c.post("/inout/orders/%d/photos/%d/delete" % (oid3, pids[0])).status_code == 403
|
||||
assert c.post("/inout/orders/%d/photos/%d/rotate?degrees=90" % (oid3, pids[0])).status_code == 403
|
||||
who["u"] = U("nobody-%s@t.local" % tag, inout=False)
|
||||
assert c.get("/inout/photos/%d" % pids[0]).status_code == 403
|
||||
who["u"] = wh
|
||||
|
||||
Reference in New Issue
Block a user