Skip to content

Commit 6323f87

Browse files
committed
Passing tests on mock for target API
1 parent ef7ee6d commit 6323f87

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

src/mock_vws/_mock_web_services_api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
validate_name_length,
4646
validate_name_type,
4747
validate_not_invalid_json,
48+
validate_project_state,
4849
validate_width,
4950
)
5051

@@ -179,6 +180,7 @@ def decorator(method: Callable[..., str]) -> Callable[..., str]:
179180
decorators = [
180181
parse_target_id,
181182
validate_authorization,
183+
validate_project_state,
182184
validate_metadata_size,
183185
validate_metadata_encoding,
184186
validate_metadata_type,

src/mock_vws/_validators.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
from mock_vws._constants import ResultCodes
2525
from mock_vws._mock_common import json_dump
26+
from ._constants import States
2627

2728

2829
def compute_hmac_base64(key: bytes, data: bytes) -> bytes:
@@ -127,14 +128,14 @@ def validate_active_flag(
127128

128129

129130
@wrapt.decorator
130-
def validate_project_status(
131+
def validate_project_state(
131132
wrapped: Callable[..., str],
132-
instance: Any, # pylint: disable=unused-argument
133+
instance: Any,
133134
args: Tuple[_RequestObjectProxy, _Context],
134135
kwargs: Dict,
135136
) -> str:
136137
"""
137-
Validate the active flag data given to the endpoint.
138+
Validate the state of the project.
138139
139140
Args:
140141
wrapped: An endpoint function for `requests_mock`.
@@ -144,30 +145,26 @@ def validate_project_status(
144145
145146
Returns:
146147
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-
"""
148+
A `FORBIDDEN` response with a PROJECT_INACTIVE result code if the
149+
project is inactive.
150+
"""
151151
request, context = args
152152

153-
if not request.text:
153+
if instance.state != States.PROJECT_INACTIVE:
154154
return wrapped(*args, **kwargs)
155155

156-
if 'active_flag' not in request.json():
156+
if request.method == 'GET' and 'duplicates' not in request.path:
157157
return wrapped(*args, **kwargs)
158158

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)
159+
context.status_code = codes.FORBIDDEN
163160

164-
context.status_code = codes.BAD_REQUEST
165161
body: Dict[str, str] = {
166162
'transaction_id': uuid.uuid4().hex,
167-
'result_code': ResultCodes.FAIL.value,
163+
'result_code': ResultCodes.PROJECT_INACTIVE.value,
168164
}
169165
return json_dump(body)
170166

167+
171168
@wrapt.decorator
172169
def validate_not_invalid_json(
173170
wrapped: Callable[..., str],

0 commit comments

Comments
 (0)