From 751808b237bf470acf4bc12da953433999287582 Mon Sep 17 00:00:00 2001 From: Stuart Reed Date: Wed, 21 Feb 2024 10:01:25 -0700 Subject: [PATCH] Address feedback on `test_get_request_headers` --- .../providers/test_async_http_provider.py | 21 +++++++------------ tests/core/providers/test_http_provider.py | 21 +++++++------------ 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/tests/core/providers/test_async_http_provider.py b/tests/core/providers/test_async_http_provider.py index 275a94781c..5e40fee87a 100644 --- a/tests/core/providers/test_async_http_provider.py +++ b/tests/core/providers/test_async_http_provider.py @@ -6,6 +6,7 @@ from web3 import ( AsyncWeb3, + __version__ as web3py_version, ) from web3._utils import ( request, @@ -108,18 +109,12 @@ async def test_async_user_provided_session() -> None: assert cached_session == session -def test_construct_user_agent(): - """ - The User-Agent used to include a stringiffied class name like: - - "web3.py/6.4.0/" - - This test does minimal checks to ensure it is more like: - - "web3.py/6.4.0/web3.providers.async_rpc.AsyncHTTPProvider" - - """ +def test_get_request_headers(): provider = AsyncHTTPProvider() headers = provider.get_request_headers() - assert "<" not in headers["User-Agent"] - assert " " not in headers["User-Agent"] + assert len(headers) == 2 + assert headers["Content-Type"] == "application/json" + assert ( + headers["User-Agent"] == f"web3.py/{web3py_version}/" + f"{AsyncHTTPProvider.__module__}.{AsyncHTTPProvider.__qualname__}" + ) diff --git a/tests/core/providers/test_http_provider.py b/tests/core/providers/test_http_provider.py index f6cd137097..eb539c2b6c 100644 --- a/tests/core/providers/test_http_provider.py +++ b/tests/core/providers/test_http_provider.py @@ -9,6 +9,7 @@ from web3 import ( Web3, + __version__ as web3py_version, ) from web3._utils import ( request, @@ -105,18 +106,12 @@ def test_user_provided_session(): assert adapter._pool_maxsize == 20 -def test_construct_user_agent(): - """ - The User-Agent used to include a stringiffied class name like: - - "web3.py/6.4.0/" - - This test does minimal checks to ensure it is more like: - - "web3.py/6.4.0/web3.providers.rpc.HTTPProvider" - - """ +def test_get_request_headers(): provider = HTTPProvider() headers = provider.get_request_headers() - assert "<" not in headers["User-Agent"] - assert " " not in headers["User-Agent"] + assert len(headers) == 2 + assert headers["Content-Type"] == "application/json" + assert ( + headers["User-Agent"] == f"web3.py/{web3py_version}/" + f"{HTTPProvider.__module__}.{HTTPProvider.__qualname__}" + )