Skip to content

Commit

Permalink
Issues/#509 Новые поля (#576)
Browse files Browse the repository at this point in the history
Добавлены новые модели: CustomWave, R128, LyricsInfo.
Классу Track добавлены новые поля: track_source, available_for_options, r128, lyrics_info, track_sharing_flag.
Классу TrackShort добавлены новые поля: original_index.
Классу Playlist добавлены новые поля: custom_wave, pager.
Классу Album добавлены новые поля: available_for_options.

---------

Co-authored-by: Ilya (Marshal) <[email protected]>
  • Loading branch information
andrew097 and MarshalX authored Mar 27, 2023
1 parent a0de455 commit a152e4d
Show file tree
Hide file tree
Showing 22 changed files with 404 additions and 6 deletions.
7 changes: 7 additions & 0 deletions docs/source/yandex_music.playlist.custom_wave.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
yandex\_music.playlist.custom\_wave
===================================

.. automodule:: yandex_music.playlist.custom_wave
:members:
:undoc-members:
:show-inheritance:
1 change: 1 addition & 0 deletions docs/source/yandex_music.playlist.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Submodules
yandex_music.playlist.brand
yandex_music.playlist.case_forms
yandex_music.playlist.contest
yandex_music.playlist.custom_wave
yandex_music.playlist.made_for
yandex_music.playlist.open_graph_data
yandex_music.playlist.play_counter
Expand Down
7 changes: 7 additions & 0 deletions docs/source/yandex_music.track.lyrics_info.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
yandex\_music.track.lyrics\_info
================================

.. automodule:: yandex_music.track.lyrics_info
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/source/yandex_music.track.r128.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
yandex\_music.track.r128
========================

.. automodule:: yandex_music.track.r128
:members:
:undoc-members:
:show-inheritance:
2 changes: 2 additions & 0 deletions docs/source/yandex_music.track.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ Submodules
:maxdepth: 4

yandex_music.track.licence_text_part
yandex_music.track.lyrics_info
yandex_music.track.lyrics_major
yandex_music.track.major
yandex_music.track.meta_data
yandex_music.track.normalization
yandex_music.track.poetry_lover_match
yandex_music.track.r128
yandex_music.track.track
yandex_music.track.track_lyrics
yandex_music.track.tracks_similar
3 changes: 3 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,6 @@
from .test_deprecation import TestDeprecation
from .test_lyrics_major import TestLyricsMajor
from .test_track_lyrics import TestTrackLyrics
from .test_custom_wave import TestCustomWave
from .test_r128 import TestR128
from .test_lyrics_info import TestLyricsInfo
33 changes: 32 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
Client,
Counts,
Cover,
CustomWave,
Day,
Description,
DiscreteScale,
Expand Down Expand Up @@ -94,6 +95,8 @@
Deprecation,
TrackLyrics,
LyricsMajor,
R128,
LyricsInfo,
)
from . import (
TestAccount,
Expand All @@ -110,6 +113,7 @@
TestChartInfoMenuItem,
TestCounts,
TestCover,
TestCustomWave,
TestDay,
TestDescription,
TestDiscreteScale,
Expand Down Expand Up @@ -182,6 +186,8 @@
TestDeprecation,
TestLyricsMajor,
TestTrackLyrics,
TestR128,
TestLyricsInfo,
)


Expand Down Expand Up @@ -246,7 +252,7 @@ def artist_decomposed(artist_without_nested_artist):


@pytest.fixture(scope='session')
def track_factory(major, normalization, user, meta_data, poetry_lover_match):
def track_factory(major, normalization, user, meta_data, poetry_lover_match, r_128, lyrics_info):
class TrackFactory:
def get(self, artists, albums, track_without_nested_tracks=None):
return Track(
Expand Down Expand Up @@ -288,6 +294,11 @@ def get(self, artists, albums, track_without_nested_tracks=None):
TestTrack.background_video_uri,
TestTrack.short_description,
TestTrack.is_suitable_for_children,
TestTrack.track_source,
TestTrack.available_for_options,
r_128,
lyrics_info,
TestTrack.track_sharing_flag,
)

