Skip to content

Commit 54a1dc4

Browse files
committed
Merge branch 'route-response-type' into switch-to-responses
2 parents fc4949b + 2fb2305 commit 54a1dc4

File tree

2 files changed

+21
-30
lines changed

2 files changed

+21
-30
lines changed

src/mock_vws/_requests_mock_server/mock_web_query_api.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222

2323
_ROUTES: set[Route] = set()
2424

25+
_ResponseType = str
26+
2527

2628
def route(
2729
path_pattern: str,
2830
http_methods: set[str],
29-
) -> Callable[[Callable[..., str]], Callable[..., str]]:
31+
) -> Callable[[Callable[..., _ResponseType]], Callable[..., _ResponseType]]:
3032
"""
3133
Register a decorated method so that it can be recognized as a route.
3234
@@ -39,7 +41,9 @@ def route(
3941
A decorator which takes methods and makes them recognizable as routes.
4042
"""
4143

42-
def decorator(method: Callable[..., str]) -> Callable[..., str]:
44+
def decorator(
45+
method: Callable[..., _ResponseType],
46+
) -> Callable[..., _ResponseType]:
4347
"""
4448
Register a decorated method so that it can be recognized as a route.
4549
@@ -93,7 +97,7 @@ def __init__(
9397
self._query_match_checker = query_match_checker
9498

9599
@route(path_pattern="/v1/query", http_methods={HTTPMethod.POST})
96-
def query(self, request: "Request", context: "Context") -> str:
100+
def query(self, request: "Request", context: "Context") -> _ResponseType:
97101
"""
98102
Perform an image recognition query.
99103
"""

src/mock_vws/_requests_mock_server/mock_web_services_api.py

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@
3838

3939
_ROUTES: set[Route] = set()
4040

41+
_ResponseType = str
42+
4143

4244
def route(
4345
path_pattern: str,
4446
http_methods: set[HTTPMethod],
45-
) -> Callable[[Callable[..., str]], Callable[..., str]]:
47+
) -> Callable[[Callable[..., str]], Callable[..., _ResponseType]]:
4648
"""
4749
Register a decorated method so that it can be recognized as a route.
4850
@@ -55,7 +57,9 @@ def route(
5557
A decorator which takes methods and makes them recognizable as routes.
5658
"""
5759

58-
def decorator(method: Callable[..., str]) -> Callable[..., str]:
60+
def decorator(
61+
method: Callable[..., _ResponseType],
62+
) -> Callable[..., _ResponseType]:
5963
"""
6064
Register a decorated method so that it can be recognized as a route.
6165
@@ -128,9 +132,7 @@ def __init__(
128132
path_pattern="/targets",
129133
http_methods={HTTPMethod.POST},
130134
)
131-
def add_target(
132-
self, request: PreparedRequest
133-
) -> tuple[int, dict[str, str], str]:
135+
def add_target(self, request: PreparedRequest) -> _ResponseType:
134136
"""
135137
Add a target.
136138
@@ -206,9 +208,7 @@ def add_target(
206208
path_pattern=f"/targets/{_TARGET_ID_PATTERN}",
207209
http_methods={HTTPMethod.DELETE},
208210
)
209-
def delete_target(
210-
self, request: PreparedRequest
211-
) -> tuple[int, dict[str, str], str]:
211+
def delete_target(self, request: PreparedRequest) -> _ResponseType:
212212
"""
213213
Delete a target.
214214
@@ -273,10 +273,7 @@ def delete_target(
273273
return HTTPStatus.OK, headers, body_json
274274

275275
@route(path_pattern="/summary", http_methods={HTTPMethod.GET})
276-
def database_summary(
277-
self,
278-
request: PreparedRequest,
279-
) -> tuple[int, dict[str, str], str]:
276+
def database_summary(self, request: PreparedRequest) -> _ResponseType:
280277
"""
281278
Get a database summary report.
282279
@@ -341,9 +338,7 @@ def database_summary(
341338
return HTTPStatus.OK, headers, body_json
342339

343340
@route(path_pattern="/targets", http_methods={HTTPMethod.GET})
344-
def target_list(
345-
self, request: PreparedRequest
346-
) -> tuple[int, dict[str, str], str]:
341+
def target_list(self, request: PreparedRequest) -> _ResponseType:
347342
"""
348343
Get a list of all targets.
349344
@@ -401,9 +396,7 @@ def target_list(
401396
path_pattern=f"/targets/{_TARGET_ID_PATTERN}",
402397
http_methods={HTTPMethod.GET},
403398
)
404-
def get_target(
405-
self, request: PreparedRequest
406-
) -> tuple[int, dict[str, str], str]:
399+
def get_target(self, request: PreparedRequest) -> _ResponseType:
407400
"""
408401
Get details of a target.
409402
@@ -469,9 +462,7 @@ def get_target(
469462
path_pattern=f"/duplicates/{_TARGET_ID_PATTERN}",
470463
http_methods={HTTPMethod.GET},
471464
)
472-
def get_duplicates(
473-
self, request: PreparedRequest
474-
) -> tuple[int, dict[str, str], str]:
465+
def get_duplicates(self, request: PreparedRequest) -> _ResponseType:
475466
"""
476467
Get targets which may be considered duplicates of a given target.
477468
@@ -543,9 +534,7 @@ def get_duplicates(
543534
path_pattern=f"/targets/{_TARGET_ID_PATTERN}",
544535
http_methods={HTTPMethod.PUT},
545536
)
546-
def update_target(
547-
self, request: PreparedRequest
548-
) -> tuple[int, dict[str, str], str]:
537+
def update_target(self, request: PreparedRequest) -> _ResponseType:
549538
"""
550539
Update a target.
551540
@@ -653,9 +642,7 @@ def update_target(
653642
path_pattern=f"/summary/{_TARGET_ID_PATTERN}",
654643
http_methods={HTTPMethod.GET},
655644
)
656-
def target_summary(
657-
self, request: PreparedRequest
658-
) -> tuple[int, dict[str, str], str]:
645+
def target_summary(self, request: PreparedRequest) -> _ResponseType:
659646
"""
660647
Get a summary report for a target.
661648

0 commit comments

Comments
 (0)