Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8e4897d

Browse files
committed
code review, use ANVIL_HOSTS everywhere
1 parent2d05029 commit8e4897d

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

‎python_anvil/api_resources/requests.py‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
frompython_anvil.httpimportHTTPClient
44

5+
fromconstantsimportVALID_HOSTS
6+
57

68
classAnvilRequest:
79
show_headers=False
@@ -166,18 +168,13 @@ def get_url(self):
166168
classFullyQualifiedRequest(BaseAnvilHttpRequest):
167169
"""A request class that validates URLs point to Anvil domains."""
168170

169-
VALID_HOSTS= [
170-
"https://app.useanvil.com",
171-
# Future Anvil specific URLs
172-
]
173-
174171
defget_url(self):
175172
return""# Not used since we expect full URLs
176173

177174
def_validate_url(self,url):
178-
ifnotany(url.startswith(host)forhostinself.VALID_HOSTS):
175+
ifnotany(url.startswith(host)forhostinVALID_HOSTS):
179176
raiseValueError(
180-
f"URL must start with one of:{', '.join(self.VALID_HOSTS)}"
177+
f"URL must start with one of:{', '.join(VALID_HOSTS)}"
181178
)
182179

183180
defget(self,url,params=None,**kwargs):

‎python_anvil/constants.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
"""Basic constants used in the library."""
22

33
GRAPHQL_ENDPOINT:str="https://graphql.useanvil.com"
4-
REST_ENDPOINT="https://app.useanvil.com/api/v1/"
4+
REST_ENDPOINT="https://app.useanvil.com/api/v1"
5+
ANVIL_HOST="https://app.useanvil.com"
6+
7+
VALID_HOSTS= [
8+
ANVIL_HOST,
9+
REST_ENDPOINT,
10+
GRAPHQL_ENDPOINT,
11+
]
512

613
RETRIES_LIMIT=5
714
REQUESTS_LIMIT= {

‎python_anvil/tests/test_api.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from ..api_resources.payloadimportFillPDFPayload
1414
from .importpayloads
15+
fromconstantsimportVALID_HOSTS
1516

1617

1718
DEV_KEY="MY-SECRET-KEY"
@@ -403,7 +404,7 @@ def describe_rest_request_absolute_url_behavior():
403404
[
404405
("some/relative/path",True),
405406
("https://external.example.com/full/path/file.pdf",True),
406-
("https://app.useanvil.com/api/v1/some-endpoint",False),
407+
*[(host+"/some-endpoint",False)forhostinVALID_HOSTS],
407408
],
408409
)
409410
@mock.patch("python_anvil.api_resources.requests.AnvilRequest._request")
@@ -431,7 +432,7 @@ def test_get_behavior(mock_request, anvil, url, should_raise):
431432
[
432433
("some/relative/path",True),
433434
("https://external.example.com/full/path/file.pdf",True),
434-
("https://app.useanvil.com/api/v1/some-endpoint",False),
435+
*[(host+"/some-endpoint",False)forhostinVALID_HOSTS],
435436
],
436437
)
437438
@mock.patch("python_anvil.api_resources.requests.AnvilRequest._request")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp