diff --git a/src/peertube/api/plugins/add_plugin.py b/src/peertube/api/plugins/add_plugin.py index 07fbd6a..652ca49 100644 --- a/src/peertube/api/plugins/add_plugin.py +++ b/src/peertube/api/plugins/add_plugin.py @@ -19,10 +19,7 @@ def _get_kwargs( "method": "post", "url": "/api/v1/plugins/install", } - if isinstance(body, AddPluginBodyType0): - _kwargs["json"] = body.to_dict() - else: - _kwargs["json"] = body.to_dict() + _kwargs["json"] = body.to_dict() headers["Content-Type"] = "application/json" diff --git a/src/peertube/api/plugins/update_plugin.py b/src/peertube/api/plugins/update_plugin.py index e7a88b0..3190297 100644 --- a/src/peertube/api/plugins/update_plugin.py +++ b/src/peertube/api/plugins/update_plugin.py @@ -19,10 +19,7 @@ def _get_kwargs( "method": "post", "url": "/api/v1/plugins/update", } - if isinstance(body, UpdatePluginBodyType0): - _kwargs["json"] = body.to_dict() - else: - _kwargs["json"] = body.to_dict() + _kwargs["json"] = body.to_dict() headers["Content-Type"] = "application/json" diff --git a/src/peertube/api/shared_utils.py b/src/peertube/api/shared_utils.py index 680c5aa..9612f19 100644 --- a/src/peertube/api/shared_utils.py +++ b/src/peertube/api/shared_utils.py @@ -26,7 +26,14 @@ def parse_response( *, client: AuthenticatedClient | Client, response: httpx.Response ) -> Any | None: """Parse response, raising error if configured.""" - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) + if response.status_code >= 400: + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None else: - return None + # For successful responses, try to parse JSON + try: + return response.json() + except ValueError: + return None diff --git a/src/peertube/api/video_feeds/get_syndicated_comments.py b/src/peertube/api/video_feeds/get_syndicated_comments.py index d0f9718..0a56bcc 100644 --- a/src/peertube/api/video_feeds/get_syndicated_comments.py +++ b/src/peertube/api/video_feeds/get_syndicated_comments.py @@ -3,6 +3,7 @@ from typing import Any, cast import httpx +from pydantic import ConfigDict, validate_call from peertube import errors from peertube.client import AuthenticatedClient, Client @@ -84,6 +85,7 @@ def _build_response( ) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync_detailed( format_: GetSyndicatedCommentsFormat, *, @@ -127,6 +129,7 @@ def sync_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync( format_: GetSyndicatedCommentsFormat, *, @@ -167,6 +170,7 @@ def sync( ).parsed +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio_detailed( format_: GetSyndicatedCommentsFormat, *, @@ -210,6 +214,7 @@ async def asyncio_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio( format_: GetSyndicatedCommentsFormat, *, diff --git a/src/peertube/api/video_feeds/get_syndicated_subscription_videos.py b/src/peertube/api/video_feeds/get_syndicated_subscription_videos.py index d7d46bd..90d1c6c 100644 --- a/src/peertube/api/video_feeds/get_syndicated_subscription_videos.py +++ b/src/peertube/api/video_feeds/get_syndicated_subscription_videos.py @@ -3,6 +3,7 @@ from typing import Any, cast import httpx +from pydantic import ConfigDict, validate_call from peertube import errors from peertube.client import AuthenticatedClient, Client @@ -106,6 +107,7 @@ def _build_response( ) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync_detailed( format_: GetSyndicatedSubscriptionVideosFormat, *, @@ -162,6 +164,7 @@ def sync_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync( format_: GetSyndicatedSubscriptionVideosFormat, *, @@ -215,6 +218,7 @@ def sync( ).parsed +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio_detailed( format_: GetSyndicatedSubscriptionVideosFormat, *, @@ -271,6 +275,7 @@ async def asyncio_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio( format_: GetSyndicatedSubscriptionVideosFormat, *, diff --git a/src/peertube/api/video_feeds/get_syndicated_videos.py b/src/peertube/api/video_feeds/get_syndicated_videos.py index b48183c..b6c5732 100644 --- a/src/peertube/api/video_feeds/get_syndicated_videos.py +++ b/src/peertube/api/video_feeds/get_syndicated_videos.py @@ -3,6 +3,7 @@ from typing import Any, cast import httpx +from pydantic import ConfigDict, validate_call from peertube import errors from peertube.client import AuthenticatedClient, Client @@ -109,6 +110,7 @@ def _build_response( ) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync_detailed( format_: GetSyndicatedVideosFormat, *, @@ -171,6 +173,7 @@ def sync_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync( format_: GetSyndicatedVideosFormat, *, @@ -230,6 +233,7 @@ def sync( ).parsed +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio_detailed( format_: GetSyndicatedVideosFormat, *, @@ -292,6 +296,7 @@ async def asyncio_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio( format_: GetSyndicatedVideosFormat, *, diff --git a/src/peertube/api/video_feeds/get_videos_podcast_feed.py b/src/peertube/api/video_feeds/get_videos_podcast_feed.py index 4e96ed9..30f7a27 100644 --- a/src/peertube/api/video_feeds/get_videos_podcast_feed.py +++ b/src/peertube/api/video_feeds/get_videos_podcast_feed.py @@ -1,6 +1,7 @@ from typing import Any import httpx +from pydantic import ConfigDict, validate_call from peertube import errors from peertube.api.shared_utils import build_response @@ -43,6 +44,7 @@ def _build_response( return build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync_detailed( *, client: AuthenticatedClient | Client, video_channel_id: str ) -> Response[Any]: @@ -67,6 +69,7 @@ def sync_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync(*, client: AuthenticatedClient | Client, video_channel_id: str) -> Any | None: """Videos podcast feed @@ -82,6 +85,7 @@ def sync(*, client: AuthenticatedClient | Client, video_channel_id: str) -> Any return sync_detailed(client=client, video_channel_id=video_channel_id).parsed +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio_detailed( *, client: AuthenticatedClient | Client, video_channel_id: str ) -> Response[Any]: diff --git a/src/peertube/api/video_feeds/syndicated_comments.py b/src/peertube/api/video_feeds/syndicated_comments.py index d0f9718..0a56bcc 100644 --- a/src/peertube/api/video_feeds/syndicated_comments.py +++ b/src/peertube/api/video_feeds/syndicated_comments.py @@ -3,6 +3,7 @@ from typing import Any, cast import httpx +from pydantic import ConfigDict, validate_call from peertube import errors from peertube.client import AuthenticatedClient, Client @@ -84,6 +85,7 @@ def _build_response( ) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync_detailed( format_: GetSyndicatedCommentsFormat, *, @@ -127,6 +129,7 @@ def sync_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync( format_: GetSyndicatedCommentsFormat, *, @@ -167,6 +170,7 @@ def sync( ).parsed +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio_detailed( format_: GetSyndicatedCommentsFormat, *, @@ -210,6 +214,7 @@ async def asyncio_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio( format_: GetSyndicatedCommentsFormat, *, diff --git a/src/peertube/api/video_feeds/syndicated_subscription_videos.py b/src/peertube/api/video_feeds/syndicated_subscription_videos.py index d7d46bd..90d1c6c 100644 --- a/src/peertube/api/video_feeds/syndicated_subscription_videos.py +++ b/src/peertube/api/video_feeds/syndicated_subscription_videos.py @@ -3,6 +3,7 @@ from typing import Any, cast import httpx +from pydantic import ConfigDict, validate_call from peertube import errors from peertube.client import AuthenticatedClient, Client @@ -106,6 +107,7 @@ def _build_response( ) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync_detailed( format_: GetSyndicatedSubscriptionVideosFormat, *, @@ -162,6 +164,7 @@ def sync_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync( format_: GetSyndicatedSubscriptionVideosFormat, *, @@ -215,6 +218,7 @@ def sync( ).parsed +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio_detailed( format_: GetSyndicatedSubscriptionVideosFormat, *, @@ -271,6 +275,7 @@ async def asyncio_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio( format_: GetSyndicatedSubscriptionVideosFormat, *, diff --git a/src/peertube/api/video_feeds/syndicated_videos.py b/src/peertube/api/video_feeds/syndicated_videos.py index b48183c..b6c5732 100644 --- a/src/peertube/api/video_feeds/syndicated_videos.py +++ b/src/peertube/api/video_feeds/syndicated_videos.py @@ -3,6 +3,7 @@ from typing import Any, cast import httpx +from pydantic import ConfigDict, validate_call from peertube import errors from peertube.client import AuthenticatedClient, Client @@ -109,6 +110,7 @@ def _build_response( ) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync_detailed( format_: GetSyndicatedVideosFormat, *, @@ -171,6 +173,7 @@ def sync_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync( format_: GetSyndicatedVideosFormat, *, @@ -230,6 +233,7 @@ def sync( ).parsed +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio_detailed( format_: GetSyndicatedVideosFormat, *, @@ -292,6 +296,7 @@ async def asyncio_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio( format_: GetSyndicatedVideosFormat, *, diff --git a/src/peertube/api/video_feeds/videos_podcast_feed.py b/src/peertube/api/video_feeds/videos_podcast_feed.py index 4e96ed9..30f7a27 100644 --- a/src/peertube/api/video_feeds/videos_podcast_feed.py +++ b/src/peertube/api/video_feeds/videos_podcast_feed.py @@ -1,6 +1,7 @@ from typing import Any import httpx +from pydantic import ConfigDict, validate_call from peertube import errors from peertube.api.shared_utils import build_response @@ -43,6 +44,7 @@ def _build_response( return build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync_detailed( *, client: AuthenticatedClient | Client, video_channel_id: str ) -> Response[Any]: @@ -67,6 +69,7 @@ def sync_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync(*, client: AuthenticatedClient | Client, video_channel_id: str) -> Any | None: """Videos podcast feed @@ -82,6 +85,7 @@ def sync(*, client: AuthenticatedClient | Client, video_channel_id: str) -> Any return sync_detailed(client=client, video_channel_id=video_channel_id).parsed +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio_detailed( *, client: AuthenticatedClient | Client, video_channel_id: str ) -> Response[Any]: diff --git a/src/peertube/api/video_mirroring/del_mirrored_video.py b/src/peertube/api/video_mirroring/del_mirrored_video.py index d9a058f..462265a 100644 --- a/src/peertube/api/video_mirroring/del_mirrored_video.py +++ b/src/peertube/api/video_mirroring/del_mirrored_video.py @@ -1,6 +1,7 @@ from typing import Any import httpx +from pydantic import ConfigDict, validate_call from peertube import errors from peertube.api.shared_utils import build_response @@ -37,6 +38,7 @@ def _build_response( return build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync_detailed(redundancy_id: str, *, client: AuthenticatedClient) -> Response[Any]: """Delete a mirror done on a video @@ -59,6 +61,7 @@ def sync_detailed(redundancy_id: str, *, client: AuthenticatedClient) -> Respons return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync(redundancy_id: str, *, client: AuthenticatedClient) -> Any | None: """Delete a mirror done on a video @@ -74,6 +77,7 @@ def sync(redundancy_id: str, *, client: AuthenticatedClient) -> Any | None: return sync_detailed(redundancy_id=redundancy_id, client=client).parsed +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio_detailed( redundancy_id: str, *, client: AuthenticatedClient ) -> Response[Any]: diff --git a/src/peertube/api/video_mirroring/get_mirrored_videos.py b/src/peertube/api/video_mirroring/get_mirrored_videos.py index 6d7f0e6..7f0b395 100644 --- a/src/peertube/api/video_mirroring/get_mirrored_videos.py +++ b/src/peertube/api/video_mirroring/get_mirrored_videos.py @@ -2,6 +2,7 @@ from typing import Any import httpx +from pydantic import ConfigDict, validate_call from peertube import errors from peertube.client import AuthenticatedClient, Client @@ -71,6 +72,7 @@ def _build_response( ) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync_detailed( *, client: AuthenticatedClient, @@ -103,6 +105,7 @@ def sync_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync( *, client: AuthenticatedClient, @@ -133,6 +136,7 @@ def sync( ).parsed +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio_detailed( *, client: AuthenticatedClient, @@ -165,6 +169,7 @@ async def asyncio_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio( *, client: AuthenticatedClient, diff --git a/src/peertube/api/video_mirroring/mirrored_videos.py b/src/peertube/api/video_mirroring/mirrored_videos.py index 6d7f0e6..7f0b395 100644 --- a/src/peertube/api/video_mirroring/mirrored_videos.py +++ b/src/peertube/api/video_mirroring/mirrored_videos.py @@ -2,6 +2,7 @@ from typing import Any import httpx +from pydantic import ConfigDict, validate_call from peertube import errors from peertube.client import AuthenticatedClient, Client @@ -71,6 +72,7 @@ def _build_response( ) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync_detailed( *, client: AuthenticatedClient, @@ -103,6 +105,7 @@ def sync_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync( *, client: AuthenticatedClient, @@ -133,6 +136,7 @@ def sync( ).parsed +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio_detailed( *, client: AuthenticatedClient, @@ -165,6 +169,7 @@ async def asyncio_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio( *, client: AuthenticatedClient, diff --git a/src/peertube/api/video_passwords/api_videos_id_passwords.py b/src/peertube/api/video_passwords/api_videos_id_passwords.py index 40eecc2..6743651 100644 --- a/src/peertube/api/video_passwords/api_videos_id_passwords.py +++ b/src/peertube/api/video_passwords/api_videos_id_passwords.py @@ -3,6 +3,7 @@ from uuid import UUID import httpx +from pydantic import ConfigDict, validate_call from peertube import errors from peertube.client import AuthenticatedClient, Client @@ -38,6 +39,9 @@ def _get_kwargs( def _parse_response( *, client: AuthenticatedClient | Client, response: httpx.Response ) -> Any | VideoPasswordList | None: + if response.status_code == 200: + response_200 = VideoPasswordList.from_dict(response.json()) + return response_200 if response.status_code == 204: response_204 = VideoPasswordList.from_dict(response.json()) @@ -62,6 +66,7 @@ def _build_response( ) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync_detailed( id: UUID | int | str, *, @@ -94,6 +99,7 @@ def sync_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync( id: UUID | int | str, *, @@ -124,6 +130,7 @@ def sync( ).parsed +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio_detailed( id: UUID | int | str, *, @@ -156,6 +163,7 @@ async def asyncio_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio( id: UUID | int | str, *, diff --git a/src/peertube/api/video_passwords/api_videos_id_passwords_video_password_id.py b/src/peertube/api/video_passwords/api_videos_id_passwords_video_password_id.py index f436c78..e9e4e4b 100644 --- a/src/peertube/api/video_passwords/api_videos_id_passwords_video_password_id.py +++ b/src/peertube/api/video_passwords/api_videos_id_passwords_video_password_id.py @@ -2,6 +2,7 @@ from uuid import UUID import httpx +from pydantic import ConfigDict, validate_call from peertube import errors from peertube.api.shared_utils import build_response @@ -41,6 +42,7 @@ def _build_response( return build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync_detailed( id: UUID | int | str, video_password_id: int, *, client: AuthenticatedClient ) -> Response[Any]: @@ -66,6 +68,7 @@ def sync_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync( id: UUID | int | str, video_password_id: int, *, client: AuthenticatedClient ) -> Any | None: @@ -85,6 +88,7 @@ def sync( ).parsed +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio_detailed( id: UUID | int | str, video_password_id: int, *, client: AuthenticatedClient ) -> Response[Any]: diff --git a/src/peertube/api/video_passwords/delete_api_v_1_videos_id_passwords_video_password_id.py b/src/peertube/api/video_passwords/delete_api_v_1_videos_id_passwords_video_password_id.py index f436c78..e9e4e4b 100644 --- a/src/peertube/api/video_passwords/delete_api_v_1_videos_id_passwords_video_password_id.py +++ b/src/peertube/api/video_passwords/delete_api_v_1_videos_id_passwords_video_password_id.py @@ -2,6 +2,7 @@ from uuid import UUID import httpx +from pydantic import ConfigDict, validate_call from peertube import errors from peertube.api.shared_utils import build_response @@ -41,6 +42,7 @@ def _build_response( return build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync_detailed( id: UUID | int | str, video_password_id: int, *, client: AuthenticatedClient ) -> Response[Any]: @@ -66,6 +68,7 @@ def sync_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync( id: UUID | int | str, video_password_id: int, *, client: AuthenticatedClient ) -> Any | None: @@ -85,6 +88,7 @@ def sync( ).parsed +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio_detailed( id: UUID | int | str, video_password_id: int, *, client: AuthenticatedClient ) -> Response[Any]: diff --git a/src/peertube/api/video_passwords/get_api_videos_id_passwords.py b/src/peertube/api/video_passwords/get_api_videos_id_passwords.py index 40eecc2..59c9a53 100644 --- a/src/peertube/api/video_passwords/get_api_videos_id_passwords.py +++ b/src/peertube/api/video_passwords/get_api_videos_id_passwords.py @@ -3,6 +3,7 @@ from uuid import UUID import httpx +from pydantic import ConfigDict, validate_call from peertube import errors from peertube.client import AuthenticatedClient, Client @@ -62,6 +63,7 @@ def _build_response( ) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync_detailed( id: UUID | int | str, *, @@ -94,6 +96,7 @@ def sync_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync( id: UUID | int | str, *, @@ -124,6 +127,7 @@ def sync( ).parsed +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio_detailed( id: UUID | int | str, *, @@ -156,6 +160,7 @@ async def asyncio_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio( id: UUID | int | str, *, diff --git a/src/peertube/api/video_playlists/add_playlist.py b/src/peertube/api/video_playlists/add_playlist.py index bb44dea..775f239 100644 --- a/src/peertube/api/video_playlists/add_playlist.py +++ b/src/peertube/api/video_playlists/add_playlist.py @@ -1,6 +1,7 @@ from typing import Any import httpx +from pydantic import ConfigDict, validate_call from peertube.api.shared_utils import build_response, parse_response from peertube.client import AuthenticatedClient, Client @@ -33,6 +34,7 @@ def _build_response( return build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync_detailed( *, client: AuthenticatedClient, body: AddPlaylistBody ) -> Response[Any]: @@ -57,6 +59,7 @@ def sync_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync(*, client: AuthenticatedClient, body: AddPlaylistBody) -> Any | None: """Create a video playlist @@ -72,6 +75,7 @@ def sync(*, client: AuthenticatedClient, body: AddPlaylistBody) -> Any | None: return sync_detailed(client=client, body=body).parsed +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio_detailed( *, client: AuthenticatedClient, body: AddPlaylistBody ) -> Response[Any]: diff --git a/src/peertube/api/video_playlists/api_accounts_name_video_playlists.py b/src/peertube/api/video_playlists/api_accounts_name_video_playlists.py index 70aefbe..1c78b41 100644 --- a/src/peertube/api/video_playlists/api_accounts_name_video_playlists.py +++ b/src/peertube/api/video_playlists/api_accounts_name_video_playlists.py @@ -2,6 +2,7 @@ from typing import Any import httpx +from pydantic import ConfigDict, validate_call from peertube import errors from peertube.client import AuthenticatedClient, Client @@ -72,6 +73,7 @@ def _build_response( ) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync_detailed( name: str, *, @@ -115,6 +117,7 @@ def sync_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync( name: str, *, @@ -155,6 +158,7 @@ def sync( ).parsed +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio_detailed( name: str, *, @@ -198,6 +202,7 @@ async def asyncio_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio( name: str, *, diff --git a/src/peertube/api/video_playlists/api_video_channels_channel_handle_video_playlists.py b/src/peertube/api/video_playlists/api_video_channels_channel_handle_video_playlists.py index 59fab5e..eb501e9 100644 --- a/src/peertube/api/video_playlists/api_video_channels_channel_handle_video_playlists.py +++ b/src/peertube/api/video_playlists/api_video_channels_channel_handle_video_playlists.py @@ -2,6 +2,7 @@ from typing import Any import httpx +from pydantic import ConfigDict, validate_call from peertube import errors from peertube.client import AuthenticatedClient, Client @@ -71,6 +72,7 @@ def _build_response( ) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync_detailed( channel_handle: str, *, @@ -111,6 +113,7 @@ def sync_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync( channel_handle: str, *, @@ -148,6 +151,7 @@ def sync( ).parsed +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio_detailed( channel_handle: str, *, @@ -188,6 +192,7 @@ async def asyncio_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio( channel_handle: str, *, diff --git a/src/peertube/api/video_playlists/get_api_accounts_name_video_playlists.py b/src/peertube/api/video_playlists/get_api_accounts_name_video_playlists.py index 70aefbe..1c78b41 100644 --- a/src/peertube/api/video_playlists/get_api_accounts_name_video_playlists.py +++ b/src/peertube/api/video_playlists/get_api_accounts_name_video_playlists.py @@ -2,6 +2,7 @@ from typing import Any import httpx +from pydantic import ConfigDict, validate_call from peertube import errors from peertube.client import AuthenticatedClient, Client @@ -72,6 +73,7 @@ def _build_response( ) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync_detailed( name: str, *, @@ -115,6 +117,7 @@ def sync_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync( name: str, *, @@ -155,6 +158,7 @@ def sync( ).parsed +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio_detailed( name: str, *, @@ -198,6 +202,7 @@ async def asyncio_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio( name: str, *, diff --git a/src/peertube/api/video_playlists/get_api_v_1_video_channels_channel_handle_video_playlists.py b/src/peertube/api/video_playlists/get_api_v_1_video_channels_channel_handle_video_playlists.py index 59fab5e..eb501e9 100644 --- a/src/peertube/api/video_playlists/get_api_v_1_video_channels_channel_handle_video_playlists.py +++ b/src/peertube/api/video_playlists/get_api_v_1_video_channels_channel_handle_video_playlists.py @@ -2,6 +2,7 @@ from typing import Any import httpx +from pydantic import ConfigDict, validate_call from peertube import errors from peertube.client import AuthenticatedClient, Client @@ -71,6 +72,7 @@ def _build_response( ) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync_detailed( channel_handle: str, *, @@ -111,6 +113,7 @@ def sync_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync( channel_handle: str, *, @@ -148,6 +151,7 @@ def sync( ).parsed +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio_detailed( channel_handle: str, *, @@ -188,6 +192,7 @@ async def asyncio_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio( channel_handle: str, *, diff --git a/src/peertube/api/video_playlists/get_playlist_privacy_policies.py b/src/peertube/api/video_playlists/get_playlist_privacy_policies.py index 7145106..28597a3 100644 --- a/src/peertube/api/video_playlists/get_playlist_privacy_policies.py +++ b/src/peertube/api/video_playlists/get_playlist_privacy_policies.py @@ -2,6 +2,7 @@ from typing import Any, cast import httpx +from pydantic import ConfigDict, validate_call from peertube import errors from peertube.client import AuthenticatedClient, Client @@ -41,6 +42,7 @@ def _build_response( ) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync_detailed(*, client: AuthenticatedClient | Client) -> Response[list[str]]: """List available playlist privacy policies @@ -60,6 +62,7 @@ def sync_detailed(*, client: AuthenticatedClient | Client) -> Response[list[str] return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync(*, client: AuthenticatedClient | Client) -> list[str] | None: """List available playlist privacy policies @@ -75,6 +78,7 @@ def sync(*, client: AuthenticatedClient | Client) -> list[str] | None: return sync_detailed(client=client).parsed +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio_detailed( *, client: AuthenticatedClient | Client ) -> Response[list[str]]: @@ -96,6 +100,7 @@ async def asyncio_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio(*, client: AuthenticatedClient | Client) -> list[str] | None: """List available playlist privacy policies diff --git a/src/peertube/api/video_playlists/get_playlists.py b/src/peertube/api/video_playlists/get_playlists.py index 8958f4a..2e3a6d6 100644 --- a/src/peertube/api/video_playlists/get_playlists.py +++ b/src/peertube/api/video_playlists/get_playlists.py @@ -2,6 +2,7 @@ from typing import Any import httpx +from pydantic import ConfigDict, validate_call from peertube import errors from peertube.client import AuthenticatedClient, Client @@ -64,6 +65,7 @@ def _build_response( ) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync_detailed( *, client: AuthenticatedClient | Client, @@ -98,6 +100,7 @@ def sync_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync( *, client: AuthenticatedClient | Client, @@ -128,6 +131,7 @@ def sync( ).parsed +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio_detailed( *, client: AuthenticatedClient | Client, @@ -162,6 +166,7 @@ async def asyncio_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio( *, client: AuthenticatedClient | Client, diff --git a/src/peertube/api/video_playlists/playlist_privacy_policies.py b/src/peertube/api/video_playlists/playlist_privacy_policies.py index 7145106..28597a3 100644 --- a/src/peertube/api/video_playlists/playlist_privacy_policies.py +++ b/src/peertube/api/video_playlists/playlist_privacy_policies.py @@ -2,6 +2,7 @@ from typing import Any, cast import httpx +from pydantic import ConfigDict, validate_call from peertube import errors from peertube.client import AuthenticatedClient, Client @@ -41,6 +42,7 @@ def _build_response( ) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync_detailed(*, client: AuthenticatedClient | Client) -> Response[list[str]]: """List available playlist privacy policies @@ -60,6 +62,7 @@ def sync_detailed(*, client: AuthenticatedClient | Client) -> Response[list[str] return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync(*, client: AuthenticatedClient | Client) -> list[str] | None: """List available playlist privacy policies @@ -75,6 +78,7 @@ def sync(*, client: AuthenticatedClient | Client) -> list[str] | None: return sync_detailed(client=client).parsed +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio_detailed( *, client: AuthenticatedClient | Client ) -> Response[list[str]]: @@ -96,6 +100,7 @@ async def asyncio_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio(*, client: AuthenticatedClient | Client) -> list[str] | None: """List available playlist privacy policies diff --git a/src/peertube/api/video_playlists/playlists.py b/src/peertube/api/video_playlists/playlists.py index 8958f4a..2e3a6d6 100644 --- a/src/peertube/api/video_playlists/playlists.py +++ b/src/peertube/api/video_playlists/playlists.py @@ -2,6 +2,7 @@ from typing import Any import httpx +from pydantic import ConfigDict, validate_call from peertube import errors from peertube.client import AuthenticatedClient, Client @@ -64,6 +65,7 @@ def _build_response( ) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync_detailed( *, client: AuthenticatedClient | Client, @@ -98,6 +100,7 @@ def sync_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync( *, client: AuthenticatedClient | Client, @@ -128,6 +131,7 @@ def sync( ).parsed +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio_detailed( *, client: AuthenticatedClient | Client, @@ -162,6 +166,7 @@ async def asyncio_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio( *, client: AuthenticatedClient | Client, diff --git a/src/peertube/api/video_playlists/reorder_video_playlists_of_channel.py b/src/peertube/api/video_playlists/reorder_video_playlists_of_channel.py index 262a350..532946b 100644 --- a/src/peertube/api/video_playlists/reorder_video_playlists_of_channel.py +++ b/src/peertube/api/video_playlists/reorder_video_playlists_of_channel.py @@ -1,6 +1,7 @@ from typing import Any import httpx +from pydantic import ConfigDict, validate_call from peertube import errors from peertube.api.shared_utils import build_response @@ -45,6 +46,7 @@ def _build_response( return build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync_detailed( channel_handle: str, *, @@ -73,6 +75,7 @@ def sync_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync( channel_handle: str, *, @@ -93,6 +96,7 @@ def sync( return sync_detailed(channel_handle=channel_handle, client=client, body=body).parsed +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio_detailed( channel_handle: str, *, diff --git a/src/peertube/api/video_rates/api_videos_id_rate.py b/src/peertube/api/video_rates/api_videos_id_rate.py index 5f71747..55e012c 100644 --- a/src/peertube/api/video_rates/api_videos_id_rate.py +++ b/src/peertube/api/video_rates/api_videos_id_rate.py @@ -2,6 +2,7 @@ from uuid import UUID import httpx +from pydantic import ConfigDict, validate_call from peertube import errors from peertube.api.shared_utils import build_response @@ -51,6 +52,7 @@ def _build_response( return build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync_detailed( id: UUID | int | str, *, @@ -83,6 +85,7 @@ def sync_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync( id: UUID | int | str, *, @@ -109,6 +112,7 @@ def sync( ).parsed +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio_detailed( id: UUID | int | str, *, diff --git a/src/peertube/api/video_rates/put_api_videos_id_rate.py b/src/peertube/api/video_rates/put_api_videos_id_rate.py index 5f71747..55e012c 100644 --- a/src/peertube/api/video_rates/put_api_videos_id_rate.py +++ b/src/peertube/api/video_rates/put_api_videos_id_rate.py @@ -2,6 +2,7 @@ from uuid import UUID import httpx +from pydantic import ConfigDict, validate_call from peertube import errors from peertube.api.shared_utils import build_response @@ -51,6 +52,7 @@ def _build_response( return build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync_detailed( id: UUID | int | str, *, @@ -83,6 +85,7 @@ def sync_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync( id: UUID | int | str, *, @@ -109,6 +112,7 @@ def sync( ).parsed +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio_detailed( id: UUID | int | str, *, diff --git a/src/peertube/api/video_stats/get_api_videos_id_stats_user_agent.py b/src/peertube/api/video_stats/get_api_videos_id_stats_user_agent.py index a1c83be..f3f5294 100644 --- a/src/peertube/api/video_stats/get_api_videos_id_stats_user_agent.py +++ b/src/peertube/api/video_stats/get_api_videos_id_stats_user_agent.py @@ -4,6 +4,7 @@ from uuid import UUID import httpx +from pydantic import ConfigDict, validate_call from peertube import errors from peertube.client import AuthenticatedClient, Client @@ -62,6 +63,7 @@ def _build_response( ) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync_detailed( id: UUID | int | str, *, @@ -92,6 +94,7 @@ def sync_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) def sync( id: UUID | int | str, *, @@ -120,6 +123,7 @@ def sync( ).parsed +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio_detailed( id: UUID | int | str, *, @@ -150,6 +154,7 @@ async def asyncio_detailed( return _build_response(client=client, response=response) +@validate_call(config=ConfigDict(arbitrary_types_allowed=True)) async def asyncio( id: UUID | int | str, *, diff --git a/src/peertube/models/post_api_v1_runners_jobs_job_uuid_accept_response_200_job.py b/src/peertube/models/post_api_v1_runners_jobs_job_uuid_accept_response_200_job.py index c91849b..6a1d733 100644 --- a/src/peertube/models/post_api_v1_runners_jobs_job_uuid_accept_response_200_job.py +++ b/src/peertube/models/post_api_v1_runners_jobs_job_uuid_accept_response_200_job.py @@ -67,8 +67,6 @@ def to_dict(self) -> dict[str, Any]: """Convert instance to dictionary.""" from peertube.models.runner_job_parent_type_0 import RunnerJobParentType0 - from peertube.models.vod_web_video_transcoding import VODWebVideoTranscoding - from peertube.models.vodhls_transcoding import VODHLSTranscoding uuid: Unset | str = UNSET if not isinstance(self.uuid, Unset): @@ -85,8 +83,6 @@ def to_dict(self) -> dict[str, Any]: payload: Unset | dict[str, Any] if isinstance(self.payload, Unset): payload = UNSET - elif isinstance(self.payload, (VODWebVideoTranscoding, VODHLSTranscoding)): - payload = self.payload.to_dict() else: payload = self.payload.to_dict() diff --git a/src/peertube/models/post_api_v1_runners_jobs_job_uuid_success_body.py b/src/peertube/models/post_api_v1_runners_jobs_job_uuid_success_body.py index 8f8ea99..d7056aa 100644 --- a/src/peertube/models/post_api_v1_runners_jobs_job_uuid_success_body.py +++ b/src/peertube/models/post_api_v1_runners_jobs_job_uuid_success_body.py @@ -44,32 +44,11 @@ class PostApiV1RunnersJobsJobUUIDSuccessBody: def to_dict(self) -> dict[str, Any]: """Convert instance to dictionary.""" - from peertube.models.post_api_v1_runners_jobs_job_uuid_success_body_vod_audio_merge_transcoding import ( - PostApiV1RunnersJobsJobUUIDSuccessBodyVODAudioMergeTranscoding, - ) - from peertube.models.post_api_v1_runners_jobs_job_uuid_success_body_vod_web_video_transcoding import ( - PostApiV1RunnersJobsJobUUIDSuccessBodyVODWebVideoTranscoding, - ) - from peertube.models.post_api_v1_runners_jobs_job_uuid_success_body_vodhls_transcoding import ( - PostApiV1RunnersJobsJobUUIDSuccessBodyVODHLSTranscoding, - ) - runner_token = self.runner_token job_token = self.job_token - payload: dict[str, Any] - if isinstance( - self.payload, - ( - PostApiV1RunnersJobsJobUUIDSuccessBodyVODWebVideoTranscoding, - PostApiV1RunnersJobsJobUUIDSuccessBodyVODHLSTranscoding, - PostApiV1RunnersJobsJobUUIDSuccessBodyVODAudioMergeTranscoding, - ), - ): - payload = self.payload.to_dict() - else: - payload = self.payload.to_dict() + payload: dict[str, Any] = self.payload.to_dict() field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) diff --git a/src/peertube/models/post_api_v1_runners_jobs_request_response_200_available_jobs_item.py b/src/peertube/models/post_api_v1_runners_jobs_request_response_200_available_jobs_item.py index 0f86c20..7cece15 100644 --- a/src/peertube/models/post_api_v1_runners_jobs_request_response_200_available_jobs_item.py +++ b/src/peertube/models/post_api_v1_runners_jobs_request_response_200_available_jobs_item.py @@ -36,9 +36,6 @@ class PostApiV1RunnersJobsRequestResponse200AvailableJobsItem: def to_dict(self) -> dict[str, Any]: """Convert instance to dictionary.""" - from peertube.models.vod_web_video_transcoding import VODWebVideoTranscoding - from peertube.models.vodhls_transcoding import VODHLSTranscoding - uuid: Unset | str = UNSET if not isinstance(self.uuid, Unset): uuid = str(self.uuid) @@ -50,8 +47,6 @@ def to_dict(self) -> dict[str, Any]: payload: Unset | dict[str, Any] if isinstance(self.payload, Unset): payload = UNSET - elif isinstance(self.payload, (VODWebVideoTranscoding, VODHLSTranscoding)): - payload = self.payload.to_dict() else: payload = self.payload.to_dict() diff --git a/src/peertube/models/runner_job.py b/src/peertube/models/runner_job.py index b83df06..0391eec 100644 --- a/src/peertube/models/runner_job.py +++ b/src/peertube/models/runner_job.py @@ -18,7 +18,12 @@ from peertube.models.vod_audio_merge_transcoding import VODAudioMergeTranscoding from peertube.models.vod_web_video_transcoding import VODWebVideoTranscoding from peertube.models.vodhls_transcoding import VODHLSTranscoding - +from peertube.models.runner_job_parent_type_0 import RunnerJobParentType0 +from peertube.models.runner_job_runner import RunnerJobRunner +from peertube.models.runner_job_state_constant import RunnerJobStateConstant +from peertube.models.vod_audio_merge_transcoding import VODAudioMergeTranscoding +from peertube.models.vod_web_video_transcoding import VODWebVideoTranscoding +from peertube.models.vodhls_transcoding import VODHLSTranscoding T = TypeVar("T", bound="RunnerJob") @@ -65,8 +70,6 @@ def to_dict(self) -> dict[str, Any]: """Convert to dictionary.""" from peertube.models.runner_job_parent_type_0 import RunnerJobParentType0 - from peertube.models.vod_web_video_transcoding import VODWebVideoTranscoding - from peertube.models.vodhls_transcoding import VODHLSTranscoding uuid: Unset | str = UNSET if not isinstance(self.uuid, Unset): @@ -83,8 +86,6 @@ def to_dict(self) -> dict[str, Any]: payload: Unset | dict[str, Any] if isinstance(self.payload, Unset): payload = UNSET - elif isinstance(self.payload, (VODWebVideoTranscoding, VODHLSTranscoding)): - payload = self.payload.to_dict() else: payload = self.payload.to_dict() @@ -166,13 +167,6 @@ def to_dict(self) -> dict[str, Any]: def from_dict(cls, src_dict: Mapping[str, Any]) -> Self: """Create from dictionary.""" - from peertube.models.runner_job_parent_type_0 import RunnerJobParentType0 - from peertube.models.runner_job_runner import RunnerJobRunner - from peertube.models.runner_job_state_constant import RunnerJobStateConstant - from peertube.models.vod_audio_merge_transcoding import VODAudioMergeTranscoding - from peertube.models.vod_web_video_transcoding import VODWebVideoTranscoding - from peertube.models.vodhls_transcoding import VODHLSTranscoding - d = dict(src_dict) _uuid = d.pop("uuid", UNSET) uuid: Unset | UUID diff --git a/src/peertube/models/runner_job_admin.py b/src/peertube/models/runner_job_admin.py index e92d4c7..3c938a1 100644 --- a/src/peertube/models/runner_job_admin.py +++ b/src/peertube/models/runner_job_admin.py @@ -70,8 +70,6 @@ def to_dict(self) -> dict[str, Any]: """Convert instance to dictionary.""" from peertube.models.runner_job_parent_type_0 import RunnerJobParentType0 - from peertube.models.vod_web_video_transcoding import VODWebVideoTranscoding - from peertube.models.vodhls_transcoding import VODHLSTranscoding uuid: Unset | str = UNSET if not isinstance(self.uuid, Unset): @@ -88,8 +86,6 @@ def to_dict(self) -> dict[str, Any]: payload: Unset | dict[str, Any] if isinstance(self.payload, Unset): payload = UNSET - elif isinstance(self.payload, (VODWebVideoTranscoding, VODHLSTranscoding)): - payload = self.payload.to_dict() else: payload = self.payload.to_dict() diff --git a/tests/peertube/api/conftest.py b/tests/peertube/api/conftest.py new file mode 100644 index 0000000..e03ff5c --- /dev/null +++ b/tests/peertube/api/conftest.py @@ -0,0 +1,141 @@ +"""Shared fixtures for API tests.""" + +import pytest + + +@pytest.fixture +def sample_playlist_data(): + """Sample playlist data used across playlist tests.""" + return { + "id": 123, + "displayName": "Test Playlist", + "description": "A test playlist", + "privacy": {"id": 1, "label": "Public"}, + "type": {"id": 1, "label": "Regular"}, + "createdAt": "2023-01-01T00:00:00.000Z", + "updatedAt": "2023-01-01T00:00:00.000Z", + } + + +@pytest.fixture +def sample_playlist_response_data(sample_playlist_data): + """Sample playlist response data with total and data array.""" + return { + "total": 1, + "data": [sample_playlist_data], + } + + +@pytest.fixture +def sample_detailed_playlist_data(): + """Detailed playlist data with all fields for comprehensive tests.""" + return { + "id": 1, + "uuid": "12345678-1234-5678-1234-567812345678", + "url": "https://example.com/playlists/playlist-uuid-1", + "displayName": "My Playlist 1", + "shortDescription": "A short description", + "description": "A longer description", + "isLocal": True, + "ownerAccount": { + "id": 1, + "name": "@user@example.com", + "displayName": "User", + "url": "https://example.com/accounts/user", + "host": "example.com", + "avatar": None, + }, + "createdAt": "2023-01-01T00:00:00.000Z", + "updatedAt": "2023-01-01T00:00:00.000Z", + "type": {"id": 1, "label": "Regular"}, + "privacy": {"id": 1, "label": "Public"}, + "videosLength": 5, + "thumbnailPath": "/static/thumbnails/playlists/playlist-uuid-1.jpg", + } + + +@pytest.fixture +def sample_playlist_response_data_detailed(sample_detailed_playlist_data): + """Sample detailed playlist response data with multiple playlists.""" + return { + "total": 2, + "data": [ + sample_detailed_playlist_data, + { + **sample_detailed_playlist_data, + "id": 2, + "uuid": "87654321-4321-8765-4321-876543218765", + "url": "https://example.com/playlists/playlist-uuid-2", + "displayName": "My Playlist 2", + "shortDescription": "Another short description", + "description": "Another longer description", + "videosLength": 3, + "thumbnailPath": "/static/thumbnails/playlists/playlist-uuid-2.jpg", + }, + ], + } + + +@pytest.fixture +def sample_video_feed_data(): + """Sample video feed data for syndicated subscription videos.""" + return [ + { + "media:title": "Test Video 1", + "link": "https://example.com/videos/watch/123", + "guid": "123", + "pubDate": "2023-01-01T12:00:00Z", + "description": "A test video description", + }, + { + "media:title": "Test Video 2", + "link": "https://example.com/videos/watch/456", + "guid": "456", + "pubDate": "2023-01-02T12:00:00Z", + "description": "Another test video description", + }, + ] + + +@pytest.fixture +def sample_mirrored_video_data(): + """Sample mirrored video data.""" + return [ + { + "id": 1, + "name": "Test Video 1", + "url": "https://example.com/video1", + "uuid": "9c9de5e8-0a1e-484a-b099-e80766180a6d", + }, + { + "id": 2, + "name": "Test Video 2", + "url": "https://example.com/video2", + "uuid": "8b8ce5e7-0a1e-484a-b099-e80766180a6c", + }, + ] + + +@pytest.fixture +def sample_owner_account_data(): + """Sample owner account data used in playlist and video objects.""" + return { + "id": 1, + "name": "@user@example.com", + "displayName": "User", + "url": "https://example.com/accounts/user", + "host": "example.com", + "avatar": None, + } + + +@pytest.fixture +def sample_privacy_data(): + """Sample privacy data.""" + return {"id": 1, "label": "Public"} + + +@pytest.fixture +def sample_playlist_type_data(): + """Sample playlist type data.""" + return {"id": 1, "label": "Regular"} diff --git a/tests/peertube/api/test_shared_utils.py b/tests/peertube/api/test_shared_utils.py index c8f3834..e98e17d 100644 --- a/tests/peertube/api/test_shared_utils.py +++ b/tests/peertube/api/test_shared_utils.py @@ -28,16 +28,13 @@ def test_build_response_returns_response_object(self, client, httpx_mock): assert hasattr(result, "parsed") def test_parse_response_returns_none_when_no_raise(self, client, mocker): - """Test parse_response returns None when raise_on_unexpected_status is False""" + """Test parse_response returns parsed JSON for successful responses""" mock_response = mocker.Mock(spec=httpx.Response) mock_response.status_code = 200 - mock_response.content = b"response content" - - # Mock client to not raise on unexpected status - mocker.patch.object(client, "raise_on_unexpected_status", new=False) + mock_response.json.return_value = {"key": "value"} result = parse_response(client=client, response=mock_response) - assert result is None + assert result == {"key": "value"} def test_parse_response_raises_when_configured(self, client, mocker): """Test parse_response raises UnexpectedStatus when configured""" diff --git a/tests/peertube/api/video_feeds/test_get_syndicated_comments.py b/tests/peertube/api/video_feeds/test_get_syndicated_comments.py new file mode 100644 index 0000000..a3e2ae5 --- /dev/null +++ b/tests/peertube/api/video_feeds/test_get_syndicated_comments.py @@ -0,0 +1,44 @@ +"""Tests for get_syndicated_comments function.""" + +import json + +from peertube.api.video_feeds.get_syndicated_comments import sync +from peertube.models.get_syndicated_comments_format import GetSyndicatedCommentsFormat + + +def test_get_syndicated_comments_success(httpx_mock, client): + """Test successful retrieval of syndicated comments.""" + # Sample response data + sample_data = [ + { + "link": "https://example.com/video/123#comment-1", + "guid": "comment-1", + "pubDate": "2023-01-01T12:00:00Z", + "content:encoded": "This is a test comment", + "dc:creator": "testuser", + }, + { + "link": "https://example.com/video/123#comment-2", + "guid": "comment-2", + "pubDate": "2023-01-02T12:00:00Z", + "content:encoded": "This is another test comment", + "dc:creator": "anotheruser", + }, + ] + + # Mock HTTP response + httpx_mock.add_response( + method="GET", + url="https://test.peertube.example/feeds/video-comments.xml", + status_code=200, + text=json.dumps(sample_data), + ) + + # Test the function + result = sync(format_=GetSyndicatedCommentsFormat.XML, client=client) + + assert result is not None + assert len(result) == 2 + assert result[0].link == "https://example.com/video/123#comment-1" + assert result[0].guid == "comment-1" + assert result[1].dccreator == "anotheruser" diff --git a/tests/peertube/api/video_feeds/test_get_syndicated_subscription_videos.py b/tests/peertube/api/video_feeds/test_get_syndicated_subscription_videos.py new file mode 100644 index 0000000..3cf0f15 --- /dev/null +++ b/tests/peertube/api/video_feeds/test_get_syndicated_subscription_videos.py @@ -0,0 +1,35 @@ +"""Tests for get_syndicated_subscription_videos function.""" + +import json + +from peertube.api.video_feeds.get_syndicated_subscription_videos import sync +from peertube.models.get_syndicated_subscription_videos_format import ( + GetSyndicatedSubscriptionVideosFormat, +) + + +def test_get_syndicated_subscription_videos_success( + httpx_mock, client, sample_video_feed_data +): + """Test successful retrieval of syndicated subscription videos.""" + # Mock HTTP response + httpx_mock.add_response( + method="GET", + url="https://test.peertube.example/feeds/subscriptions.xml?accountId=test-account&token=test-token", + status_code=200, + text=json.dumps(sample_video_feed_data), + ) + + # Test the function + result = sync( + format_=GetSyndicatedSubscriptionVideosFormat.XML, + client=client, + account_id="test-account", + token="test-token", # noqa: S106 + ) + + assert result is not None + assert len(result) == 2 + assert result[0].mediatitle == "Test Video 1" + assert result[0].guid == "123" + assert result[1].link == "https://example.com/videos/watch/456" diff --git a/tests/peertube/api/video_mirroring/test_del_mirrored_video.py b/tests/peertube/api/video_mirroring/test_del_mirrored_video.py new file mode 100644 index 0000000..5a1a0c8 --- /dev/null +++ b/tests/peertube/api/video_mirroring/test_del_mirrored_video.py @@ -0,0 +1,18 @@ +"""Tests for del_mirrored_video function.""" + +from peertube.api.video_mirroring.del_mirrored_video import sync + + +def test_del_mirrored_video_success(httpx_mock, auth_client): + """Test successful deletion of mirrored video.""" + # Mock HTTP response + httpx_mock.add_response( + method="DELETE", + url="https://test.peertube.example/api/v1/server/redundancy/videos/test-redundancy-id", + status_code=204, + ) + + # Test the function + result = sync(redundancy_id="test-redundancy-id", client=auth_client) + + assert result is None diff --git a/tests/peertube/api/video_mirroring/test_get_mirrored_videos.py b/tests/peertube/api/video_mirroring/test_get_mirrored_videos.py new file mode 100644 index 0000000..54b7186 --- /dev/null +++ b/tests/peertube/api/video_mirroring/test_get_mirrored_videos.py @@ -0,0 +1,27 @@ +"""Tests for get_mirrored_videos function.""" + +from peertube.api.video_mirroring.get_mirrored_videos import sync +from peertube.models.get_mirrored_videos_target import GetMirroredVideosTarget + + +def test_get_mirrored_videos_success( + httpx_mock, auth_client, sample_mirrored_video_data +): + """Test successful retrieval of mirrored videos.""" + # Mock HTTP response + httpx_mock.add_response( + method="GET", + url="https://test.peertube.example/api/v1/server/redundancy/videos?target=my-videos&count=15", + status_code=200, + json=sample_mirrored_video_data, + ) + + # Test the function + result = sync(client=auth_client, target=GetMirroredVideosTarget.MY_VIDEOS) + + assert result is not None + assert len(result) == 2 + assert result[0].id == 1 + assert result[0].name == "Test Video 1" + assert result[1].id == 2 + assert result[1].name == "Test Video 2" diff --git a/tests/peertube/api/video_mirroring/test_mirrored_videos.py b/tests/peertube/api/video_mirroring/test_mirrored_videos.py new file mode 100644 index 0000000..14dceb1 --- /dev/null +++ b/tests/peertube/api/video_mirroring/test_mirrored_videos.py @@ -0,0 +1,33 @@ +"""Tests for mirrored_videos function.""" + +from peertube.api.video_mirroring.mirrored_videos import sync +from peertube.models.get_mirrored_videos_target import GetMirroredVideosTarget + + +def test_mirrored_videos_success(httpx_mock, auth_client): + """Test successful retrieval of mirrored videos.""" + # Sample response data + sample_data = [ + { + "id": 3, + "name": "Mirrored Video 1", + "url": "https://example.com/mirrored1", + "uuid": "7a7ae5e6-0a1e-484a-b099-e80766180a6b", + }, + ] + + # Mock HTTP response + httpx_mock.add_response( + method="GET", + url="https://test.peertube.example/api/v1/server/redundancy/videos?target=remote-videos&count=15", + status_code=200, + json=sample_data, + ) + + # Test the function + result = sync(client=auth_client, target=GetMirroredVideosTarget.REMOTE_VIDEOS) + + assert result is not None + assert len(result) == 1 + assert result[0].id == 3 + assert result[0].name == "Mirrored Video 1" diff --git a/tests/peertube/api/video_passwords/test_api_videos_id_passwords.py b/tests/peertube/api/video_passwords/test_api_videos_id_passwords.py new file mode 100644 index 0000000..541a5a6 --- /dev/null +++ b/tests/peertube/api/video_passwords/test_api_videos_id_passwords.py @@ -0,0 +1,41 @@ +"""Tests for api_videos_id_passwords function.""" + +from peertube.api.video_passwords.api_videos_id_passwords import sync +from peertube.models.video_password_list import VideoPasswordList +from peertube.types import UNSET + + +def test_api_videos_id_passwords_success(httpx_mock, auth_client): + """Test successful retrieval of video passwords.""" + # Mock response data + response_data = { + "total": 1, + "data": [ + { + "id": 123, + "label": "Test Password", + "createdAt": "2023-01-01T00:00:00.000Z", + } + ], + } + + # Mock HTTP response + httpx_mock.add_response( + method="GET", + url="https://test.peertube.example/api/v1/videos/123/passwords?count=15", + json=response_data, + status_code=200, + ) + + # Test the function + result = sync( + id=123, + client=auth_client, + start=UNSET, + count=15, + sort=UNSET, + ) + + # Assert result is the expected model + expected = VideoPasswordList.from_dict(response_data) + assert result == expected diff --git a/tests/peertube/api/video_passwords/test_delete_api_v_1_videos_id_passwords_video_password_id.py b/tests/peertube/api/video_passwords/test_delete_api_v_1_videos_id_passwords_video_password_id.py new file mode 100644 index 0000000..287243f --- /dev/null +++ b/tests/peertube/api/video_passwords/test_delete_api_v_1_videos_id_passwords_video_password_id.py @@ -0,0 +1,19 @@ +from peertube.api.video_passwords.delete_api_v_1_videos_id_passwords_video_password_id import ( # noqa: E501 + sync, +) + + +class TestDeleteApiV1VideosIdPasswordsVideoPasswordId: + def test_sync(self, auth_client, httpx_mock): + # Mock the API response + httpx_mock.add_response( + method="DELETE", + url="https://test.peertube.example/api/v1/videos/123/passwords/456", + status_code=204, + ) + + # Call the sync function + result = sync(id=123, video_password_id=456, client=auth_client) + + # Assert the result + assert result is None diff --git a/tests/peertube/api/video_playlists/test_add_playlist.py b/tests/peertube/api/video_playlists/test_add_playlist.py new file mode 100644 index 0000000..5b5ac11 --- /dev/null +++ b/tests/peertube/api/video_playlists/test_add_playlist.py @@ -0,0 +1,40 @@ +"""Tests for add_playlist function.""" + +from peertube.api.video_playlists.add_playlist import sync +from peertube.models.add_playlist_body import AddPlaylistBody +from peertube.models.video_playlist_privacy_set import VideoPlaylistPrivacySet + + +def test_add_playlist_success(httpx_mock, auth_client): + """Test successful playlist creation.""" + # Create request body + body = AddPlaylistBody( + display_name="Test Playlist", + privacy=VideoPlaylistPrivacySet(1), # Public + description="A test playlist", + video_channel_id=42, + ) + + # Mock response data + response_data = { + "id": 123, + "displayName": "Test Playlist", + "description": "A test playlist", + "privacy": {"id": 1, "label": "Public"}, + "videoChannelId": 42, + "createdAt": "2023-01-01T00:00:00.000Z", + "updatedAt": "2023-01-01T00:00:00.000Z", + } + + # Mock HTTP response + httpx_mock.add_response( + method="POST", + url="https://test.peertube.example/api/v1/video-playlists", + json=response_data, + status_code=201, + ) + + # Test the function + result = sync(client=auth_client, body=body) + + assert result == response_data diff --git a/tests/peertube/api/video_playlists/test_api_accounts_name_video_playlists.py b/tests/peertube/api/video_playlists/test_api_accounts_name_video_playlists.py new file mode 100644 index 0000000..3a45170 --- /dev/null +++ b/tests/peertube/api/video_playlists/test_api_accounts_name_video_playlists.py @@ -0,0 +1,37 @@ +"""Tests for api_accounts_name_video_playlists function.""" + +from peertube.api.video_playlists.api_accounts_name_video_playlists import sync +from peertube.models.get_api_v1_accounts_name_video_playlists_response_200 import ( + GetApiV1AccountsNameVideoPlaylistsResponse200, +) +from peertube.types import UNSET + + +def test_api_accounts_name_video_playlists_success( + httpx_mock, client, sample_playlist_response_data +): + """Test successful retrieval of account playlists.""" + # Mock HTTP response + httpx_mock.add_response( + method="GET", + url="https://test.peertube.example/api/v1/accounts/test-account/video-playlists?count=15", + json=sample_playlist_response_data, + status_code=200, + ) + + # Test the function + result = sync( + name="test-account", + client=client, + start=UNSET, + count=15, + sort=UNSET, + search=UNSET, + playlist_type=UNSET, + ) + + # Assert result is the expected model + expected = GetApiV1AccountsNameVideoPlaylistsResponse200.from_dict( + sample_playlist_response_data + ) + assert result == expected diff --git a/tests/peertube/api/video_playlists/test_api_video_channels_channel_handle_video_playlists.py b/tests/peertube/api/video_playlists/test_api_video_channels_channel_handle_video_playlists.py new file mode 100644 index 0000000..a17fae7 --- /dev/null +++ b/tests/peertube/api/video_playlists/test_api_video_channels_channel_handle_video_playlists.py @@ -0,0 +1,38 @@ +"""Tests for api_video_channels_channel_handle_video_playlists function.""" + +from peertube.api.video_playlists.api_video_channels_channel_handle_video_playlists import ( # noqa: E501 + sync, +) +from peertube.models.get_api_v1_video_channels_channel_handle_video_playlists_response_200 import ( # noqa: E501 + GetApiV1VideoChannelsChannelHandleVideoPlaylistsResponse200, +) +from peertube.types import UNSET + + +def test_api_video_channels_channel_handle_video_playlists_success( + httpx_mock, client, sample_playlist_response_data +): + """Test successful retrieval of channel playlists.""" + # Mock HTTP response + httpx_mock.add_response( + method="GET", + url="https://test.peertube.example/api/v1/video-channels/test-channel/video-playlists?count=15", + json=sample_playlist_response_data, + status_code=200, + ) + + # Test the function + result = sync( + channel_handle="test-channel", + client=client, + start=UNSET, + count=15, + sort=UNSET, + playlist_type=UNSET, + ) + + # Assert result is the expected model + expected = GetApiV1VideoChannelsChannelHandleVideoPlaylistsResponse200.from_dict( + sample_playlist_response_data + ) + assert result == expected diff --git a/tests/peertube/api/video_playlists/test_get_playlist_privacy_policies.py b/tests/peertube/api/video_playlists/test_get_playlist_privacy_policies.py new file mode 100644 index 0000000..93460eb --- /dev/null +++ b/tests/peertube/api/video_playlists/test_get_playlist_privacy_policies.py @@ -0,0 +1,18 @@ +from peertube.api.video_playlists.get_playlist_privacy_policies import sync + + +class TestGetPlaylistPrivacyPolicies: + def test_sync(self, client, httpx_mock): + # Mock the API response + httpx_mock.add_response( + method="GET", + url="https://test.peertube.example/api/v1/video-playlists/privacies", + json=["public", "private", "unlisted"], + status_code=200, + ) + + # Call the sync function + result = sync(client=client) + + # Assert the result + assert result == ["public", "private", "unlisted"] diff --git a/tests/peertube/api/video_playlists/test_get_playlists.py b/tests/peertube/api/video_playlists/test_get_playlists.py new file mode 100644 index 0000000..7aaf05d --- /dev/null +++ b/tests/peertube/api/video_playlists/test_get_playlists.py @@ -0,0 +1,45 @@ +"""Tests for get_playlists function.""" + +from peertube.api.video_playlists.get_playlists import sync + + +def test_get_playlists_success(httpx_mock, client): + """Test successful retrieval of video playlists.""" + # Sample response data + sample_data = { + "total": 2, + "data": [ + { + "id": 1, + "uuid": "9c9de5e8-0a1e-484a-b099-e80766180a6d", + "displayName": "My Playlist 1", + "description": "A test playlist", + }, + { + "id": 2, + "uuid": "8b8ce5e7-0a1e-484a-b099-e80766180a6c", + "displayName": "My Playlist 2", + "description": "Another test playlist", + }, + ], + } + + # Mock HTTP response + httpx_mock.add_response( + method="GET", + url="https://test.peertube.example/api/v1/video-playlists?count=15", + status_code=200, + json=sample_data, + ) + + # Test the function + result = sync(client=client) + + assert result is not None + assert result.total == 2 + assert result.data is not None + assert len(result.data) == 2 # type: ignore[arg-type] + assert result.data[0].id == 1 # type: ignore[attr-defined] + assert result.data[0].display_name == "My Playlist 1" # type: ignore[attr-defined] + assert result.data[1].id == 2 # type: ignore[attr-defined] + assert result.data[1].display_name == "My Playlist 2" # type: ignore[attr-defined] diff --git a/tests/peertube/api/video_playlists/test_playlist_privacy_policies.py b/tests/peertube/api/video_playlists/test_playlist_privacy_policies.py new file mode 100644 index 0000000..38b0b9d --- /dev/null +++ b/tests/peertube/api/video_playlists/test_playlist_privacy_policies.py @@ -0,0 +1,26 @@ +"""Tests for playlist_privacy_policies function.""" + +from peertube.api.video_playlists.playlist_privacy_policies import sync + + +def test_playlist_privacy_policies_success(httpx_mock, client): + """Test successful retrieval of playlist privacy policies.""" + # Sample response data + sample_data = ["public", "unlisted", "private"] + + # Mock HTTP response + httpx_mock.add_response( + method="GET", + url="https://test.peertube.example/api/v1/video-playlists/privacies", + status_code=200, + json=sample_data, + ) + + # Test the function + result = sync(client=client) + + assert result is not None + assert len(result) == 3 + assert "public" in result + assert "unlisted" in result + assert "private" in result diff --git a/tests/peertube/api/video_playlists/test_playlists.py b/tests/peertube/api/video_playlists/test_playlists.py new file mode 100644 index 0000000..e45fbb6 --- /dev/null +++ b/tests/peertube/api/video_playlists/test_playlists.py @@ -0,0 +1,29 @@ +from typing import cast + +from peertube.api.video_playlists.playlists import sync +from peertube.types import UNSET + + +class TestPlaylists: + def test_sync(self, client, httpx_mock, sample_playlist_response_data_detailed): + # Mock the API response + httpx_mock.add_response( + method="GET", + url="https://test.peertube.example/api/v1/video-playlists?count=15", + json=sample_playlist_response_data_detailed, + status_code=200, + ) + + # Call the sync function + result = sync(client=client) + + # Assert the result + assert result is not None + assert result.total == 2 + assert result.data is not UNSET + data = cast("list", result.data) + assert len(data) == 2 + assert data[0].id == 1 + assert data[0].display_name == "My Playlist 1" + assert data[1].id == 2 + assert data[1].display_name == "My Playlist 2" diff --git a/tests/peertube/api/video_playlists/test_reorder_video_playlists_of_channel.py b/tests/peertube/api/video_playlists/test_reorder_video_playlists_of_channel.py new file mode 100644 index 0000000..9d27a4c --- /dev/null +++ b/tests/peertube/api/video_playlists/test_reorder_video_playlists_of_channel.py @@ -0,0 +1,27 @@ +"""Tests for reorder_video_playlists_of_channel function.""" + +from peertube.api.video_playlists.reorder_video_playlists_of_channel import sync +from peertube.models.reorder_video_playlists_of_channel_body import ( + ReorderVideoPlaylistsOfChannelBody, +) + + +def test_reorder_video_playlists_of_channel_success(httpx_mock, auth_client): + """Test successful reordering of channel playlists.""" + # Create request body + body = ReorderVideoPlaylistsOfChannelBody( + start_position=1, + insert_after_position=2, + ) + + # Mock HTTP response + httpx_mock.add_response( + method="POST", + url="https://test.peertube.example/api/v1/video-channels/test-channel/video-playlists/reorder", + status_code=204, + ) + + # Test the function + result = sync(channel_handle="test-channel", client=auth_client, body=body) + + assert result is None diff --git a/tests/peertube/api/video_rates/test_api_videos_id_rate.py b/tests/peertube/api/video_rates/test_api_videos_id_rate.py new file mode 100644 index 0000000..ebb6c77 --- /dev/null +++ b/tests/peertube/api/video_rates/test_api_videos_id_rate.py @@ -0,0 +1,25 @@ +"""Tests for api_videos_id_rate function.""" + +from peertube.api.video_rates.api_videos_id_rate import sync +from peertube.models.put_api_v1_videos_id_rate_body import PutApiV1VideosIdRateBody +from peertube.models.put_api_v1_videos_id_rate_body_rating import ( + PutApiV1VideosIdRateBodyRating, +) + + +def test_api_videos_id_rate_success(httpx_mock, auth_client): + """Test successful video rating.""" + # Create request body + body = PutApiV1VideosIdRateBody(rating=PutApiV1VideosIdRateBodyRating.LIKE) + + # Mock HTTP response + httpx_mock.add_response( + method="PUT", + url="https://test.peertube.example/api/v1/videos/123/rate", + status_code=204, + ) + + # Test the function + result = sync(id=123, client=auth_client, body=body) + + assert result is None diff --git a/tests/peertube/api/video_rates/test_put_api_videos_id_rate.py b/tests/peertube/api/video_rates/test_put_api_videos_id_rate.py new file mode 100644 index 0000000..f133d6f --- /dev/null +++ b/tests/peertube/api/video_rates/test_put_api_videos_id_rate.py @@ -0,0 +1,25 @@ +"""Tests for put_api_videos_id_rate function.""" + +from peertube.api.video_rates.put_api_videos_id_rate import sync +from peertube.models.put_api_v1_videos_id_rate_body import PutApiV1VideosIdRateBody +from peertube.models.put_api_v1_videos_id_rate_body_rating import ( + PutApiV1VideosIdRateBodyRating, +) + + +def test_put_api_videos_id_rate_success(httpx_mock, auth_client): + """Test successful video rating update.""" + # Create request body + body = PutApiV1VideosIdRateBody(rating=PutApiV1VideosIdRateBodyRating.DISLIKE) + + # Mock HTTP response + httpx_mock.add_response( + method="PUT", + url="https://test.peertube.example/api/v1/videos/123/rate", + status_code=204, + ) + + # Test the function + result = sync(id=123, client=auth_client, body=body) + + assert result is None diff --git a/tests/peertube/api/video_stats/test_get_api_videos_id_stats_user_agent.py b/tests/peertube/api/video_stats/test_get_api_videos_id_stats_user_agent.py new file mode 100644 index 0000000..f3b055d --- /dev/null +++ b/tests/peertube/api/video_stats/test_get_api_videos_id_stats_user_agent.py @@ -0,0 +1,45 @@ +"""Tests for get_api_videos_id_stats_user_agent function.""" + +from peertube.api.video_stats.get_api_videos_id_stats_user_agent import sync + + +def test_get_api_videos_id_stats_user_agent_success(httpx_mock, auth_client): + """Test successful retrieval of video stats by user agent.""" + # Sample response data + sample_data = { + "clients": [ + {"name": "Chrome", "viewers": 150.5}, + {"name": "Firefox", "viewers": 75.2}, + ], + "devices": [ + {"name": "desktop", "viewers": 200.0}, + {"name": "mobile", "viewers": 25.7}, + ], + "operatingSystem": [ + {"name": "Windows", "viewers": 120.3}, + {"name": "macOS", "viewers": 80.2}, + ], + } + + # Mock HTTP response + httpx_mock.add_response( + method="GET", + url="https://test.peertube.example/api/v1/videos/123/stats/user-agent", + status_code=200, + json=sample_data, + ) + + # Test the function + result = sync(id=123, client=auth_client) + + assert result is not None + assert result.clients is not None + assert len(result.clients) == 2 # type: ignore[arg-type] + assert result.clients[0].name == "Chrome" # type: ignore[attr-defined] + assert result.clients[0].viewers == 150.5 # type: ignore[attr-defined] + assert result.devices is not None + assert len(result.devices) == 2 # type: ignore[arg-type] + assert result.devices[0].name.value == "desktop" # type: ignore[attr-defined] + assert result.operating_system is not None + assert len(result.operating_system) == 2 # type: ignore[arg-type] + assert result.operating_system[1].name == "macOS" # type: ignore[attr-defined] diff --git a/tests/test_api_functions.py b/tests/test_api_functions.py deleted file mode 100644 index 8b71d43..0000000 --- a/tests/test_api_functions.py +++ /dev/null @@ -1,82 +0,0 @@ -"""Test the generated API functions for PeerTube.""" - -from unittest.mock import patch - -import pytest - -from peertube import Client -from peertube.api.accounts import get_account, get_accounts -from peertube.api.video import get_categories, get_languages, get_video -from peertube.errors import UnexpectedStatus -from peertube.types import Response - -# Optional imports that might not be available -try: - from peertube.models import VideoConstantNumberCategory -except ImportError: - VideoConstantNumberCategory = None - - -class TestGeneratedAPI: - """Test that generated API functions can be imported and have correct structure.""" - - def test_import_video_api_functions(self): - """Test that video API functions can be imported.""" - try: - assert get_video is not None - assert get_categories is not None - assert get_languages is not None - except (ImportError, AttributeError) as e: - pytest.fail(f"Failed to import video API functions: {e}") - - def test_import_account_api_functions(self): - """Test that account API functions can be imported.""" - try: - assert get_accounts is not None - assert get_account is not None - except (ImportError, AttributeError) as e: - pytest.fail(f"Failed to import accounts API functions: {e}") - - def test_api_function_structure(self): - """Test that API functions have expected structure.""" - # API functions should have sync and asyncio methods - assert hasattr(get_categories, "sync") - assert hasattr(get_categories, "asyncio") - assert hasattr(get_categories, "sync_detailed") - assert hasattr(get_categories, "asyncio_detailed") - - @patch("peertube.api.video.get_categories.sync") - def test_api_function_call_structure(self, mock_get_categories): - """Test that API functions can be called with client parameter.""" - # Mock response - mock_get_categories.return_value = {"1": "Music", "2": "Films"} - - # Create client - client = Client(base_url="https://example.peertube.com") - - # Call API function - result = get_categories.sync(client=client) - - # Verify call was made with client - mock_get_categories.assert_called_once_with(client=client) - assert result == {"1": "Music", "2": "Films"} - - def test_model_imports(self): - """Test that generated models can be imported.""" - if VideoConstantNumberCategory is None: - pytest.skip("VideoConstantNumberCategory not available") - assert VideoConstantNumberCategory is not None - - def test_types_import(self): - """Test that generated types can be imported.""" - try: - assert Response is not None - except (ImportError, AttributeError) as e: - pytest.fail(f"Failed to import types: {e}") - - def test_errors_import(self): - """Test that generated errors can be imported.""" - try: - assert UnexpectedStatus is not None - except (ImportError, AttributeError) as e: - pytest.fail(f"Failed to import errors: {e}") diff --git a/tests/test_client_generation.py b/tests/test_client_generation.py deleted file mode 100644 index b13e74d..0000000 --- a/tests/test_client_generation.py +++ /dev/null @@ -1,65 +0,0 @@ -"""Basic tests for the generated PeerTube API client.""" - -from peertube import AuthenticatedClient, Client - - -class TestClientGeneration: - """Test the generated client functionality.""" - - def test_client_import_success(self): - """Test that client classes can be imported successfully.""" - - assert Client is not None - assert AuthenticatedClient is not None - - def test_client_initialization(self): - """Test that Client can be initialized without errors.""" - - base_url = "https://example.peertube.com" - client = Client(base_url=base_url) - - assert client is not None - - def test_authenticated_client_initialization(self): - """Test that AuthenticatedClient can be initialized without errors.""" - - base_url = "https://example.peertube.com" - token = "test-token" - client = AuthenticatedClient(base_url=base_url, token=token) - - assert client is not None - - def test_client_base_url(self): - """Test that client stores base URL correctly.""" - - base_url = "https://example.peertube.com" - client = Client(base_url=base_url) - - assert hasattr(client, "_base_url") - - def test_authenticated_client_token(self): - """Test that authenticated client stores token correctly.""" - - base_url = "https://example.peertube.com" - token = "test-token" - client = AuthenticatedClient(base_url=base_url, token=token) - - assert hasattr(client, "token") - assert client.token == token - - def test_client_with_custom_timeout(self): - """Test that client accepts custom timeout parameter.""" - - base_url = "https://example.peertube.com" - timeout = 30.0 - client = Client(base_url=base_url, timeout=timeout) - - assert client is not None - - def test_client_with_ssl_verification_disabled(self): - """Test that client accepts SSL verification parameter.""" - - base_url = "https://example.peertube.com" - client = Client(base_url=base_url, verify_ssl=False) - - assert client is not None