File tree 3 files changed +7
-2
lines changed
3 files changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -157,6 +157,8 @@ def items(self) -> ItemCollection:
157
157
158
158
@classmethod
159
159
def validate (cls , payload : Dict [str , Any ]) -> bool :
160
+ """Validates the payload and returns True if valid. If invalid, raises
161
+ ``stactask.exceptions.FailedValidation`` or returns False."""
160
162
# put validation logic on input Items and process definition here
161
163
return True
162
164
Original file line number Diff line number Diff line change 1
1
from typing import Any , Dict , List
2
2
3
3
from stactask import Task
4
+ from stactask .exceptions import FailedValidation
4
5
5
6
6
7
class NothingTask (Task ):
@@ -17,7 +18,9 @@ class FailValidateTask(Task):
17
18
18
19
@classmethod
19
20
def validate (self , payload : Dict [str , Any ]) -> bool :
20
- return False
21
+ if payload :
22
+ raise FailedValidation ("Extra context about what went wrong" )
23
+ return True
21
24
22
25
def process (self , ** kwargs : Any ) -> List [Dict [str , Any ]]:
23
26
return self .items_as_dicts
Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ def test_task_init(nothing_task: Task) -> None:
41
41
42
42
43
43
def test_failed_validation (items : Dict [str , Any ]) -> None :
44
- with pytest .raises (FailedValidation ):
44
+ with pytest .raises (FailedValidation , match = "Extra context" ):
45
45
FailValidateTask (items )
46
46
47
47
You can’t perform that action at this time.
0 commit comments