Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce check_validity method #241

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions cads_adaptors/adaptors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,27 @@ def __init__(
pathlib.Path() if cache_tmp_path is None else cache_tmp_path
)

@abc.abstractmethod
def check_validity(self, request: Request) -> None:
"""Check the validity of the request.

Parameters
----------
request : Request
Incoming request.

Returns
-------
None
If the request is valid.

Raises
------
cads_adaptors.exceptions.InvalidRequest
If the request is invalid.
"""
pass

@abc.abstractmethod
def normalise_request(self, request: Request) -> Request:
"""Apply any normalisation to the request before validation.
Expand Down Expand Up @@ -207,6 +228,9 @@ class DummyAdaptor(AbstractAdaptor):
def apply_constraints(self, request: Request) -> dict[str, Any]:
return {}

def check_validity(self, request: Request) -> None:
return

def estimate_costs(self, request: Request, **kwargs: Any) -> dict[str, int]:
size = int(request.get("size", 0))
time = int(request.get("time", 0.0))
Expand Down
3 changes: 3 additions & 0 deletions cads_adaptors/adaptors/cds.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ def retrieve(self, request: Request) -> BinaryIO:
result = self.retrieve_list_of_results(request)
return self.make_download_object(result)

def check_validity(self, request: Request) -> None:
return

def apply_constraints(self, request: Request) -> dict[str, Any]:
return constraints.validate_constraints(self.form, request, self.constraints)

Expand Down
Loading