Skip to content

Commit ef7ee6d

Browse files
committed
Stub for validator
1 parent 4f1babf commit ef7ee6d

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/mock_vws/_validators.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,48 @@ def validate_active_flag(
126126
return json_dump(body)
127127

128128

129+
@wrapt.decorator
130+
def validate_project_status(
131+
wrapped: Callable[..., str],
132+
instance: Any, # pylint: disable=unused-argument
133+
args: Tuple[_RequestObjectProxy, _Context],
134+
kwargs: Dict,
135+
) -> str:
136+
"""
137+
Validate the active flag data given to the endpoint.
138+
139+
Args:
140+
wrapped: An endpoint function for `requests_mock`.
141+
instance: The class that the endpoint function is in.
142+
args: The arguments given to the endpoint function.
143+
kwargs: The keyword arguments given to the endpoint function.
144+
145+
Returns:
146+
The result of calling the endpoint.
147+
A `BAD_REQUEST` response with a FAIL result code if there is
148+
active flag data given to the endpoint which is not either a Boolean or
149+
NULL.
150+
"""
151+
request, context = args
152+
153+
if not request.text:
154+
return wrapped(*args, **kwargs)
155+
156+
if 'active_flag' not in request.json():
157+
return wrapped(*args, **kwargs)
158+
159+
active_flag = request.json().get('active_flag')
160+
161+
if active_flag is None or isinstance(active_flag, bool):
162+
return wrapped(*args, **kwargs)
163+
164+
context.status_code = codes.BAD_REQUEST
165+
body: Dict[str, str] = {
166+
'transaction_id': uuid.uuid4().hex,
167+
'result_code': ResultCodes.FAIL.value,
168+
}
169+
return json_dump(body)
170+
129171
@wrapt.decorator
130172
def validate_not_invalid_json(
131173
wrapped: Callable[..., str],

0 commit comments

Comments
 (0)