return TrackFactory()
Expand Down Expand Up @@ -388,6 +399,7 @@ def get(self, artists, volumes, albums=None, deprecation=None):
TestAlbum.likes_count,
deprecation,
TestAlbum.available_regions,
TestAlbum.available_for_options,
)

return AlbumFactory()
Expand Down Expand Up @@ -423,6 +435,8 @@ def playlist_factory(
contest,
open_graph_data,
brand,
custom_wave,
pager,
):
class PlaylistFactory:
def get(self, similar_playlists, last_owner_playlists):
Expand Down Expand Up @@ -482,6 +496,8 @@ def get(self, similar_playlists, last_owner_playlists):
TestPlaylist.ready,
TestPlaylist.is_for_from,
TestPlaylist.regions,
custom_wave,
pager,
)

return PlaylistFactory()
Expand Down Expand Up @@ -1299,3 +1315,18 @@ def search_result_with_results_and_type(request, types, results):
[results[request.param]],
types[request.param],
)


@pytest.fixture(scope='session')
def custom_wave():
return CustomWave(TestCustomWave.title, TestCustomWave.animation_url, TestCustomWave.position)


@pytest.fixture(scope='session')
def r_128():
return R128(TestR128.i, TestR128.tp)


@pytest.fixture(scope='session')
def lyrics_info():
return LyricsInfo(TestLyricsInfo.has_available_sync_lyrics, TestLyricsInfo.has_available_text_lyrics)
4 changes: 4 additions & 0 deletions tests/test_album.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class TestAlbum:
start_date = '2020-06-30'
likes_count = 2
available_regions = ['kg', 'tm', 'by', 'kz', 'md', 'ru', 'am', 'ge', 'uz', 'tj', 'il', 'az', 'ua']
available_for_options = ['bookmate']

