This commit is contained in:
2026-07-05 21:27:23 +09:00
parent 23d907265a
commit 3abc2edba6
83 changed files with 10351 additions and 1217 deletions
+100
View File
@@ -0,0 +1,100 @@
import json
import unittest
from typing import Any
from uuid import UUID
from B03_FileInput.B03_FileInput_Repository import (
create_input_file,
get_project_storage_relative_path,
)
class FakeCursor:
"""asyncmy 커서 흉내 (async context manager + execute/fetchone/lastrowid)."""
def __init__(self, *, lastrowid: int = 0, row: tuple[Any, ...] | None = None) -> None:
self.query = ""
self.arguments: tuple[Any, ...] = ()
self.lastrowid = lastrowid
self._row = row
async def __aenter__(self) -> "FakeCursor":
return self
async def __aexit__(self, *_exc: Any) -> None:
return None
async def execute(self, query: str, arguments: tuple[Any, ...] | None = None) -> None:
self.query = query
self.arguments = arguments or ()
async def fetchone(self) -> tuple[Any, ...] | None:
return self._row
class FakeConnection:
"""asyncmy 커넥션 흉내 (cursor() 팩토리)."""
def __init__(self, cursor: FakeCursor) -> None:
self._cursor = cursor
def cursor(self) -> FakeCursor:
return self._cursor
class CreateInputFileTest(unittest.IsolatedAsyncioTestCase):
async def test_create_input_file(self) -> None:
cursor = FakeCursor(lastrowid=17)
connection = FakeConnection(cursor)
project_id = UUID("550e8400-e29b-41d4-a716-446655440000")
metadata = {"point_count": 2, "crs": "EPSG:5179"}
input_file_id = await create_input_file( # type: ignore[arg-type]
connection,
project_id=project_id,
file_type="las",
original_filename="cloud.las",
relative_path="B03_FileInput/input/las/cloud.las",
file_size_bytes=1024 * 1024,
upload_by=3,
crs_epsg=5179,
metadata=metadata,
)
self.assertEqual(input_file_id, 17)
self.assertIn("INSERT INTO input_files", cursor.query)
self.assertEqual(cursor.arguments[0], str(project_id))
self.assertEqual(cursor.arguments[3], "B03_FileInput/input/las/cloud.las")
self.assertEqual(cursor.arguments[4], 1.0)
self.assertEqual(json.loads(cursor.arguments[7]), metadata)
with self.assertRaises(ValueError):
await create_input_file( # type: ignore[arg-type]
connection,
project_id=project_id,
file_type="las",
original_filename="cloud.las",
relative_path="../outside/cloud.las",
file_size_bytes=1,
upload_by=None,
crs_epsg=None,
metadata={},
)
async def test_get_project_storage_relative_path(self) -> None:
project_id = UUID("550e8400-e29b-41d4-a716-446655440000")
connection = FakeConnection(FakeCursor(row=("storage/company/user/project-id",)))
relative_path = await get_project_storage_relative_path( # type: ignore[arg-type]
connection,
project_id,
)
self.assertEqual(relative_path, "storage/company/user/project-id")
for row in (None, ("../outside",), ("/absolute/path",)):
with self.subTest(row=row):
with self.assertRaises((LookupError, ValueError)):
await get_project_storage_relative_path( # type: ignore[arg-type]
FakeConnection(FakeCursor(row=row)),
project_id,
)