Skip to content

Commit

Permalink
Remove support for user_agent, removing unneeded i/o (#1093)
Browse files Browse the repository at this point in the history
  • Loading branch information
frenck committed Jun 26, 2024
1 parent d001e34 commit 900d31f
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 46 deletions.
9 changes: 0 additions & 9 deletions src/adguardhome/adguardhome.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import asyncio
import json
import socket
from importlib import metadata
from typing import Any, Mapping, Self

import aiohttp
Expand Down Expand Up @@ -35,7 +34,6 @@ def __init__( # noqa: PLR0913
request_timeout: int = 10,
session: aiohttp.client.ClientSession | None = None,
tls: bool = False,
user_agent: str | None = None,
username: str | None = None,
verify_ssl: bool = True,
) -> None:
Expand All @@ -53,7 +51,6 @@ def __init__( # noqa: PLR0913
request_timeout: Max timeout to wait for a response from the API.
session: Optional, shared, aiohttp client session.
tls: True, when TLS/SSL should be used.
user_agent: Defaults to PythonAdGuardHome/<version>.
username: Username for HTTP auth, if enabled.
verify_ssl: Can be set to false, when TLS with self-signed cert is used.
Expand All @@ -69,11 +66,6 @@ def __init__( # noqa: PLR0913
self.tls = tls
self.username = username
self.verify_ssl = verify_ssl
self.user_agent = user_agent

if user_agent is None:
version = metadata.version(__package__)
self.user_agent = f"PythonAdGuardHome/{version}"

if self.base_path[-1] != "/":
self.base_path += "/"
Expand Down Expand Up @@ -130,7 +122,6 @@ async def request( # noqa: PLR0913
auth = aiohttp.BasicAuth(self.username, self.password)

headers = {
"User-Agent": self.user_agent,
"Accept": "application/json, text/plain, */*",
}

Expand Down
37 changes: 0 additions & 37 deletions tests/test_adguardhome.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,43 +122,6 @@ async def test_request_base_path(aresponses: ResponsesMockServer) -> None:
assert response == {"message": "OMG PUPPIES!"}


async def test_request_user_agent(aresponses: ResponsesMockServer) -> None:
"""Test AdGuard Home client sending correct user agent headers."""

# Handle to run asserts on request in
async def response_handler(request: aiohttp.ClientResponse) -> Response:
"""Response handler for this test."""
assert request.headers["User-Agent"] == "PythonAdGuardHome/0.0.0"
return aresponses.Response(text="TEDDYBEAR", status=200)

aresponses.add("example.com:3000", "/", "GET", response_handler)

async with aiohttp.ClientSession() as session:
adguard = AdGuardHome("example.com", base_path="/", session=session)
await adguard.request("/")


async def test_request_custom_user_agent(aresponses: ResponsesMockServer) -> None:
"""Test AdGuard Home client sending correct user agent headers."""

# Handle to run asserts on request in
async def response_handler(request: aiohttp.ClientResponse) -> Response:
"""Response handler for this test."""
assert request.headers["User-Agent"] == "LoremIpsum/1.0"
return aresponses.Response(text="TEDDYBEAR", status=200)

aresponses.add("example.com:3000", "/", "GET", response_handler)

async with aiohttp.ClientSession() as session:
adguard = AdGuardHome(
"example.com",
base_path="/",
session=session,
user_agent="LoremIpsum/1.0",
)
await adguard.request("/")


async def test_timeout(aresponses: ResponsesMockServer) -> None:
"""Test request timeout from AdGuard Home."""

Expand Down

0 comments on commit 900d31f

Please sign in to comment.