Skip to content

Commit 174be27

Browse files
committed
Add more keyword arguments
1 parent 46d5a99 commit 174be27

19 files changed

+54
-38
lines changed

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
# This method of getting the release from the version goes hand in hand with
4444
# the ``post-release`` versioning scheme chosen in the ``setuptools-scm``
4545
# configuration.
46-
release = version.split(".post")[0]
46+
release = version.split(sep=".post")[0]
4747

4848

4949
project_metadata = importlib.metadata.metadata(distribution_name=project)

src/mock_vws/_database_matchers.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ def get_database_matching_client_keys(
3535
Raises:
3636
ValueError: No database matches the given request.
3737
"""
38-
content_type = request_headers.get("Content-Type", "").split(sep=";")[0]
38+
content_type = request_headers.get("Content-Type", default="").split(
39+
sep=";"
40+
)[0]
3941
auth_header = request_headers.get("Authorization")
40-
date = request_headers.get("Date", "")
42+
date = request_headers.get("Date", default="")
4143

4244
for database in databases:
4345
expected_authorization_header = authorization_header(
@@ -80,9 +82,10 @@ def get_database_matching_server_keys(
8082
Raises:
8183
ValueError: No database matches the given request.
8284
"""
83-
content_type = request_headers.get("Content-Type", "").split(sep=";")[0]
85+
content_type_header = request_headers.get("Content-Type", default="")
86+
content_type = content_type_header.split(sep=";")[0]
8487
auth_header = request_headers.get("Authorization")
85-
date = request_headers.get("Date", "")
88+
date = request_headers.get("Date", default="")
8689

8790
for database in databases:
8891
expected_authorization_header = authorization_header(

src/mock_vws/_flask_server/healthcheck.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ def flask_app_healthy(port: int) -> bool:
1515
"""
1616
Check if the Flask app is healthy.
1717
"""
18-
conn = http.client.HTTPConnection("localhost", port)
18+
conn = http.client.HTTPConnection(host="localhost", port=port)
1919
try:
20-
conn.request("GET", "/some-random-endpoint")
20+
conn.request(method="GET", url="/some-random-endpoint")
2121
response = conn.getresponse()
2222
except (TimeoutError, http.client.HTTPException, socket.gaierror):
2323
return False

src/mock_vws/_flask_server/target_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def delete_database(database_name: str) -> Response:
8888
return Response(response="", status=HTTPStatus.OK)
8989

9090

91-
@TARGET_MANAGER_FLASK_APP.route("/databases", methods=[HTTPMethod.GET])
91+
@TARGET_MANAGER_FLASK_APP.route(rule="/databases", methods=[HTTPMethod.GET])
9292
@beartype
9393
def get_databases() -> Response:
9494
"""
@@ -101,7 +101,7 @@ def get_databases() -> Response:
101101
)
102102

103103

104-
@TARGET_MANAGER_FLASK_APP.route("/databases", methods=[HTTPMethod.POST])
104+
@TARGET_MANAGER_FLASK_APP.route(rule="/databases", methods=[HTTPMethod.POST])
105105
@beartype
106106
def create_database() -> Response:
107107
"""Create a new database.

src/mock_vws/_flask_server/vwq.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def set_terminate_wsgi_input() -> None:
109109
request.environ["wsgi.input_terminated"] = True
110110

111111

112-
@CLOUDRECO_FLASK_APP.errorhandler(ValidatorError)
112+
@CLOUDRECO_FLASK_APP.errorhandler(code_or_exception=ValidatorError)
113113
def handle_exceptions(exc: ValidatorError) -> Response:
114114
"""
115115
Return the error response associated with the given exception.
@@ -125,7 +125,7 @@ def handle_exceptions(exc: ValidatorError) -> Response:
125125
return response
126126

127127

128-
@CLOUDRECO_FLASK_APP.route("/v1/query", methods=[HTTPMethod.POST])
128+
@CLOUDRECO_FLASK_APP.route(rule="/v1/query", methods=[HTTPMethod.POST])
129129
def query() -> Response:
130130
"""
131131
Perform an image recognition query.

src/mock_vws/_flask_server/vws.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def validate_request() -> None:
140140
)
141141

142142

143-
@VWS_FLASK_APP.errorhandler(ValidatorError)
143+
@VWS_FLASK_APP.errorhandler(code_or_exception=ValidatorError)
144144
def handle_exceptions(exc: ValidatorError) -> Response:
145145
"""
146146
Return the error response associated with the given exception.
@@ -156,7 +156,7 @@ def handle_exceptions(exc: ValidatorError) -> Response:
156156
return response
157157

158158

159-
@VWS_FLASK_APP.route("/targets", methods=[HTTPMethod.POST])
159+
@VWS_FLASK_APP.route(rule="/targets", methods=[HTTPMethod.POST])
160160
@beartype
161161
def add_target() -> Response:
162162
"""Add a target.
@@ -228,7 +228,9 @@ def add_target() -> Response:
228228
)
229229

