mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
fix(test): Fixes for "TestClient" changes
Seems that client is optional according to the ASGI spec. https://asgi.readthedocs.io/en/latest/specs/www.html With Starlette 0.35 the TestClient connection scope is None for "client". https://github.com/encode/starlette/pull/2377 Signed-off-by: moson <moson@archlinux.org>
This commit is contained in:
parent
22e1577324
commit
2fcd793a58
8 changed files with 29 additions and 16 deletions
|
@ -391,9 +391,10 @@ def test_post_register_error_invalid_captcha(client: TestClient):
|
|||
|
||||
|
||||
def test_post_register_error_ip_banned(client: TestClient):
|
||||
# 'testclient' is used as request.client.host via FastAPI TestClient.
|
||||
# 'no-client' is our fallback value in case request.client is None
|
||||
# which is the case for TestClient
|
||||
with db.begin():
|
||||
create(Ban, IPAddress="testclient", BanTS=datetime.utcnow())
|
||||
create(Ban, IPAddress="no-client", BanTS=datetime.utcnow())
|
||||
|
||||
with client as request:
|
||||
response = post_register(request)
|
||||
|
|
|
@ -310,10 +310,10 @@ def pipeline():
|
|||
redis = redis_connection()
|
||||
pipeline = redis.pipeline()
|
||||
|
||||
# The 'testclient' host is used when requesting the app
|
||||
# via fastapi.testclient.TestClient.
|
||||
pipeline.delete("ratelimit-ws:testclient")
|
||||
pipeline.delete("ratelimit:testclient")
|
||||
# 'no-client' is our fallback value in case request.client is None
|
||||
# which is the case for TestClient
|
||||
pipeline.delete("ratelimit-ws:no-client")
|
||||
pipeline.delete("ratelimit:no-client")
|
||||
pipeline.execute()
|
||||
|
||||
yield pipeline
|
||||
|
@ -760,8 +760,8 @@ def test_rpc_ratelimit(
|
|||
assert response.status_code == int(HTTPStatus.TOO_MANY_REQUESTS)
|
||||
|
||||
# Delete the cached records.
|
||||
pipeline.delete("ratelimit-ws:testclient")
|
||||
pipeline.delete("ratelimit:testclient")
|
||||
pipeline.delete("ratelimit-ws:no-client")
|
||||
pipeline.delete("ratelimit:no-client")
|
||||
one, two = pipeline.execute()
|
||||
assert one and two
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue