From 21e2ef5ecb4a93bb057e465a938118d9e785ae14 Mon Sep 17 00:00:00 2001 From: moson Date: Sun, 7 Apr 2024 08:58:19 +0200 Subject: [PATCH] fix(test): Fix "TestClient" TestClient changes were reverted with 0.37.2: https://github.com/encode/starlette/pull/2525 https://github.com/encode/starlette/releases/tag/0.37.2 Signed-off-by: moson --- aurweb/util.py | 4 ++-- test/test_accounts_routes.py | 4 ++-- test/test_rpc.py | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/aurweb/util.py b/aurweb/util.py index e5948a40..89efd852 100644 --- a/aurweb/util.py +++ b/aurweb/util.py @@ -213,6 +213,6 @@ def hash_query(query: Query): def get_client_ip(request: fastapi.Request) -> str: """ Returns the client's IP address for a Request. - Falls back to 'no-client' is request.client is None + Falls back to 'testclient' if request.client is None """ - return request.client.host if request.client else "no-client" + return request.client.host if request.client else "testclient" diff --git a/test/test_accounts_routes.py b/test/test_accounts_routes.py index ccf1bc99..3d966627 100644 --- a/test/test_accounts_routes.py +++ b/test/test_accounts_routes.py @@ -391,10 +391,10 @@ def test_post_register_error_invalid_captcha(client: TestClient): def test_post_register_error_ip_banned(client: TestClient): - # 'no-client' is our fallback value in case request.client is None + # 'testclient' is our fallback value in case request.client is None # which is the case for TestClient with db.begin(): - create(Ban, IPAddress="no-client", BanTS=datetime.utcnow()) + create(Ban, IPAddress="testclient", BanTS=datetime.utcnow()) with client as request: response = post_register(request) diff --git a/test/test_rpc.py b/test/test_rpc.py index 9c969b73..a2256700 100644 --- a/test/test_rpc.py +++ b/test/test_rpc.py @@ -310,10 +310,10 @@ def pipeline(): redis = redis_connection() pipeline = redis.pipeline() - # 'no-client' is our fallback value in case request.client is None + # 'testclient' 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.delete("ratelimit-ws:testclient") + pipeline.delete("ratelimit:testclient") 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:no-client") - pipeline.delete("ratelimit:no-client") + pipeline.delete("ratelimit-ws:testclient") + pipeline.delete("ratelimit:testclient") one, two = pipeline.execute() assert one and two