Skip to content

Commit

Permalink
Address feedback on test_get_request_headers
Browse files Browse the repository at this point in the history
  • Loading branch information
reedsa committed Feb 21, 2024
1 parent b593f6e commit 751808b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 26 deletions.
21 changes: 8 additions & 13 deletions tests/core/providers/test_async_http_provider.py
Expand Up @@ -6,6 +6,7 @@

from web3 import (
AsyncWeb3,
__version__ as web3py_version,
)
from web3._utils import (
request,
Expand Down Expand Up @@ -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/<class 'web3.providers.async_rpc.AsyncHTTPProvider'>"
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__}"
)
21 changes: 8 additions & 13 deletions tests/core/providers/test_http_provider.py
Expand Up @@ -9,6 +9,7 @@

from web3 import (
Web3,
__version__ as web3py_version,
)
from web3._utils import (
request,
Expand Down Expand Up @@ -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/<class 'web3.providers.rpc.HTTPProvider'>"
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__}"
)

0 comments on commit 751808b

Please sign in to comment.