test_playlist.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. from yandex_music import Playlist
  2. class TestPlaylist:
  3. uid = 503646255
  4. kind = 69814820
  5. title = 'Плейлист дня'
  6. track_count = 57
  7. tags = []
  8. revision = 0
  9. snapshot = 1
  10. visibility = 'public'
  11. collective = False
  12. url_part = 'daily'
  13. created = '2018-04-29T21:00:00+00:00'
  14. modified = '2019-11-09T03:00:00+00:00'
  15. available = True
  16. is_banner = False
  17. is_premiere = False
  18. duration_ms = 12402690
  19. og_image = 'avatars.yandex.net/get-music-user-playlist/38125/q0ahkhfQE3neTk/%%?1572609906461'
  20. og_title = 'Плейлист дня'
  21. og_description = 'Слушайте с пользой: подкасты, которые могут вам понравиться'
  22. image = ''
  23. background_color = ''
  24. text_color = ''
  25. id_for_from = 'playlist_of_the_day'
  26. dummy_description = 'Слушайте интересные подкасты, чтобы мы могли узнать вас получше и\\xa0собрать этот плейлист'
  27. dummy_page_description = (
  28. 'Чтобы собрать для вас этот плейлист, мы должны узнать вас чуточку поближе. Слушайте больше!'
  29. )
  30. metrika_id = 666666
  31. coauthors = [1130000003905541]
  32. prerolls = []
  33. likes_count = 1
  34. generated_playlist_type = 'playlistOfTheDay'
  35. animated_cover_uri = 'avatars.yandex.net/get-music-user-playlist/30088/q0ahjvoZK5FT4A/%%'
  36. ever_played = True
  37. description = 'Каждый день — новый. Каждый день — ваш!'
  38. description_formatted = 'Каждый день — новый. Каждый день — ваш!'
  39. playlist_uuid = '5d06568a-9430-1df3-e066-6a32cf34d639'
  40. type = 'missedLikes'
  41. ready = True
  42. is_for_from = None
  43. regions = None
  44. def test_expected_values(
  45. self,
  46. playlist,
  47. user,
  48. cover,
  49. made_for,
  50. track_short,
  51. play_counter,
  52. playlist_absence,
  53. playlist_without_nested_playlists,
  54. artist,
  55. track_id,
  56. contest,
  57. open_graph_data,
  58. brand,
  59. custom_wave,
  60. pager,
  61. ):
  62. assert playlist.owner == user
  63. assert playlist.uid == self.uid
  64. assert playlist.kind == self.kind
  65. assert playlist.title == self.title
  66. assert playlist.track_count == self.track_count
  67. assert playlist.cover == cover
  68. assert playlist.made_for == made_for
  69. assert playlist.play_counter == play_counter
  70. assert playlist.playlist_absence == playlist_absence
  71. assert playlist.tags == self.tags
  72. assert playlist.revision == self.revision
  73. assert playlist.snapshot == self.snapshot
  74. assert playlist.visibility == self.visibility
  75. assert playlist.collective == self.collective
  76. assert playlist.url_part == self.url_part
  77. assert playlist.created == self.created
  78. assert playlist.modified == self.modified
  79. assert playlist.available == self.available
  80. assert playlist.is_banner == self.is_banner
  81. assert playlist.is_premiere == self.is_premiere
  82. assert playlist.duration_ms == self.duration_ms
  83. assert playlist.og_image == self.og_image
  84. assert playlist.og_title == self.og_title
  85. assert playlist.og_description == self.og_description
  86. assert playlist.image == self.image
  87. assert playlist.cover_without_text == cover
  88. assert playlist.contest == contest
  89. assert playlist.background_color == self.background_color
  90. assert playlist.text_color == self.text_color
  91. assert playlist.id_for_from == self.id_for_from
  92. assert playlist.dummy_description == self.dummy_description
  93. assert playlist.dummy_page_description == self.dummy_page_description
  94. assert playlist.dummy_cover == cover
  95. assert playlist.dummy_rollover_cover == cover
  96. assert playlist.og_data == open_graph_data
  97. assert playlist.branding == brand
  98. assert playlist.metrika_id == self.metrika_id
  99. assert playlist.coauthors == self.coauthors
  100. assert playlist.top_artist == [artist]
  101. assert playlist.recent_tracks == [track_id]
  102. assert playlist.tracks == [track_short]
  103. assert playlist.prerolls == self.prerolls
  104. assert playlist.likes_count == self.likes_count
  105. assert playlist.similar_playlists == [playlist_without_nested_playlists]
  106. assert playlist.last_owner_playlists == [playlist_without_nested_playlists]
  107. assert playlist.generated_playlist_type == self.generated_playlist_type
  108. assert playlist.animated_cover_uri == self.animated_cover_uri
  109. assert playlist.ever_played == self.ever_played
  110. assert playlist.description == self.description
  111. assert playlist.description_formatted == self.description_formatted
  112. assert playlist.playlist_uuid == self.playlist_uuid
  113. assert playlist.type == self.type
  114. assert playlist.ready == self.ready
  115. assert playlist.is_for_from == self.is_for_from
  116. assert playlist.regions == self.regions
  117. assert playlist.custom_wave == custom_wave
  118. assert playlist.pager == pager
  119. def test_de_json_none(self, client):
  120. assert Playlist.de_json({}, client) is None
  121. def test_de_list_none(self, client):
  122. assert Playlist.de_list([], client) == []
  123. def test_de_json_required(self, client, user, cover, made_for, play_counter, playlist_absence):
  124. json_dict = {
  125. 'owner': user.to_dict(),
  126. 'cover': cover.to_dict(),
  127. 'made_for': made_for.to_dict(),
  128. 'play_counter': play_counter.to_dict(),
  129. 'playlist_absence': playlist_absence.to_dict(),
  130. }
  131. playlist = Playlist.de_json(json_dict, client)
  132. assert playlist.owner == user
  133. assert playlist.cover == cover
  134. assert playlist.made_for == made_for
  135. assert playlist.play_counter == play_counter
  136. assert playlist.playlist_absence == playlist_absence
  137. def test_de_json_all(
  138. self,
  139. client,
  140. user,
  141. cover,
  142. made_for,
  143. track_short,
  144. play_counter,
  145. playlist_absence,
  146. playlist_without_nested_playlists,
  147. artist,
  148. track_id,
  149. contest,
  150. open_graph_data,
  151. brand,
  152. custom_wave,
  153. pager,
  154. ):
  155. json_dict = {
  156. 'owner': user.to_dict(),
  157. 'uid': self.uid,
  158. 'kind': self.kind,
  159. 'title': self.title,
  160. 'track_count': self.track_count,
  161. 'cover': cover.to_dict(),
  162. 'made_for': made_for.to_dict(),
  163. 'play_counter': play_counter.to_dict(),
  164. 'playlist_absence': playlist_absence.to_dict(),
  165. 'tags': self.tags,
  166. 'revision': self.revision,
  167. 'snapshot': self.snapshot,
  168. 'visibility': self.visibility,
  169. 'collective': self.collective,
  170. 'created': self.created,
  171. 'modified': self.modified,
  172. 'available': self.available,
  173. 'is_banner': self.is_banner,
  174. 'is_premiere': self.is_premiere,
  175. 'duration_ms': self.duration_ms,
  176. 'og_image': self.og_image,
  177. 'tracks': [track_short.to_dict()],
  178. 'prerolls': self.prerolls,
  179. 'likes_count': self.likes_count,
  180. 'generated_playlist_type': self.generated_playlist_type,
  181. 'url_part': self.url_part,
  182. 'animated_cover_uri': self.animated_cover_uri,
  183. 'ever_played': self.ever_played,
  184. 'description': self.description,
  185. 'description_formatted': self.description_formatted,
  186. 'is_for_from': self.is_for_from,
  187. 'regions': self.regions,
  188. 'og_title': self.og_title,
  189. 'image': self.image,
  190. 'id_for_from': self.id_for_from,
  191. 'background_color': self.background_color,
  192. 'text_color': self.text_color,
  193. 'cover_without_text': cover.to_dict(),
  194. 'coauthors': self.coauthors,
  195. 'similar_playlists': [playlist_without_nested_playlists.to_dict()],
  196. 'last_owner_playlists': [playlist_without_nested_playlists.to_dict()],
  197. 'og_description': self.og_description,
  198. 'top_artist': [artist.to_dict()],
  199. 'recent_tracks': [track_id.to_dict()],
  200. 'metrika_id': self.metrika_id,
  201. 'contest': contest.to_dict(),
  202. 'dummy_description': self.dummy_description,
  203. 'dummy_page_description': self.dummy_page_description,
  204. 'dummy_cover': cover.to_dict(),
  205. 'dummy_rollover_cover': cover.to_dict(),
  206. 'og_data': open_graph_data.to_dict(),
  207. 'branding': brand.to_dict(),
  208. 'playlist_uuid': self.playlist_uuid,
  209. 'type': self.type,
  210. 'ready': self.ready,
  211. 'custom_wave': custom_wave.to_dict(),
  212. 'pager': pager.to_dict(),
  213. }
  214. playlist = Playlist.de_json(json_dict, client)
  215. assert playlist.owner == user
  216. assert playlist.uid == self.uid
  217. assert playlist.kind == self.kind
  218. assert playlist.title == self.title
  219. assert playlist.track_count == self.track_count
  220. assert playlist.cover == cover
  221. assert playlist.made_for == made_for
  222. assert playlist.play_counter == play_counter
  223. assert playlist.playlist_absence == playlist_absence
  224. assert playlist.tags == self.tags
  225. assert playlist.revision == self.revision
  226. assert playlist.snapshot == self.snapshot
  227. assert playlist.visibility == self.visibility
  228. assert playlist.collective == self.collective
  229. assert playlist.url_part == self.url_part
  230. assert playlist.created == self.created
  231. assert playlist.modified == self.modified
  232. assert playlist.available == self.available
  233. assert playlist.is_banner == self.is_banner
  234. assert playlist.is_premiere == self.is_premiere
  235. assert playlist.duration_ms == self.duration_ms
  236. assert playlist.og_image == self.og_image
  237. assert playlist.og_title == self.og_title
  238. assert playlist.og_description == self.og_description
  239. assert playlist.image == self.image
  240. assert playlist.cover_without_text == cover
  241. assert playlist.contest == contest
  242. assert playlist.background_color == self.background_color
  243. assert playlist.text_color == self.text_color
  244. assert playlist.id_for_from == self.id_for_from
  245. assert playlist.dummy_description == self.dummy_description
  246. assert playlist.dummy_page_description == self.dummy_page_description
  247. assert playlist.dummy_cover == cover
  248. assert playlist.dummy_rollover_cover == cover
  249. assert playlist.og_data == open_graph_data
  250. assert playlist.branding == brand
  251. assert playlist.metrika_id == self.metrika_id
  252. assert playlist.coauthors == self.coauthors
  253. assert playlist.top_artist == [artist]
  254. assert playlist.recent_tracks == [track_id]
  255. assert playlist.tracks == [track_short]
  256. assert playlist.prerolls == self.prerolls
  257. assert playlist.likes_count == self.likes_count
  258. assert playlist.similar_playlists == [playlist_without_nested_playlists]
  259. assert playlist.last_owner_playlists == [playlist_without_nested_playlists]
  260. assert playlist.generated_playlist_type == self.generated_playlist_type
  261. assert playlist.animated_cover_uri == self.animated_cover_uri
  262. assert playlist.ever_played == self.ever_played
  263. assert playlist.description == self.description
  264. assert playlist.description_formatted == self.description_formatted
  265. assert playlist.playlist_uuid == self.playlist_uuid
  266. assert playlist.type == self.type
  267. assert playlist.ready == self.ready
  268. assert playlist.is_for_from == self.is_for_from
  269. assert playlist.regions == self.regions
  270. assert playlist.custom_wave == custom_wave
  271. assert playlist.pager == pager
  272. def test_equality(self, user, cover, made_for, play_counter, playlist_absence):
  273. a = Playlist(user, cover, made_for, play_counter, playlist_absence)
  274. b = Playlist(user, cover, made_for, play_counter, None)
  275. c = Playlist(user, None, made_for, play_counter, playlist_absence)
  276. d = Playlist(user, cover, made_for, play_counter, playlist_absence)
  277. assert a != b != c
  278. assert hash(a) != hash(b) != hash(c)
  279. assert a is not b is not c
  280. assert a == d