Skip to content

Commit a644a2a

Browse files
committed
Check and fix N818 ruff rule
1 parent 9baa27a commit a644a2a

27 files changed

+239
-224
lines changed

src/mock_vws/_flask_server/vws.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
from mock_vws._mock_common import json_dump
2323
from mock_vws._services_validators import run_services_validators
2424
from mock_vws._services_validators.exceptions import (
25-
Fail,
26-
TargetStatusNotSuccess,
27-
TargetStatusProcessing,
25+
FailError,
26+
TargetStatusNotSuccessError,
27+
TargetStatusProcessingError,
2828
ValidatorError,
2929
)
3030
from mock_vws.database import VuforiaDatabase
@@ -299,7 +299,7 @@ def delete_target(target_id: str) -> Response:
299299
)
300300

301301
if target.status == TargetStatuses.PROCESSING.value:
302-
raise TargetStatusProcessing
302+
raise TargetStatusProcessingError
303303

304304
databases_url = f"{settings.target_manager_base_url}/databases"
305305
requests.delete(
@@ -563,7 +563,7 @@ def update_target(target_id: str) -> Response:
563563
)
564564

565565
if target.status != TargetStatuses.SUCCESS.value:
566-
raise TargetStatusNotSuccess
566+
raise TargetStatusNotSuccessError
567567

568568
update_values: dict[str, str | int | float | bool | None] = {}
569569
if "width" in request_json:
@@ -578,7 +578,7 @@ def update_target(target_id: str) -> Response:
578578
"This is not allowed. "
579579
),
580580
)
581-
raise Fail(status_code=HTTPStatus.BAD_REQUEST)
581+
raise FailError(status_code=HTTPStatus.BAD_REQUEST)
582582
update_values["active_flag"] = active_flag
583583

584584
if "application_metadata" in request_json:
@@ -590,7 +590,7 @@ def update_target(target_id: str) -> Response:
590590
"This is not allowed."
591591
),
592592
)
593-
raise Fail(status_code=HTTPStatus.BAD_REQUEST)
593+
raise FailError(status_code=HTTPStatus.BAD_REQUEST)
594594
update_values["application_metadata"] = application_metadata
595595

596596
if "name" in request_json:

src/mock_vws/_query_validators/accept_header_validators.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import logging
66

7-
from mock_vws._query_validators.exceptions import InvalidAcceptHeader
7+
from mock_vws._query_validators.exceptions import InvalidAcceptHeaderError
88

99
_LOGGER = logging.getLogger(__name__)
1010

@@ -17,7 +17,7 @@ def validate_accept_header(request_headers: dict[str, str]) -> None:
1717
request_headers: The headers sent with the request.
1818
1919
Raises:
20-
InvalidAcceptHeader: The Accept header is given and is not
20+
InvalidAcceptHeaderError: The Accept header is given and is not
2121
'application/json' or '*/*'.
2222
"""
2323
accept = request_headers.get("Accept")
@@ -27,4 +27,4 @@ def validate_accept_header(request_headers: dict[str, str]) -> None:
2727
_LOGGER.warning(
2828
msg="The Accept header is not 'application/json' or '*/*'.",
2929
)
30-
raise InvalidAcceptHeader
30+
raise InvalidAcceptHeaderError

src/mock_vws/_query_validators/auth_validators.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
from mock_vws._database_matchers import get_database_matching_client_keys
1111
from mock_vws._query_validators.exceptions import (
12-
AuthenticationFailure,
13-
AuthHeaderMissing,
14-
MalformedAuthHeader,
12+
AuthenticationFailureError,
13+
AuthHeaderMissingError,
14+
MalformedAuthHeaderError,
1515
)
1616

1717
_LOGGER = logging.getLogger(__name__)
@@ -28,13 +28,13 @@ def validate_auth_header_exists(request_headers: dict[str, str]) -> None:
2828
request_headers: The headers sent with the request.
2929
3030
Raises:
31-
AuthHeaderMissing: There is no "Authorization" header.
31+
AuthHeaderMissingError: There is no "Authorization" header.
3232
"""
3333
if "Authorization" in request_headers:
3434
return
3535

3636
_LOGGER.warning(msg="There is no authorization header.")
37-
raise AuthHeaderMissing
37+
raise AuthHeaderMissingError
3838

3939

