From f1ee529aea258d914204976d2cc6c0c97c5cce66 Mon Sep 17 00:00:00 2001 From: Lennart Weller Date: Fri, 13 Sep 2024 19:09:11 +0200 Subject: [PATCH] feat: add debug logging to proxy requests (#22) * feat: add debug logging to proxy requests * fix: tox --- aiocloudweather/proxy.py | 5 +++++ pytest.ini | 2 ++ tests/test_server.py | 1 - 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 pytest.ini diff --git a/aiocloudweather/proxy.py b/aiocloudweather/proxy.py index 8cf29d5..625de6d 100644 --- a/aiocloudweather/proxy.py +++ b/aiocloudweather/proxy.py @@ -1,10 +1,13 @@ """Proxy for forwarding data to the CloudWeather APIs.""" from enum import Enum +import logging from aiohttp import web, TCPConnector, ClientSession from urllib.parse import quote from aiohttp.resolver import AsyncResolver +_LOGGER = logging.getLogger(__name__) + class DataSink(Enum): """Data sinks for the CloudWeather API.""" @@ -30,12 +33,14 @@ async def forward_wunderground(self, request: web.Request) -> web.Response: """Forward Wunderground data to their API.""" query_string = quote(request.query_string).replace("%20", "+") url = f"https://rtupdate.wunderground.com/weatherstation/updateweatherstation.php?{query_string}" + _LOGGER.debug("Forwarding Wunderground data: %s", url) return await self.session.get(url) async def forward_weathercloud(self, request: web.Request) -> web.Response: """Forward WeatherCloud data to their API.""" new_path = request.path[request.path.index("/v01/set") :] url = f"https://api.weathercloud.net{new_path}" + _LOGGER.debug("Forwarding WeatherCloud data: %s", url) return await self.session.get(url) async def forward(self, sink: DataSink, request: web.Request) -> web.Response: diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..6a7d170 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +asyncio_default_fixture_loop_scope = function \ No newline at end of file diff --git a/tests/test_server.py b/tests/test_server.py index 9381554..b8f448c 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -1,4 +1,3 @@ -import asyncio import pytest from aiohttp import web from aiocloudweather.server import CloudWeatherListener