test_track.py 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. from yandex_music import Track
  2. class TestTrack:
  3. id = '10994777'
  4. title = 'Sapphire'
  5. available = True
  6. available_for_premium_users = True
  7. lyrics_available = False
  8. best = False
  9. real_id = '10994777'
  10. og_image = 'avatars.yandex.net/get-music-content/28589/daef4251.a.1193829-1/%%'
  11. type = 'music'
  12. cover_uri = 'avatars.yandex.net/get-music-content/28589/daef4251.a.1193829-1/%%'
  13. duration_ms = 251270
  14. storage_dir = '51327_109b74ca.36526310.1.609676'
  15. file_size = 6036792
  16. error = None
  17. can_publish = False
  18. state = 'playable'
  19. desired_visibility = 'private'
  20. filename = 'Ты не так плох.mp3'
  21. regions = None
  22. available_as_rbt = None
  23. content_warning = None
  24. explicit = None
  25. preview_duration_ms = 30000
  26. available_full_without_permission = False
  27. version = 'Radio Edit'
  28. remember_position = False
  29. background_video_uri = 'https://music-background-videos.s3.yandex.net/converted/60018e4cdcaa9a42948cda8d'
  30. short_description = (
  31. 'По каким признакам во внешности, в поведении, в одежде можно понять, что девушка несвободна?'
  32. ' Чтобы не ошибиться со своими чувствами и устремлениями…» — такой замечательный вопрос'
  33. ' пришел мне от подписчика. Причин, которые могут остановить мужчин в момент появления'
  34. ' желания познакомиться с девушкой, достаточно много. Обычно они сводятся к опасениям,'
  35. )
  36. is_suitable_for_children = True
  37. track_source = 'OWN'
  38. available_for_options = ['bookmate']
  39. track_sharing_flag = 'VIDEO_ALLOWED'
  40. def test_expected_values(
  41. self,
  42. track,
  43. artist,
  44. album,
  45. major,
  46. normalization,
  47. track_without_nested_tracks,
  48. user,
  49. meta_data,
  50. poetry_lover_match,
  51. r_128,
  52. lyrics_info,
  53. ):
  54. assert track.id == self.id
  55. assert track.title == self.title
  56. assert track.available == self.available
  57. assert track.available_for_premium_users == self.available_for_premium_users
  58. assert track.artists == [artist]
  59. assert track.albums == [album]
  60. assert track.lyrics_available == self.lyrics_available
  61. assert track.poetry_lover_matches == [poetry_lover_match]
  62. assert track.best == self.best
  63. assert track.real_id == self.real_id
  64. assert track.og_image == self.og_image
  65. assert track.type == self.type
  66. assert track.cover_uri == self.cover_uri
  67. assert track.major == major
  68. assert track.duration_ms == self.duration_ms
  69. assert track.storage_dir == self.storage_dir
  70. assert track.file_size == self.file_size
  71. assert track.substituted == track_without_nested_tracks
  72. assert track.matched_track == track_without_nested_tracks
  73. assert track.normalization == normalization
  74. assert track.error == self.error
  75. assert track.meta_data == meta_data
  76. assert track.regions == self.regions
  77. assert track.available_as_rbt == self.available_as_rbt
  78. assert track.content_warning == self.content_warning
  79. assert track.explicit == self.explicit
  80. assert track.preview_duration_ms == self.preview_duration_ms
  81. assert track.available_full_without_permission == self.available_full_without_permission
  82. assert track.version == self.version
  83. assert track.remember_position == self.remember_position
  84. assert track.can_publish == self.can_publish
  85. assert track.state == self.state
  86. assert track.desired_visibility == self.desired_visibility
  87. assert track.filename == self.filename
  88. assert track.user_info == user
  89. assert track.background_video_uri == self.background_video_uri
  90. assert track.short_description == self.short_description
  91. assert track.is_suitable_for_children == self.is_suitable_for_children
  92. assert track.track_source == self.track_source
  93. assert track.available_for_options == self.available_for_options
  94. assert track.r128 == r_128
  95. assert track.lyrics_info == lyrics_info
  96. assert track.track_sharing_flag == self.track_sharing_flag
  97. def test_de_json_none(self, client):
  98. assert Track.de_json({}, client) is None
  99. def test_de_list_none(self, client):
  100. assert Track.de_list([], client) == []
  101. def test_de_json_required(self, client, artist, album):
  102. json_dict = {'id': self.id}
  103. track = Track.de_json(json_dict, client)
  104. assert track.id == self.id
  105. def test_de_json_all(
  106. self,
  107. client,
  108. artist,
  109. album,
  110. major,
  111. normalization,
  112. track_without_nested_tracks,
  113. user,
  114. meta_data,
  115. poetry_lover_match,
  116. r_128,
  117. lyrics_info,
  118. ):
  119. json_dict = {
  120. 'id': self.id,
  121. 'title': self.title,
  122. 'available': self.available,
  123. 'available_for_premium_users': self.available_for_premium_users,
  124. 'artists': [artist.to_dict()],
  125. 'albums': [album.to_dict()],
  126. 'lyrics_available': self.lyrics_available,
  127. 'best': self.best,
  128. 'real_id': self.real_id,
  129. 'og_image': self.og_image,
  130. 'type': self.type,
  131. 'cover_uri': self.cover_uri,
  132. 'major': major.to_dict(),
  133. 'duration_ms': self.duration_ms,
  134. 'storage_dir': self.storage_dir,
  135. 'file_size': self.file_size,
  136. 'normalization': normalization.to_dict(),
  137. 'error': self.error,
  138. 'regions': self.regions,
  139. 'available_as_rbt': self.available_as_rbt,
  140. 'content_warning': self.content_warning,
  141. 'explicit': self.explicit,
  142. 'preview_duration_ms': self.preview_duration_ms,
  143. 'version': self.version,
  144. 'available_full_without_permission': self.available_full_without_permission,
  145. 'remember_position': self.remember_position,
  146. 'substituted': track_without_nested_tracks.to_dict(),
  147. 'matched_track': track_without_nested_tracks.to_dict(),
  148. 'can_publish': self.can_publish,
  149. 'state': self.state,
  150. 'desired_visibility': self.desired_visibility,
  151. 'filename': self.filename,
  152. 'user_info': user.to_dict(),
  153. 'meta_data': meta_data.to_dict(),
  154. 'poetry_lover_matches': [poetry_lover_match.to_dict()],
  155. 'background_video_uri': self.background_video_uri,
  156. 'short_description': self.short_description,
  157. 'is_suitable_for_children': self.is_suitable_for_children,
  158. 'track_source': self.track_source,
  159. 'available_for_options': self.available_for_options,
  160. 'r128': r_128.to_dict(),
  161. 'lyrics_info': lyrics_info.to_dict(),
  162. 'track_sharing_flag': self.track_sharing_flag,
  163. }
  164. track = Track.de_json(json_dict, client)
  165. assert track.id == self.id
  166. assert track.title == self.title
  167. assert track.available == self.available
  168. assert track.available_for_premium_users == self.available_for_premium_users
  169. assert track.artists == [artist]
  170. assert track.albums == [album]
  171. assert track.lyrics_available == self.lyrics_available
  172. assert track.poetry_lover_matches == [poetry_lover_match]
  173. assert track.best == self.best
  174. assert track.real_id == self.real_id
  175. assert track.og_image == self.og_image
  176. assert track.type == self.type
  177. assert track.cover_uri == self.cover_uri
  178. assert track.major == major
  179. assert track.duration_ms == self.duration_ms
  180. assert track.storage_dir == self.storage_dir
  181. assert track.file_size == self.file_size
  182. assert track.substituted == track_without_nested_tracks
  183. assert track.matched_track == track_without_nested_tracks
  184. assert track.normalization == normalization
  185. assert track.error == self.error
  186. assert track.meta_data == meta_data
  187. assert track.regions == self.regions
  188. assert track.available_as_rbt == self.available_as_rbt
  189. assert track.content_warning == self.content_warning
  190. assert track.explicit == self.explicit
  191. assert track.preview_duration_ms == self.preview_duration_ms
  192. assert track.available_full_without_permission == self.available_full_without_permission
  193. assert track.version == self.version
  194. assert track.remember_position == self.remember_position
  195. assert track.can_publish == self.can_publish
  196. assert track.state == self.state
  197. assert track.desired_visibility == self.desired_visibility
  198. assert track.filename == self.filename
  199. assert track.user_info == user
  200. assert track.background_video_uri == self.background_video_uri
  201. assert track.short_description == self.short_description
  202. assert track.is_suitable_for_children == self.is_suitable_for_children
  203. assert track.track_source == self.track_source
  204. assert track.available_for_options == self.available_for_options
  205. assert track.r128 == r_128
  206. assert track.lyrics_info == lyrics_info
  207. assert track.track_sharing_flag == self.track_sharing_flag
  208. def test_equality(self):
  209. a = Track(self.id)
  210. b = Track(10)
  211. c = Track(self.id)
  212. assert a != b
  213. assert hash(a) != hash(b)
  214. assert a is not b
  215. assert a == c