4040
def validate_auth_header_number_of_parts(
@@ -47,7 +47,8 @@ def validate_auth_header_number_of_parts(
4747
request_headers: The headers sent with the request.
4848
4949
Raises:
50-
MalformedAuthHeader: The "Authorization" header is not as expected.
50+
MalformedAuthHeaderError: The "Authorization" header is not as
51+
expected.
5152
"""
5253
header = request_headers["Authorization"]
5354
parts = header.split(" ")
@@ -56,7 +57,7 @@ def validate_auth_header_number_of_parts(
5657
return
5758

5859
_LOGGER.warning(msg="The authorization header is malformed.")
59-
raise MalformedAuthHeader
60+
raise MalformedAuthHeaderError
6061

6162

6263
def validate_client_key_exists(
@@ -71,7 +72,7 @@ def validate_client_key_exists(
7172
databases: All Vuforia databases.
7273
7374
Raises:
74-
AuthenticationFailure: The client key is unknown.
75+
AuthenticationFailureError: The client key is unknown.
7576
"""
7677
header = request_headers["Authorization"]
7778
first_part, _ = header.split(":")
@@ -81,7 +82,7 @@ def validate_client_key_exists(
8182
return
8283

8384
_LOGGER.warning(msg="The client key is unknown.")
84-
raise AuthenticationFailure
85+
raise AuthenticationFailureError
8586

8687

8788
def validate_auth_header_has_signature(
@@ -94,14 +95,14 @@ def validate_auth_header_has_signature(
9495
request_headers: The headers sent with the request.
9596
9697
Raises:
97-
MalformedAuthHeader: The "Authorization" header has no signature.
98+
MalformedAuthHeaderError: The "Authorization" header has no signature.
9899
"""
99100
header = request_headers["Authorization"]
100101
if header.count(":") == 1 and header.split(":")[1]:
101102
return
102103

103104
_LOGGER.warning(msg="The authorization header has no signature.")
104-
raise MalformedAuthHeader
105+
raise MalformedAuthHeaderError
105106

106107

107108
def validate_authorization(
@@ -122,7 +123,8 @@ def validate_authorization(
122123
databases: All Vuforia databases.
123124
124125
Raises:
125-
AuthenticationFailure: The "Authorization" header is not as expected.
126+
AuthenticationFailureError: The "Authorization" header is not as
127+
expected.
126128
"""
127129
try:
128130
get_database_matching_client_keys(
@@ -136,4 +138,4 @@ def validate_authorization(
136138
_LOGGER.warning(
137139
msg="The authorization header does not match any databases.",
138140
)
139-
raise AuthenticationFailure from ValueError
141+
raise AuthenticationFailureError from ValueError

src/mock_vws/_query_validators/content_length_validators.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
import logging
66

77
from mock_vws._query_validators.exceptions import (
8-
AuthenticationFailureGoodFormatting,
9-
ContentLengthHeaderNotInt,
10-
ContentLengthHeaderTooLarge,
8+
AuthenticationFailureGoodFormattingError,
9+
ContentLengthHeaderNotIntError,
10+
ContentLengthHeaderTooLargeError,
1111
)
1212

1313
_LOGGER = logging.getLogger(__name__)
@@ -23,15 +23,16 @@ def validate_content_length_header_is_int(
2323
request_headers: The headers sent with the request.
2424
2525
Raises:
26-
ContentLengthHeaderNotInt: ``Content-Length`` header is not an integer.
26+
ContentLengthHeaderNotIntError: ``Content-Length`` header is not an
27+
integer.
2728
"""
2829
given_content_length = request_headers["Content-Length"]
2930

3031
try:
3132
int(given_content_length)
3233
except ValueError as exc:
3334
_LOGGER.warning(msg="The Content-Length header is not an integer.")
34-
raise ContentLengthHeaderNotInt from exc
35+
raise ContentLengthHeaderNotIntError from exc
3536

3637

3738
def validate_content_length_header_not_too_large(
@@ -46,8 +47,8 @@ def validate_content_length_header_not_too_large(
4647
request_body: The body of the request.
4748
4849
Raises:
49-
ContentLengthHeaderTooLarge: The given content length header says that
50-
the content length is greater than the body length.
50+
ContentLengthHeaderTooLargeError: The given content length header says
51+
that the content length is greater than the body length.
5152
"""
5253
given_content_length = request_headers["Content-Length"]
5354

@@ -56,7 +57,7 @@ def validate_content_length_header_not_too_large(
5657
# We skip coverage here as running a test to cover this is very slow.
5758
if given_content_length_value > body_length: # pragma: no cover
5859
_LOGGER.warning(msg="The Content-Length header is too large.")
59-
raise ContentLengthHeaderTooLarge
60+
raise ContentLengthHeaderTooLargeError
6061

6162

6263
def validate_content_length_header_not_too_small(
@@ -71,8 +72,9 @@ def validate_content_length_header_not_too_small(
7172
request_body: The body of the request.
7273
7374
Raises:
74-
AuthenticationFailureGoodFormatting: The given content length header
75-
says that the content length is smaller than the body length.
75+
AuthenticationFailureGoodFormattingError: The given content length
76+
header says that the content length is smaller than the body
77+
length.
7678
"""
7779
given_content_length = request_headers["Content-Length"]
7880

@@ -81,4 +83,4 @@ def validate_content_length_header_not_too_small(
8183

8284
if given_content_length_value < body_length:
8385
_LOGGER.warning(msg="The Content-Length header is too small.")
84-
raise AuthenticationFailureGoodFormatting
86+
raise AuthenticationFailureGoodFormattingError

src/mock_vws/_query_validators/content_type_validators.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
from email.message import EmailMessage
77

88
from mock_vws._query_validators.exceptions import (
9-
ImageNotGiven,
10-
NoBoundaryFound,
11-
NoContentType,
12-
UnsupportedMediaType,
9+
ImageNotGivenError,
10+
NoBoundaryFoundError,
11+
NoContentTypeError,
12+
UnsupportedMediaTypeError,
1313
)
1414

1515
_LOGGER = logging.getLogger(__name__)
@@ -27,17 +27,18 @@ def validate_content_type_header(
2727
request_body: The body of the request.
2828
2929
Raises:
30-
UnsupportedMediaType: The ``Content-Type`` header main part is not
30+
UnsupportedMediaTypeError: The ``Content-Type`` header main part is not
3131
'multipart/form-data'.
32-
NoBoundaryFound: The ``Content-Type`` header does not contain a
32+
NoBoundaryFoundError: The ``Content-Type`` header does not contain a
3333
boundary.
34-
ImageNotGiven: The boundary is not in the request body.
35-
NoContentType: The content type header is either empty or not given.
34+
ImageNotGivenError: The boundary is not in the request body.
35+
NoContentTypeError: The content type header is either empty or not
36+
given.
3637
"""
3738
content_type_header = request_headers.get("Content-Type", "")
3839
if not content_type_header:
3940
_LOGGER.warning(msg="The content type header is empty.")
40-
raise NoContentType
41+
raise NoContentTypeError
4142

4243
email_message = EmailMessage()
4344
email_message["Content-Type"] = request_headers["Content-Type"]
@@ -47,15 +48,15 @@ def validate_content_type_header(
4748
"The content type header main part is not multipart/form-data."
4849
),
4950
)
50-
raise UnsupportedMediaType
51+
raise UnsupportedMediaTypeError
5152

5253
boundary = email_message.get_boundary()
5354
if boundary is None:
5455
_LOGGER.warning(
5556
msg="The content type header does not contain a boundary.",
5657
)
57-
raise NoBoundaryFound
58+
raise NoBoundaryFoundError
5859

5960
if boundary.encode() not in request_body:
6061
_LOGGER.warning(msg="The boundary is not in the request body.")
61-
raise ImageNotGiven
62+
raise ImageNotGivenError

src/mock_vws/_query_validators/date_validators.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
from zoneinfo import ZoneInfo
99

1010
from mock_vws._query_validators.exceptions import (
11-
DateFormatNotValid,
12-
DateHeaderNotGiven,
13-
RequestTimeTooSkewed,
11+
DateFormatNotValidError,
12+
DateHeaderNotGivenError,
13+
RequestTimeTooSkewedError,
1414
)
1515

1616
_LOGGER = logging.getLogger(__name__)
@@ -24,13 +24,13 @@ def validate_date_header_given(request_headers: dict[str, str]) -> None:
2424
request_headers: The headers sent with the request.
2525
2626
Raises:
27-
DateHeaderNotGiven: The date is not given.
27+
DateHeaderNotGivenError: The date is not given.
2828
"""
2929
if "Date" in request_headers:
3030
return
3131

3232
_LOGGER.warning(msg="The date header is not given.")
33-
raise DateHeaderNotGiven
33+
raise DateHeaderNotGivenError
3434

3535

3636
def _accepted_date_formats() -> set[str]:
@@ -60,7 +60,7 @@ def validate_date_format(request_headers: dict[str, str]) -> None:
6060
request_headers: The headers sent with the request.
6161
6262
Raises:
63-
DateFormatNotValid: The date is in the wrong format.
63+
DateFormatNotValidError: The date is in the wrong format.
6464
"""
6565
date_header = request_headers["Date"]
6666

@@ -70,7 +70,7 @@ def validate_date_format(request_headers: dict[str, str]) -> None:
7070
return
7171

7272
_LOGGER.warning(msg="The date header is in the wrong format.")
73-
raise DateFormatNotValid
73+
raise DateFormatNotValidError
7474

7575

7676
def validate_date_in_range(request_headers: dict[str, str]) -> None:
@@ -81,7 +81,7 @@ def validate_date_in_range(request_headers: dict[str, str]) -> None:
8181
request_headers: The headers sent with the request.
8282
8383
Raises:
84-
RequestTimeTooSkewed: The date is out of range.
84+
RequestTimeTooSkewedError: The date is out of range.
8585
"""
8686
date_header = request_headers["Date"]
8787

@@ -105,4 +105,4 @@ def validate_date_in_range(request_headers: dict[str, str]) -> None:
105105
return
106106

107107
_LOGGER.warning(msg="The date header is out of range.")
108-
raise RequestTimeTooSkewed
108+
raise RequestTimeTooSkewedError

0 commit comments

Comments
 (0)