test_landing_list.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import pytest
  2. from yandex_music import LandingList
  3. @pytest.fixture(scope='class')
  4. def landing_list(playlist_id):
  5. return LandingList(
  6. TestLandingList.type,
  7. TestLandingList.type_for_from,
  8. TestLandingList.title,
  9. TestLandingList.id,
  10. TestLandingList.new_releases,
  11. [playlist_id],
  12. TestLandingList.podcasts,
  13. )
  14. class TestLandingList:
  15. id = 'fNdCYuAs'
  16. title = 'Новые треки, альбомы и сборники'
  17. type = 'new-releases'
  18. type_for_from = 'new-releases'
  19. new_releases = [10704986, 10527291, 9479589]
  20. podcasts = [10532030, 8693523, 10509632]
  21. def test_expected_values(self, landing_list, playlist_id):
  22. assert landing_list.id == self.id
  23. assert landing_list.title == self.title
  24. assert landing_list.type == self.type
  25. assert landing_list.type_for_from == self.type_for_from
  26. assert landing_list.new_releases == self.new_releases
  27. assert landing_list.podcasts == self.podcasts
  28. assert landing_list.new_playlists == [playlist_id]
  29. def test_de_json_none(self, client):
  30. assert LandingList.de_json({}, client) is None
  31. def test_de_json_required(self, client):
  32. json_dict = {'title': self.title, 'type': self.type, 'type_for_from': self.type_for_from}
  33. landing_list = LandingList.de_json(json_dict, client)
  34. assert landing_list.title == self.title
  35. assert landing_list.type == self.type
  36. assert landing_list.type_for_from == self.type_for_from
  37. def test_de_json_all(self, client, playlist_id):
  38. json_dict = {
  39. 'title': self.title,
  40. 'type': self.type,
  41. 'type_for_from': self.type_for_from,
  42. 'id': self.id,
  43. 'new_releases': self.new_releases,
  44. 'podcasts': self.podcasts,
  45. 'new_playlists': [playlist_id.to_dict()],
  46. }
  47. landing_list = LandingList.de_json(json_dict, client)
  48. assert landing_list.id == self.id
  49. assert landing_list.title == self.title
  50. assert landing_list.type == self.type
  51. assert landing_list.type_for_from == self.type_for_from
  52. assert landing_list.new_releases == self.new_releases
  53. assert landing_list.podcasts == self.podcasts
  54. assert landing_list.new_playlists == [playlist_id]
  55. def test_equality(self, playlist_id):
  56. a = LandingList(self.type, self.type_for_from, self.title, self.id, self.new_releases, [playlist_id], [])
  57. b = LandingList(self.type, self.type_for_from, self.title, self.id, self.new_releases, [], [])
  58. c = LandingList(self.type, self.type_for_from, self.title, '', self.new_releases, [playlist_id], [])
  59. d = LandingList(self.type, self.type_for_from, self.title, self.id, self.new_releases, [playlist_id], [])
  60. assert a != b != c
  61. assert hash(a) != hash(b) != hash(c)
  62. assert a is not b is not c
  63. assert a == d