From e189d1f532cfd3f65280468008bad6dc26f1b5a0 Mon Sep 17 00:00:00 2001 From: Georg Krause <mail@georg-krause.net> Date: Mon, 26 Sep 2022 15:08:53 +0200 Subject: [PATCH] Fix all favorite test case --- .../favorites_tracks_all_retrieve.py | 24 +++--- funkwhale_api_client/models/__init__.py | 2 + funkwhale_api_client/models/all_favorite.py | 76 +++++++++++++++++++ .../models/simple_favorite.py | 64 ++++++++++++++++ tests/unit/test_model_all_favorite.py | 8 ++ tests/unit/test_model_user_track_favorite.py | 8 -- 6 files changed, 162 insertions(+), 20 deletions(-) create mode 100644 funkwhale_api_client/models/all_favorite.py create mode 100644 funkwhale_api_client/models/simple_favorite.py create mode 100644 tests/unit/test_model_all_favorite.py delete mode 100644 tests/unit/test_model_user_track_favorite.py diff --git a/funkwhale_api_client/api/favorites/favorites_tracks_all_retrieve.py b/funkwhale_api_client/api/favorites/favorites_tracks_all_retrieve.py index 10ff72b..f6944dd 100644 --- a/funkwhale_api_client/api/favorites/favorites_tracks_all_retrieve.py +++ b/funkwhale_api_client/api/favorites/favorites_tracks_all_retrieve.py @@ -3,7 +3,7 @@ from typing import Any, Dict, Optional import httpx from ...client import AuthenticatedClient -from ...models.user_track_favorite import UserTrackFavorite +from ...models.all_favorite import AllFavorite from ...types import Response @@ -25,15 +25,15 @@ def _get_kwargs( } -def _parse_response(*, response: httpx.Response) -> Optional[UserTrackFavorite]: +def _parse_response(*, response: httpx.Response) -> Optional[AllFavorite]: if response.status_code == 200: - response_200 = UserTrackFavorite.from_dict(response.json()) + response_200 = AllFavorite.from_dict(response.json()) return response_200 return None -def _build_response(*, response: httpx.Response) -> Response[UserTrackFavorite]: +def _build_response(*, response: httpx.Response) -> Response[AllFavorite]: return Response( status_code=response.status_code, content=response.content, @@ -45,13 +45,13 @@ def _build_response(*, response: httpx.Response) -> Response[UserTrackFavorite]: def sync_detailed( *, client: AuthenticatedClient, -) -> Response[UserTrackFavorite]: +) -> Response[AllFavorite]: """Return all the favorites of the current user, with only limited data to have a performant endpoint and avoid lots of queries just to display favorites status in the UI Returns: - Response[UserTrackFavorite] + Response[AllFavorite] """ kwargs = _get_kwargs( @@ -69,13 +69,13 @@ def sync_detailed( def sync( *, client: AuthenticatedClient, -) -> Optional[UserTrackFavorite]: +) -> Optional[AllFavorite]: """Return all the favorites of the current user, with only limited data to have a performant endpoint and avoid lots of queries just to display favorites status in the UI Returns: - Response[UserTrackFavorite] + Response[AllFavorite] """ return sync_detailed( @@ -86,13 +86,13 @@ def sync( async def asyncio_detailed( *, client: AuthenticatedClient, -) -> Response[UserTrackFavorite]: +) -> Response[AllFavorite]: """Return all the favorites of the current user, with only limited data to have a performant endpoint and avoid lots of queries just to display favorites status in the UI Returns: - Response[UserTrackFavorite] + Response[AllFavorite] """ kwargs = _get_kwargs( @@ -108,13 +108,13 @@ async def asyncio_detailed( async def asyncio( *, client: AuthenticatedClient, -) -> Optional[UserTrackFavorite]: +) -> Optional[AllFavorite]: """Return all the favorites of the current user, with only limited data to have a performant endpoint and avoid lots of queries just to display favorites status in the UI Returns: - Response[UserTrackFavorite] + Response[AllFavorite] """ return ( diff --git a/funkwhale_api_client/models/__init__.py b/funkwhale_api_client/models/__init__.py index 3be9453..5e70da9 100644 --- a/funkwhale_api_client/models/__init__.py +++ b/funkwhale_api_client/models/__init__.py @@ -12,6 +12,7 @@ from .album_create import AlbumCreate from .album_create_request import AlbumCreateRequest from .album_request import AlbumRequest from .albums_list_ordering_item import AlbumsListOrderingItem +from .all_favorite import AllFavorite from .allow_list_stat import AllowListStat from .api_actor import APIActor from .api_actor_request import APIActorRequest @@ -253,6 +254,7 @@ from .scopes import Scopes from .services import Services from .simple_artist import SimpleArtist from .simple_artist_request import SimpleArtistRequest +from .simple_favorite import SimpleFavorite from .software import Software from .subscription import Subscription from .tag import Tag diff --git a/funkwhale_api_client/models/all_favorite.py b/funkwhale_api_client/models/all_favorite.py new file mode 100644 index 0000000..f2ada45 --- /dev/null +++ b/funkwhale_api_client/models/all_favorite.py @@ -0,0 +1,76 @@ +from typing import Any, Dict, List, Type, TypeVar + +import attr + +from ..models.simple_favorite import SimpleFavorite + +T = TypeVar("T", bound="AllFavorite") + + +@attr.s(auto_attribs=True) +class AllFavorite: + """ + Attributes: + results (List[SimpleFavorite]): + count (int): + """ + + results: List[SimpleFavorite] + count: int + additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) + + def to_dict(self) -> Dict[str, Any]: + results = [] + for results_item_data in self.results: + results_item = results_item_data.to_dict() + + results.append(results_item) + + count = self.count + + field_dict: Dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "results": results, + "count": count, + } + ) + + return field_dict + + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + d = src_dict.copy() + results = [] + _results = d.pop("results") + for results_item_data in _results: + results_item = SimpleFavorite.from_dict(results_item_data) + + results.append(results_item) + + count = d.pop("count") + + all_favorite = cls( + results=results, + count=count, + ) + + all_favorite.additional_properties = d + return all_favorite + + @property + def additional_keys(self) -> List[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/funkwhale_api_client/models/simple_favorite.py b/funkwhale_api_client/models/simple_favorite.py new file mode 100644 index 0000000..c93f541 --- /dev/null +++ b/funkwhale_api_client/models/simple_favorite.py @@ -0,0 +1,64 @@ +from typing import Any, Dict, List, Type, TypeVar + +import attr + +T = TypeVar("T", bound="SimpleFavorite") + + +@attr.s(auto_attribs=True) +class SimpleFavorite: + """ + Attributes: + id (int): + track (int): + """ + + id: int + track: int + additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) + + def to_dict(self) -> Dict[str, Any]: + id = self.id + track = self.track + + field_dict: Dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "id": id, + "track": track, + } + ) + + return field_dict + + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + d = src_dict.copy() + id = d.pop("id") + + track = d.pop("track") + + simple_favorite = cls( + id=id, + track=track, + ) + + simple_favorite.additional_properties = d + return simple_favorite + + @property + def additional_keys(self) -> List[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/tests/unit/test_model_all_favorite.py b/tests/unit/test_model_all_favorite.py new file mode 100644 index 0000000..43965c8 --- /dev/null +++ b/tests/unit/test_model_all_favorite.py @@ -0,0 +1,8 @@ +from funkwhale_api_client.models.all_favorite import AllFavorite + + +def test_AllFavorite(load_data): + response = load_data("favorites_all") + favorites: AllFavorite = AllFavorite.from_dict(response) + + assert isinstance(favorites, AllFavorite) diff --git a/tests/unit/test_model_user_track_favorite.py b/tests/unit/test_model_user_track_favorite.py deleted file mode 100644 index 51d0be9..0000000 --- a/tests/unit/test_model_user_track_favorite.py +++ /dev/null @@ -1,8 +0,0 @@ -from funkwhale_api_client.models.user_track_favorite import UserTrackFavorite - - -def test_UserTrackFavorite(load_data): - response = load_data("favorites_all") - favorites: UserTrackFavorite = UserTrackFavorite.from_dict(response) - - assert isinstance(favorites, UserTrackFavorite) -- GitLab