Skip to content

Commit

Permalink
add path prefix to TESOutput model
Browse files Browse the repository at this point in the history
  • Loading branch information
salihuDickson committed Oct 21, 2024
1 parent 3541fd0 commit 335b275
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions crategen/models/tes_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ntpath
import posixpath
import re
from enum import Enum
from typing import Optional

Expand Down Expand Up @@ -214,6 +215,18 @@ class TESOutput(BaseModel):
path: str
type: Optional[TESFileType] = TESFileType.FILE

@root_validator()
def validate_is_path_prefix_required(cls, values):
"""If the 'path' property contains wildcards then the 'path_prefix' property is required"""
path = values.get("path")
path_prefix = values.get("path_prefix")
pattern = r"[\*\?]"

if bool(re.search(pattern, path)) and not bool(path_prefix):
raise ValueError(
"The 'path_prefix' property is required when the 'path' property contains wildcards"
)

@validator("path")
def validate_path(cls, value):
"""Ensure that 'path' is an absolute path and handle wildcards."""
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_tes_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
r"C:\Users\user\Document.pdf",
r"D:\Projects\my_website\index.html",
r"\\server\share",
# "s3://my-bucket/data/file.txt",
]

invalid_paths = [
Expand Down

0 comments on commit 335b275

Please sign in to comment.