Skip to content
Merged
Show file tree
Hide file tree
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
64 changes: 64 additions & 0 deletions tests/albums/test_get_album_with_tracks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import asyncio
import secrets

import pytest
from ymdantic import YMClient
from ymdantic.exceptions import YMError
from ymdantic.models import Album


@pytest.mark.anyio
Comment thread
KatantDev marked this conversation as resolved.
async def test_get_available_album_with_tracks(client: YMClient) -> None:
album_id = 1814060

result = await client.get_album_with_tracks(album_id=album_id)

assert result is not None
assert isinstance(result, Album)
assert result.meta_type == "music"
assert result.id == album_id
assert result.title is not None
assert result.artists is not None
assert len(result.artists) > 0
assert result.track_count > 0
assert result.volumes is not None
assert len(result.volumes) > 0
assert len(result.volumes[0]) > 0


@pytest.mark.anyio
async def test_get_not_found_album_with_tracks(client: YMClient) -> None:
with pytest.raises(YMError):
await client.get_album_with_tracks(album_id=181406011111)


async def test_get_available_album_with_podcast(client: YMClient) -> None:
album_id = 10141723

result = await client.get_album_with_tracks(album_id=album_id)

assert result is not None
assert isinstance(result, Album)
assert result.meta_type == "podcast"
assert result.id == album_id
assert result.title is not None
assert result.artists is not None
assert result.track_count > 0
assert result.volumes is not None
assert len(result.volumes) > 0
assert len(result.volumes[0]) > 0


@pytest.mark.anyio
async def test_get_random_album(client: YMClient) -> None:
album_ids = [secrets.randbelow(140_000_000) for _ in range(50)]
results = await asyncio.gather(
*[client.get_album_with_tracks(album_id=album_id) for album_id in album_ids],
return_exceptions=True,
)
error_results = [
result
for result in results
if isinstance(result, BaseException) and not isinstance(result, YMError)
]
assert len(error_results) == 0
3 changes: 2 additions & 1 deletion ymdantic/models/tracks/album.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ class TrackAlbum(BaseAlbum):
# Дата начала альбома.
track_position: Optional[TrackPosition] = None
# Позиция трека в альбоме (если есть).
listening_finished: bool
listening_finished: Optional[bool] = None
# Флаг, указывающий, завершено ли прослушивание альбома.
2 changes: 2 additions & 0 deletions ymdantic/models/tracks/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class BaseTrack(YMBaseModel, DeprecatedMixin):
best: bool | None = None
# Является ли трек лучшим (поле доступно при получении альбома с треками
# `get_album_with_tracks`).
listening_finished: bool | None = None
# Флаг, указывающий, завершено ли прослушивание альбома.

@property
def artists_names(self) -> str | None:
Expand Down