230230

231-
@VWS_FLASK_APP.route("/targets/<string:target_id>", methods=[HTTPMethod.GET])
231+
@VWS_FLASK_APP.route(
232+
rule="/targets/<string:target_id>", methods=[HTTPMethod.GET]
233+
)
232234
@beartype
233235
def get_target(target_id: str) -> Response:
234236
"""Get details of a target.
@@ -337,7 +339,7 @@ def delete_target(target_id: str) -> Response:
337339
)
338340

339341

340-
@VWS_FLASK_APP.route("/summary", methods=[HTTPMethod.GET])
342+
@VWS_FLASK_APP.route(rule="/summary", methods=[HTTPMethod.GET])
341343
@beartype
342344
def database_summary() -> Response:
343345
"""Get a database summary report.
@@ -418,7 +420,7 @@ def target_summary(target_id: str) -> Response:
418420
"result_code": ResultCodes.SUCCESS.value,
419421
"database_name": database.database_name,
420422
"target_name": target.name,
421-
"upload_date": target.upload_date.strftime("%Y-%m-%d"),
423+
"upload_date": target.upload_date.strftime(format="%Y-%m-%d"),
422424
"active_flag": target.active_flag,
423425
"tracking_rating": target.tracking_rating,
424426
"total_recos": target.total_recos,
@@ -506,7 +508,7 @@ def get_duplicates(target_id: str) -> Response:
506508
)
507509

508510

509-
@VWS_FLASK_APP.route("/targets", methods=[HTTPMethod.GET])
511+
@VWS_FLASK_APP.route(rule="/targets", methods=[HTTPMethod.GET])
510512
def target_list() -> Response:
511513
"""Get a list of all targets.
512514
@@ -546,7 +548,9 @@ def target_list() -> Response:
546548
)
547549

548550

549-
@VWS_FLASK_APP.route("/targets/<string:target_id>", methods=[HTTPMethod.PUT])
551+
@VWS_FLASK_APP.route(
552+
rule="/targets/<string:target_id>", methods=[HTTPMethod.PUT]
553+
)
550554
def update_target(target_id: str) -> Response:
551555
"""Update a target.
552556

src/mock_vws/_query_tools.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@ def get_query_match_response_text(
5454
content_length=len(request_body),
5555
)
5656

57-
max_num_results = fields.get("max_num_results", "1")
58-
include_target_data = fields.get("include_target_data", "top").lower()
57+
max_num_results = fields.get(key="max_num_results", default="1")
58+
include_target_data = fields.get(
59+
key="include_target_data",
60+
default="top",
61+
).lower()
5962

6063
image_part = files["image"]
6164
image_value = image_part.stream.read()

src/mock_vws/_query_validators/date_validators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def validate_date_in_range(*, request_headers: Mapping[str, str]) -> None:
8888
date_header = request_headers["Date"]
8989
gmt = ZoneInfo(key="GMT")
9090

91-
date = datetime.datetime.fromtimestamp(0, tz=gmt)
91+
date = datetime.datetime.fromtimestamp(timestamp=0, tz=gmt)
9292
for date_format in _accepted_date_formats():
9393
with contextlib.suppress(ValueError):
9494
date = datetime.datetime.strptime(

src/mock_vws/_query_validators/image_validators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def validate_image_field_given(
4444
boundary=boundary.encode(encoding="utf-8"),
4545
content_length=len(request_body),
4646
)
47-
if files.get("image") is not None:
47+
if files.get(key="image") is not None:
4848
return
4949

5050
_LOGGER.warning(msg="The image field is not given.")

src/mock_vws/_query_validators/include_target_data_validators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def validate_include_target_data(
4040
boundary=boundary.encode(encoding="utf-8"),
4141
content_length=len(request_body),
4242
)
43-
include_target_data = fields.get("include_target_data", "top")
43+
include_target_data = fields.get(key="include_target_data", default="top")
4444
allowed_included_target_data = {"top", "all", "none"}
4545
if include_target_data.lower() in allowed_included_target_data:
4646
return

0 commit comments

Comments
 (0)