diff --git a/stactask/task.py b/stactask/task.py index e0f2db6..f206a5b 100644 --- a/stactask/task.py +++ b/stactask/task.py @@ -157,6 +157,8 @@ def items(self) -> ItemCollection: @classmethod def validate(cls, payload: Dict[str, Any]) -> bool: + """Validates the payload and returns True if valid. If invalid, raises + ``stactask.exceptions.FailedValidation`` or returns False.""" # put validation logic on input Items and process definition here return True diff --git a/tests/tasks.py b/tests/tasks.py index 58aebc5..401ebf2 100644 --- a/tests/tasks.py +++ b/tests/tasks.py @@ -1,6 +1,7 @@ from typing import Any, Dict, List from stactask import Task +from stactask.exceptions import FailedValidation class NothingTask(Task): @@ -17,7 +18,9 @@ class FailValidateTask(Task): @classmethod def validate(self, payload: Dict[str, Any]) -> bool: - return False + if payload: + raise FailedValidation("Extra context about what went wrong") + return True def process(self, **kwargs: Any) -> List[Dict[str, Any]]: return self.items_as_dicts diff --git a/tests/test_task.py b/tests/test_task.py index e794d46..982c8ec 100644 --- a/tests/test_task.py +++ b/tests/test_task.py @@ -41,7 +41,7 @@ def test_task_init(nothing_task: Task) -> None: def test_failed_validation(items: Dict[str, Any]) -> None: - with pytest.raises(FailedValidation): + with pytest.raises(FailedValidation, match="Extra context"): FailValidateTask(items)