Skip to content

Commit c16e911

Browse files
committed
make unit tests pass
1 parent 583d864 commit c16e911

File tree

2 files changed

+13
-13
lines changed
  • services/api-server/src/simcore_service_api_server/models

2 files changed

+13
-13
lines changed

services/api-server/src/simcore_service_api_server/models/domain/files.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from mimetypes import guess_type
21
from pathlib import Path
32
from typing import Annotated
43
from urllib.parse import quote as _quote
@@ -17,8 +16,6 @@
1716
Field,
1817
StringConstraints,
1918
TypeAdapter,
20-
ValidationInfo,
21-
field_validator,
2219
)
2320
from servicelib.file_utils import create_sha256_checksum
2421

@@ -86,16 +83,6 @@ class File(BaseModel):
8683
},
8784
)
8885

89-
@field_validator("content_type", mode="before")
90-
@classmethod
91-
def guess_content_type(cls, v, info: ValidationInfo):
92-
if v is None:
93-
filename = info.data.get("filename")
94-
if filename:
95-
mime_content_type, _ = guess_type(filename, strict=False)
96-
return mime_content_type
97-
return v
98-
9986
@classmethod
10087
async def create_from_path(cls, path: Path) -> "File":
10188
async with aiofiles.open(path, mode="rb") as file:

services/api-server/src/simcore_service_api_server/models/schemas/files.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import datetime
2+
from mimetypes import guess_type
23
from typing import Annotated
34
from uuid import UUID
45

@@ -10,6 +11,8 @@
1011
ConfigDict,
1112
Field,
1213
NonNegativeInt,
14+
ValidationInfo,
15+
field_validator,
1316
)
1417

1518
from .._utils_pydantic import UriSchema
@@ -81,6 +84,16 @@ class File(ApiServerOutputSchema):
8184
},
8285
)
8386

87+
@field_validator("content_type", mode="before")
88+
@classmethod
89+
def guess_content_type(cls, v, info: ValidationInfo):
90+
if v is None:
91+
filename = info.data.get("filename")
92+
if filename:
93+
mime_content_type, _ = guess_type(filename, strict=False)
94+
return mime_content_type
95+
return v
96+
8497
@classmethod
8598
def from_domain_model(cls, file: DomainFile) -> "File":
8699
return cls(

0 commit comments

Comments
 (0)