test_brief_info.py 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. import pytest
  2. from yandex_music import BriefInfo
  3. @pytest.fixture(scope='class')
  4. def brief_info(artist, track, album, playlist, cover, playlist_id, video, chart, vinyl, stats):
  5. return BriefInfo(
  6. artist,
  7. [album],
  8. [playlist],
  9. [album],
  10. TestBriefInfo.last_release_ids,
  11. [album],
  12. [track],
  13. [artist],
  14. [cover],
  15. TestBriefInfo.concerts,
  16. [video],
  17. [vinyl],
  18. TestBriefInfo.has_promotions,
  19. [playlist_id],
  20. stats,
  21. [chart],
  22. )
  23. class TestBriefInfo:
  24. last_release_ids = [8501194, 8302547, 8302836, 8302450]
  25. concerts = None
  26. has_promotions = False
  27. def test_expected_values(
  28. self, brief_info, artist, track, album, playlist, cover, playlist_id, video, chart, vinyl, stats
  29. ):
  30. assert brief_info.artist == artist
  31. assert brief_info.albums == [album]
  32. assert brief_info.playlists == [playlist]
  33. assert brief_info.also_albums == [album]
  34. assert brief_info.last_release_ids == self.last_release_ids
  35. assert brief_info.last_releases == [album]
  36. assert brief_info.popular_tracks == [track]
  37. assert brief_info.similar_artists == [artist]
  38. assert brief_info.all_covers == [cover]
  39. assert brief_info.concerts == self.concerts
  40. assert brief_info.videos == [video]
  41. assert brief_info.vinyls == [vinyl]
  42. assert brief_info.has_promotions == self.has_promotions
  43. assert brief_info.playlist_ids == [playlist_id]
  44. assert brief_info.stats == stats
  45. assert brief_info.tracks_in_chart == [chart]
  46. def test_de_json_none(self, client):
  47. assert BriefInfo.de_json({}, client) is None
  48. def test_de_json_required(self, client, artist, track, album, playlist, cover, playlist_id, video, vinyl):
  49. json_dict = {
  50. 'artist': artist.to_dict(),
  51. 'albums': [album.to_dict()],
  52. 'also_albums': [album.to_dict()],
  53. 'last_release_ids': self.last_release_ids,
  54. 'last_releases': [album.to_dict()],
  55. 'popular_tracks': [track.to_dict()],
  56. 'similar_artists': [artist.to_dict()],
  57. 'all_covers': [cover.to_dict()],
  58. 'concerts': self.concerts,
  59. 'videos': [video.to_dict()],
  60. 'vinyls': [vinyl.to_dict()],
  61. 'has_promotions': self.has_promotions,
  62. 'playlist_ids': [playlist_id.to_dict()],
  63. 'playlists': [playlist.to_dict()],
  64. }
  65. brief_info = BriefInfo.de_json(json_dict, client)
  66. assert brief_info.artist == artist
  67. assert brief_info.albums == [album]
  68. assert brief_info.playlists == [playlist]
  69. assert brief_info.also_albums == [album]
  70. assert brief_info.last_release_ids == self.last_release_ids
  71. assert brief_info.last_releases == [album]
  72. assert brief_info.popular_tracks == [track]
  73. assert brief_info.similar_artists == [artist]
  74. assert brief_info.all_covers == [cover]
  75. assert brief_info.concerts == self.concerts
  76. assert brief_info.videos == [video]
  77. assert brief_info.vinyls == [vinyl]
  78. assert brief_info.has_promotions == self.has_promotions
  79. assert brief_info.playlist_ids == [playlist_id]
  80. def test_de_json_all(self, client, artist, track, album, playlist, cover, playlist_id, video, chart, vinyl, stats):
  81. json_dict = {
  82. 'artist': artist.to_dict(),
  83. 'albums': [album.to_dict()],
  84. 'also_albums': [album.to_dict()],
  85. 'last_release_ids': self.last_release_ids,
  86. 'last_releases': [album.to_dict()],
  87. 'popular_tracks': [track.to_dict()],
  88. 'similar_artists': [artist.to_dict()],
  89. 'all_covers': [cover.to_dict()],
  90. 'concerts': self.concerts,
  91. 'videos': [video.to_dict()],
  92. 'vinyls': [vinyl.to_dict()],
  93. 'has_promotions': self.has_promotions,
  94. 'playlist_ids': [playlist_id.to_dict()],
  95. 'tracks_in_chart': [chart.to_dict()],
  96. 'playlists': [playlist.to_dict()],
  97. 'stats': stats.to_dict(),
  98. }
  99. brief_info = BriefInfo.de_json(json_dict, client)
  100. assert brief_info.artist == artist
  101. assert brief_info.albums == [album]
  102. assert brief_info.playlists == [playlist]
  103. assert brief_info.also_albums == [album]
  104. assert brief_info.last_release_ids == self.last_release_ids
  105. assert brief_info.last_releases == [album]
  106. assert brief_info.popular_tracks == [track]
  107. assert brief_info.similar_artists == [artist]
  108. assert brief_info.all_covers == [cover]
  109. assert brief_info.concerts == self.concerts
  110. assert brief_info.videos == [video]
  111. assert brief_info.vinyls == [vinyl]
  112. assert brief_info.has_promotions == self.has_promotions
  113. assert brief_info.playlist_ids == [playlist_id]
  114. assert brief_info.stats == stats
  115. assert brief_info.tracks_in_chart == [chart]
  116. def test_equality(self, artist, track, album, playlist, cover, playlist_id, video, vinyl, stats):
  117. a = BriefInfo(
  118. artist,
  119. [album],
  120. [playlist],
  121. [album],
  122. self.last_release_ids,
  123. [album],
  124. [track],
  125. [artist],
  126. [cover],
  127. self.concerts,
  128. [video],
  129. [vinyl],
  130. self.has_promotions,
  131. [playlist_id],
  132. stats,
  133. )
  134. b = BriefInfo(
  135. artist,
  136. [album],
  137. [],
  138. [album],
  139. self.last_release_ids,
  140. [],
  141. [],
  142. [artist],
  143. [cover],
  144. self.concerts,
  145. [video],
  146. [vinyl],
  147. True,
  148. [playlist_id],
  149. stats,
  150. )
  151. c = BriefInfo(
  152. artist,
  153. [album],
  154. [playlist],
  155. [album],
  156. [1, 2, 3],
  157. [album],
  158. [track],
  159. [artist],
  160. [],
  161. self.concerts,
  162. [video],
  163. [vinyl],
  164. self.has_promotions,
  165. [playlist_id],
  166. stats,
  167. )
  168. d = BriefInfo(
  169. artist,
  170. [album],
  171. [playlist],
  172. [album],
  173. self.last_release_ids,
  174. [album],
  175. [track],
  176. [artist],
  177. [cover],
  178. self.concerts,
  179. [video],
  180. [vinyl],
  181. self.has_promotions,
  182. [playlist_id],
  183. stats,
  184. )
  185. assert a != b != c
  186. assert hash(a) != hash(b) != hash(c)
  187. assert a is not b is not c
  188. assert a == d