From 44a361ea83488b83c7116dbc3dd3a4855181fed8 Mon Sep 17 00:00:00 2001 From: Joostlek Date: Thu, 18 Jan 2024 07:46:20 +0100 Subject: [PATCH 1/3] Add method for getting startup info --- src/aiomealie/__init__.py | 2 +- src/aiomealie/mealie.py | 10 ++-------- src/aiomealie/models.py | 1 - tests/syrupy.py | 4 +--- tests/test_mealie.py | 5 ++--- 5 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/aiomealie/__init__.py b/src/aiomealie/__init__.py index 8537ca8..e9fe841 100644 --- a/src/aiomealie/__init__.py +++ b/src/aiomealie/__init__.py @@ -6,5 +6,5 @@ __all__ = [ "MealieConnectionError", - "MealieClient" + "MealieClient", ] diff --git a/src/aiomealie/mealie.py b/src/aiomealie/mealie.py index cfd4624..27a5fd3 100644 --- a/src/aiomealie/mealie.py +++ b/src/aiomealie/mealie.py @@ -7,16 +7,10 @@ from typing import Self from aiohttp import ClientSession -import orjson from yarl import URL -from aiomealie.exceptions import ( - MealieConnectionError, - MealieError, -) -from aiomealie.models import ( - StartupInfo, -) +from aiomealie.exceptions import MealieConnectionError, MealieError +from aiomealie.models import StartupInfo VERSION = metadata.version(__package__) diff --git a/src/aiomealie/models.py b/src/aiomealie/models.py index 3574704..d459121 100644 --- a/src/aiomealie/models.py +++ b/src/aiomealie/models.py @@ -12,4 +12,3 @@ class StartupInfo(DataClassORJSONMixin): """StartupInfo model.""" is_first_login: bool = field(metadata=field_options(alias="isFirstLogin")) - diff --git a/tests/syrupy.py b/tests/syrupy.py index fedf611..3cd6332 100644 --- a/tests/syrupy.py +++ b/tests/syrupy.py @@ -63,6 +63,4 @@ class MealieSnapshotExtension(AmberSnapshotExtension): Need to be bumped when we change the MealieSnapshotSerializer. """ - serializer_class: type[ - AmberDataSerializer - ] = MealieSnapshotSerializer + serializer_class: type[AmberDataSerializer] = MealieSnapshotSerializer diff --git a/tests/test_mealie.py b/tests/test_mealie.py index fd6838c..74289e0 100644 --- a/tests/test_mealie.py +++ b/tests/test_mealie.py @@ -6,10 +6,9 @@ from aioresponses import CallbackResult, aioresponses import pytest -from syrupy import SnapshotAssertion - -from aiomealie.exceptions import MealieError, MealieConnectionError +from aiomealie.exceptions import MealieConnectionError, MealieError from aiomealie.mealie import MealieClient +from syrupy import SnapshotAssertion from tests import load_fixture from .const import MEALIE_URL From a3c545b85e9f83aac19bd1724c2535a88093934e Mon Sep 17 00:00:00 2001 From: Joostlek Date: Thu, 18 Jan 2024 07:52:25 +0100 Subject: [PATCH 2/3] Add method for getting startup info --- tests/const.py | 7 +++---- tests/test_mealie.py | 7 ++++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/const.py b/tests/const.py index 9fe5532..60da7fd 100644 --- a/tests/const.py +++ b/tests/const.py @@ -1,11 +1,10 @@ """Constants for tests.""" -from importlib import metadata -MEALIE_URL = "https://demo.mealie.io:443" +from aiomealie.mealie import VERSION -version = metadata.version("aiomealie") +MEALIE_URL = "https://demo.mealie.io:443" HEADERS = { - "User-Agent": f"AioMealie/{version}", + "User-Agent": f"AioMealie/{VERSION}", "Accept": "application/json, text/plain, */*", } diff --git a/tests/test_mealie.py b/tests/test_mealie.py index 74289e0..16e626c 100644 --- a/tests/test_mealie.py +++ b/tests/test_mealie.py @@ -24,8 +24,8 @@ async def test_putting_in_own_session( body=load_fixture("data.json"), ) async with aiohttp.ClientSession() as session: - analytics = MealieClient(session=session) - await analytics.get_analytics() + analytics = MealieClient(session=session, api_host="demo.mealie.io") + await analytics.get_startup_info() assert analytics.session is not None assert not analytics.session.closed await analytics.close() @@ -41,7 +41,7 @@ async def test_creating_own_session( status=200, body=load_fixture("startup_info.json"), ) - analytics = MealieClient("demo.mealie.io") + analytics = MealieClient(api_host="demo.mealie.io") await analytics.get_startup_info() assert analytics.session is not None assert not analytics.session.closed @@ -81,6 +81,7 @@ async def response_handler(_: str, **_kwargs: Any) -> CallbackResult: ) async with MealieClient( request_timeout=1, + api_host="demo.mealie.io", ) as mealie_client: with pytest.raises(MealieConnectionError): assert await mealie_client.get_startup_info() From 4e8d91ff67bcad43840bd82f9766a9278a6014a7 Mon Sep 17 00:00:00 2001 From: Joostlek Date: Thu, 18 Jan 2024 07:57:39 +0100 Subject: [PATCH 3/3] Add method for getting startup info --- src/aiomealie/mealie.py | 2 +- tests/__snapshots__/test_mealie.ambr | 6 ++++++ tests/test_mealie.py | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 tests/__snapshots__/test_mealie.ambr diff --git a/src/aiomealie/mealie.py b/src/aiomealie/mealie.py index 27a5fd3..11d4e9b 100644 --- a/src/aiomealie/mealie.py +++ b/src/aiomealie/mealie.py @@ -65,7 +65,7 @@ async def _request(self, uri: str) -> str: async def get_startup_info(self) -> StartupInfo: """Get startup info.""" - response = await self._request("/api/app/about/startup-info") + response = await self._request("api/app/about/startup-info") return StartupInfo.from_json(response) async def close(self) -> None: diff --git a/tests/__snapshots__/test_mealie.ambr b/tests/__snapshots__/test_mealie.ambr new file mode 100644 index 0000000..c921f62 --- /dev/null +++ b/tests/__snapshots__/test_mealie.ambr @@ -0,0 +1,6 @@ +# serializer version: 1 +# name: test_analytics + dict({ + 'is_first_login': True, + }) +# --- diff --git a/tests/test_mealie.py b/tests/test_mealie.py index 16e626c..35d2018 100644 --- a/tests/test_mealie.py +++ b/tests/test_mealie.py @@ -21,7 +21,7 @@ async def test_putting_in_own_session( responses.get( f"{MEALIE_URL}/api/app/about/startup-info", status=200, - body=load_fixture("data.json"), + body=load_fixture("startup_info.json"), ) async with aiohttp.ClientSession() as session: analytics = MealieClient(session=session, api_host="demo.mealie.io")