Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add statistics #199

Merged
merged 3 commits into from
Jul 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/aiomealie/__init__.py
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
MealieAuthenticationError,
MealieValidationError,
MealieBadRequestError,
MealieNotFoundError,
)
from aiomealie.mealie import MealieClient
from aiomealie.models import (
@@ -28,6 +29,7 @@
Instruction,
Ingredient,
Tag,
Statistics,
)

__all__ = [
@@ -36,6 +38,7 @@
"MealieError",
"MealieAuthenticationError",
"MealieBadRequestError",
"MealieNotFoundError",
"MealieValidationError",
"MealieClient",
"StartupInfo",
@@ -51,6 +54,7 @@
"MealplanResponse",
"MealplanEntryType",
"ShoppingItem",
"Statistics",
"MutateShoppingItem",
"ShoppingItemsResponse",
"ShoppingList",
7 changes: 7 additions & 0 deletions src/aiomealie/mealie.py
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@
Theme,
UserInfo,
Recipe,
Statistics,
)

if TYPE_CHECKING:
@@ -263,6 +264,12 @@ async def delete_shopping_item(self, item_id: str) -> None:

await self._delete(f"api/groups/shopping/items/{item_id}")

async def get_statistics(self) -> Statistics:
"""Get statistics."""

response = await self._get("api/groups/statistics")
return Statistics.from_json(response)

async def close(self) -> None:
"""Close open client session."""
if self.session and self._close_session:
11 changes: 11 additions & 0 deletions src/aiomealie/models.py
Original file line number Diff line number Diff line change
@@ -268,3 +268,14 @@ class ShoppingItemsResponse(DataClassORJSONMixin):
"""ShoppingItemsResponse model."""

items: list[ShoppingItem]


@dataclass
class Statistics(DataClassORJSONMixin):
"""Statistics model."""

total_recipes: int = field(metadata=field_options(alias="totalRecipes"))
total_users: int = field(metadata=field_options(alias="totalUsers"))
total_categories: int = field(metadata=field_options(alias="totalCategories"))
total_tags: int = field(metadata=field_options(alias="totalTags"))
total_tools: int = field(metadata=field_options(alias="totalTools"))
9 changes: 9 additions & 0 deletions tests/__snapshots__/test_mealie.ambr
Original file line number Diff line number Diff line change
@@ -1465,6 +1465,15 @@
'is_first_login': True,
})
# ---
# name: test_statistics
dict({
'total_categories': 24,
'total_recipes': 765,
'total_tags': 454,
'total_tools': 11,
'total_users': 3,
})
# ---
# name: test_theme
dict({
'dark_accent': '#007A99',
7 changes: 7 additions & 0 deletions tests/fixtures/statistics.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"totalRecipes": 765,
"totalUsers": 3,
"totalCategories": 24,
"totalTags": 454,
"totalTools": 11
}
14 changes: 14 additions & 0 deletions tests/test_mealie.py
Original file line number Diff line number Diff line change
@@ -520,3 +520,17 @@ async def test_delete_shopping_item(
params=None,
json=None,
)


async def test_statistics(
responses: aioresponses,
mealie_client: MealieClient,
snapshot: SnapshotAssertion,
) -> None:
"""Test retrieving statistics."""
responses.get(
f"{MEALIE_URL}/api/groups/statistics",
status=200,
body=load_fixture("statistics.json"),
)
assert await mealie_client.get_statistics() == snapshot