def test_expected_values(
self,
Expand Down Expand Up @@ -101,6 +102,7 @@ def test_expected_values(
assert album.likes_count == self.likes_count
assert album.deprecation == deprecation
assert album.available_regions == self.available_regions
assert album.available_for_options == self.available_for_options

def test_de_json_none(self, client):
assert Album.de_json({}, client) is None
Expand Down Expand Up @@ -160,6 +162,7 @@ def test_de_json_all(self, client, artist, label, track_position, track, album_w
'likes_count': self.likes_count,
'deprecation': deprecation.to_dict(),
'available_regions': self.available_regions,
'available_for_options': self.available_for_options,
}
album = Album.de_json(json_dict, client)

Expand Down Expand Up @@ -207,6 +210,7 @@ def test_de_json_all(self, client, artist, label, track_position, track, album_w
assert album.likes_count == self.likes_count
assert album.deprecation == deprecation
assert album.available_regions == self.available_regions
assert album.available_for_options == self.available_for_options

def test_equality(self, artist, label):
a = Album(self.id)
Expand Down
52 changes: 52 additions & 0 deletions tests/test_custom_wave.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import pytest

from yandex_music import CustomWave


class TestCustomWave:
title = 'В стиле: Трибунал'
animation_url = 'https://music-custom-wave-media.s3.yandex.net/base.json'
position = 'default'

def test_expected_values(self, custom_wave):
assert custom_wave.title == self.title
assert custom_wave.animation_url == self.animation_url
assert custom_wave.position == self.position

def test_de_json_none(self, client):
assert CustomWave.de_json({}, client) is None

def test_de_json_required(self, client):
json_dict = {
'title': self.title,
'animation_url': self.animation_url,
'position': self.position,
}
customwave = CustomWave.de_json(json_dict, client)

assert customwave.title == self.title
assert customwave.animation_url == self.animation_url
assert customwave.position == self.position

def test_de_json_all(self, client):
json_dict = {
'title': self.title,
'animation_url': self.animation_url,
'position': self.position,
}
customwave = CustomWave.de_json(json_dict, client)

assert customwave.title == self.title
assert customwave.animation_url == self.animation_url
assert customwave.position == self.position

def test_equality(self):
a = CustomWave(self.title, self.animation_url, self.position)
b = CustomWave('', self.animation_url, self.position)
c = CustomWave(self.title, self.animation_url, self.position)

assert a != b
assert hash(a) != hash(b)
assert a is not b

assert a == c
34 changes: 34 additions & 0 deletions tests/test_lyrics_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from yandex_music import LyricsInfo


class TestLyricsInfo:
has_available_sync_lyrics = False
has_available_text_lyrics = True

def test_expected_values(self, lyrics_info):
assert lyrics_info.has_available_sync_lyrics == self.has_available_sync_lyrics
assert lyrics_info.has_available_text_lyrics == self.has_available_text_lyrics

def test_de_json_none(self, client):
assert LyricsInfo.de_json({}, client) is None

def test_de_json_required(self, client):
json_dict = {
'has_available_sync_lyrics': self.has_available_sync_lyrics,
'has_available_text_lyrics': self.has_available_text_lyrics,
}
lyrics_info = LyricsInfo.de_json(json_dict, client)

assert lyrics_info.has_available_sync_lyrics == self.has_available_sync_lyrics
assert lyrics_info.has_available_text_lyrics == self.has_available_text_lyrics

def test_equality(self):
a = LyricsInfo(self.has_available_sync_lyrics, self.has_available_text_lyrics)
b = LyricsInfo(True, self.has_available_text_lyrics)
c = LyricsInfo(self.has_available_sync_lyrics, self.has_available_text_lyrics)

assert a != b
assert hash(a) != hash(b)
assert a is not b

assert a == c
10 changes: 10 additions & 0 deletions tests/test_playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def test_expected_values(
contest,
open_graph_data,
brand,
custom_wave,
pager,
):
assert playlist.owner == user
assert playlist.uid == self.uid
Expand Down Expand Up @@ -115,6 +117,8 @@ def test_expected_values(
assert playlist.ready == self.ready
assert playlist.is_for_from == self.is_for_from
assert playlist.regions == self.regions
assert playlist.custom_wave == custom_wave
assert playlist.pager == pager

def test_de_json_none(self, client):
assert Playlist.de_json({}, client) is None
Expand Down Expand Up @@ -153,6 +157,8 @@ def test_de_json_all(
contest,
open_graph_data,
brand,
custom_wave,
pager,
):
json_dict = {
'owner': user.to_dict(),
Expand Down Expand Up @@ -210,6 +216,8 @@ def test_de_json_all(
'playlist_uuid': self.playlist_uuid,
'type': self.type,
'ready': self.ready,
'custom_wave': custom_wave.to_dict(),
'pager': pager.to_dict(),
}
playlist = Playlist.de_json(json_dict, client)

Expand Down Expand Up @@ -268,6 +276,8 @@ def test_de_json_all(
assert playlist.ready == self.ready
assert playlist.is_for_from == self.is_for_from
assert playlist.regions == self.regions
assert playlist.custom_wave == custom_wave
assert playlist.pager == pager

def test_equality(self, user, cover, made_for, play_counter, playlist_absence):
a = Playlist(user, cover, made_for, play_counter, playlist_absence)
Expand Down
33 changes: 33 additions & 0 deletions tests/test_r128.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import pytest

from yandex_music import R128


class TestR128:
i = -13.12
tp = 0.63

def test_expected_values(self, r_128):
assert r_128.i == self.i
assert r_128.tp == self.tp

def test_de_json_none(self, client):
assert R128.de_json({}, client) is None

def test_de_json_required(self, client):
json_dict = {'i': self.i, 'tp': self.tp}
r128 = R128.de_json(json_dict, client)

assert r128.i == self.i
assert r128.tp == self.tp

def test_equality(self):
a = R128(self.i, self.tp)
b = R128(-8.98, self.tp)
c = R128(self.i, self.tp)

assert a != b
assert hash(a) != hash(b)
assert a is not b

assert a == c
Loading

0 comments on commit a152e4d

Please sign in to comment.