test_user_settings.py 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. import pytest
  2. from yandex_music import UserSettings
  3. @pytest.fixture(scope='class')
  4. def user_settings(shot):
  5. return UserSettings(
  6. TestUserSettings.uid,
  7. TestUserSettings.last_fm_scrobbling_enabled,
  8. TestUserSettings.shuffle_enabled,
  9. TestUserSettings.volume_percents,
  10. TestUserSettings.modified,
  11. TestUserSettings.facebook_scrobbling_enabled,
  12. TestUserSettings.add_new_track_on_playlist_top,
  13. TestUserSettings.user_music_visibility,
  14. TestUserSettings.user_social_visibility,
  15. TestUserSettings.rbt_disabled,
  16. TestUserSettings.theme,
  17. TestUserSettings.promos_disabled,
  18. TestUserSettings.auto_play_radio,
  19. TestUserSettings.sync_queue_enabled,
  20. TestUserSettings.ads_disabled,
  21. TestUserSettings.disk_enabled,
  22. TestUserSettings.show_disk_tracks_in_library,
  23. )
  24. class TestUserSettings:
  25. uid = 1130000002804400
  26. last_fm_scrobbling_enabled = False
  27. shuffle_enabled = False
  28. volume_percents = 70
  29. modified = '2020-01-25T22:52:21+00:00'
  30. facebook_scrobbling_enabled = False
  31. add_new_track_on_playlist_top = False
  32. user_music_visibility = 'public'
  33. user_social_visibility = 'public'
  34. rbt_disabled = False
  35. theme = 'black'
  36. promos_disabled = True
  37. auto_play_radio = True
  38. sync_queue_enabled = True
  39. ads_disabled = None
  40. disk_enabled = False
  41. show_disk_tracks_in_library = False
  42. def test_expected_values(self, user_settings):
  43. assert user_settings.uid == self.uid
  44. assert user_settings.last_fm_scrobbling_enabled == self.last_fm_scrobbling_enabled
  45. assert user_settings.shuffle_enabled == self.shuffle_enabled
  46. assert user_settings.volume_percents == self.volume_percents
  47. assert user_settings.modified == self.modified
  48. assert user_settings.facebook_scrobbling_enabled == self.facebook_scrobbling_enabled
  49. assert user_settings.add_new_track_on_playlist_top == self.add_new_track_on_playlist_top
  50. assert user_settings.user_music_visibility == self.user_music_visibility
  51. assert user_settings.user_social_visibility == self.user_social_visibility
  52. assert user_settings.rbt_disabled == self.rbt_disabled
  53. assert user_settings.theme == self.theme
  54. assert user_settings.promos_disabled == self.promos_disabled
  55. assert user_settings.auto_play_radio == self.auto_play_radio
  56. assert user_settings.sync_queue_enabled == self.sync_queue_enabled
  57. assert user_settings.ads_disabled == self.ads_disabled
  58. assert user_settings.disk_enabled == self.disk_enabled
  59. assert user_settings.show_disk_tracks_in_library == self.show_disk_tracks_in_library
  60. def test_de_json_none(self, client):
  61. assert UserSettings.de_json({}, client) is None
  62. def test_de_json_required(self, client):
  63. json_dict = {
  64. 'uid': self.uid,
  65. 'last_fm_scrobbling_enabled': self.last_fm_scrobbling_enabled,
  66. 'shuffle_enabled': self.shuffle_enabled,
  67. 'volume_percents': self.volume_percents,
  68. 'modified': self.modified,
  69. 'facebook_scrobbling_enabled': self.facebook_scrobbling_enabled,
  70. 'add_new_track_on_playlist_top': self.add_new_track_on_playlist_top,
  71. 'user_music_visibility': self.user_music_visibility,
  72. 'user_social_visibility': self.user_social_visibility,
  73. 'rbt_disabled': self.rbt_disabled,
  74. 'theme': self.theme,
  75. 'promos_disabled': self.promos_disabled,
  76. 'auto_play_radio': self.auto_play_radio,
  77. 'sync_queue_enabled': self.sync_queue_enabled,
  78. }
  79. user_settings = UserSettings.de_json(json_dict, client)
  80. assert user_settings.uid == self.uid
  81. assert user_settings.last_fm_scrobbling_enabled == self.last_fm_scrobbling_enabled
  82. assert user_settings.shuffle_enabled == self.shuffle_enabled
  83. assert user_settings.volume_percents == self.volume_percents
  84. assert user_settings.modified == self.modified
  85. assert user_settings.facebook_scrobbling_enabled == self.facebook_scrobbling_enabled
  86. assert user_settings.add_new_track_on_playlist_top == self.add_new_track_on_playlist_top
  87. assert user_settings.user_music_visibility == self.user_music_visibility
  88. assert user_settings.user_social_visibility == self.user_social_visibility
  89. assert user_settings.rbt_disabled == self.rbt_disabled
  90. assert user_settings.theme == self.theme
  91. assert user_settings.promos_disabled == self.promos_disabled
  92. assert user_settings.auto_play_radio == self.auto_play_radio
  93. assert user_settings.sync_queue_enabled == self.sync_queue_enabled
  94. def test_de_json_all(self, client):
  95. json_dict = {
  96. 'uid': self.uid,
  97. 'last_fm_scrobbling_enabled': self.last_fm_scrobbling_enabled,
  98. 'shuffle_enabled': self.shuffle_enabled,
  99. 'volume_percents': self.volume_percents,
  100. 'modified': self.modified,
  101. 'facebook_scrobbling_enabled': self.facebook_scrobbling_enabled,
  102. 'add_new_track_on_playlist_top': self.add_new_track_on_playlist_top,
  103. 'user_music_visibility': self.user_music_visibility,
  104. 'user_social_visibility': self.user_social_visibility,
  105. 'rbt_disabled': self.rbt_disabled,
  106. 'theme': self.theme,
  107. 'promos_disabled': self.promos_disabled,
  108. 'auto_play_radio': self.auto_play_radio,
  109. 'sync_queue_enabled': self.sync_queue_enabled,
  110. 'ads_disabled': self.ads_disabled,
  111. 'disk_enabled': self.disk_enabled,
  112. 'show_disk_tracks_in_library': self.show_disk_tracks_in_library,
  113. }
  114. user_settings = UserSettings.de_json(json_dict, client)
  115. assert user_settings.uid == self.uid
  116. assert user_settings.last_fm_scrobbling_enabled == self.last_fm_scrobbling_enabled
  117. assert user_settings.shuffle_enabled == self.shuffle_enabled
  118. assert user_settings.volume_percents == self.volume_percents
  119. assert user_settings.modified == self.modified
  120. assert user_settings.facebook_scrobbling_enabled == self.facebook_scrobbling_enabled
  121. assert user_settings.add_new_track_on_playlist_top == self.add_new_track_on_playlist_top
  122. assert user_settings.user_music_visibility == self.user_music_visibility
  123. assert user_settings.user_social_visibility == self.user_social_visibility
  124. assert user_settings.rbt_disabled == self.rbt_disabled
  125. assert user_settings.theme == self.theme
  126. assert user_settings.promos_disabled == self.promos_disabled
  127. assert user_settings.auto_play_radio == self.auto_play_radio
  128. assert user_settings.sync_queue_enabled == self.sync_queue_enabled
  129. assert user_settings.ads_disabled == self.ads_disabled
  130. assert user_settings.disk_enabled == self.disk_enabled
  131. assert user_settings.show_disk_tracks_in_library == self.show_disk_tracks_in_library
  132. def test_equality(self):
  133. a = UserSettings(
  134. self.uid,
  135. self.last_fm_scrobbling_enabled,
  136. self.shuffle_enabled,
  137. self.volume_percents,
  138. self.modified,
  139. self.facebook_scrobbling_enabled,
  140. self.add_new_track_on_playlist_top,
  141. self.user_music_visibility,
  142. self.user_social_visibility,
  143. self.rbt_disabled,
  144. self.theme,
  145. self.promos_disabled,
  146. self.auto_play_radio,
  147. self.sync_queue_enabled,
  148. self.ads_disabled,
  149. self.disk_enabled,
  150. self.show_disk_tracks_in_library,
  151. )
  152. b = UserSettings(
  153. self.uid,
  154. self.last_fm_scrobbling_enabled,
  155. self.shuffle_enabled,
  156. self.volume_percents,
  157. self.modified,
  158. self.facebook_scrobbling_enabled,
  159. self.add_new_track_on_playlist_top,
  160. 'private',
  161. self.user_social_visibility,
  162. self.rbt_disabled,
  163. 'white',
  164. self.promos_disabled,
  165. self.auto_play_radio,
  166. self.sync_queue_enabled,
  167. self.ads_disabled,
  168. True,
  169. self.show_disk_tracks_in_library,
  170. )
  171. c = UserSettings(
  172. self.uid,
  173. self.last_fm_scrobbling_enabled,
  174. self.shuffle_enabled,
  175. self.volume_percents,
  176. self.modified,
  177. self.facebook_scrobbling_enabled,
  178. self.add_new_track_on_playlist_top,
  179. self.user_music_visibility,
  180. self.user_social_visibility,
  181. self.rbt_disabled,
  182. self.theme,
  183. self.promos_disabled,
  184. self.auto_play_radio,
  185. self.sync_queue_enabled,
  186. self.ads_disabled,
  187. self.disk_enabled,
  188. self.show_disk_tracks_in_library,
  189. )
  190. assert a != b != c
  191. assert hash(a) != hash(b) != hash(c)
  192. assert a is not b is not c
  193. assert a == c
  194. assert hash(a) == hash(c)