test_artist.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import pytest
  2. from yandex_music import Artist
  3. from yandex_music.exceptions import IdMissingError
  4. class TestArtist:
  5. id = 10987
  6. error = 'not-found'
  7. reason = 'not-found'
  8. name = 'Elvis Presley'
  9. various = False
  10. composer = None
  11. genres = None
  12. og_image = ''
  13. op_image = None
  14. no_pictures_from_search = None
  15. available = None
  16. tickets_available = False
  17. likes_count = 657469
  18. regions = None
  19. full_names = None
  20. hand_made_description = (
  21. 'Одна из самых популярных советских рок-групп 1980-х годов. Лидером, '
  22. 'автором практически всех текстов и музыки неизменно оставался Виктор Цой.'
  23. )
  24. countries = None
  25. en_wikipedia_link = None
  26. db_aliases = None
  27. aliases = None
  28. init_date = '1935-01-08'
  29. end_date = None
  30. ya_money_id = '4100170623944'
  31. def test_expected_values(
  32. self, artist, cover, counts, ratings, link, track_without_artists_and_albums, description, artist_decomposed
  33. ):
  34. assert artist.id == self.id
  35. assert artist.error == self.error
  36. assert artist.reason == self.reason
  37. assert artist.name == self.name
  38. assert artist.various == self.various
  39. assert artist.composer == self.composer
  40. assert artist.cover == cover
  41. assert artist.genres == self.genres
  42. assert artist.og_image == self.og_image
  43. assert artist.op_image == self.op_image
  44. assert artist.no_pictures_from_search == self.no_pictures_from_search
  45. assert artist.counts == counts
  46. assert artist.available == self.available
  47. assert artist.ratings == ratings
  48. assert artist.links == [link]
  49. assert artist.tickets_available == self.tickets_available
  50. assert artist.likes_count == self.likes_count
  51. assert artist.popular_tracks == [track_without_artists_and_albums]
  52. assert artist.regions == self.regions
  53. assert artist.decomposed == artist_decomposed
  54. assert artist.full_names == self.full_names
  55. assert artist.hand_made_description == self.hand_made_description
  56. assert artist.description == description
  57. assert artist.countries == self.countries
  58. assert artist.en_wikipedia_link == self.en_wikipedia_link
  59. assert artist.db_aliases == self.db_aliases
  60. assert artist.aliases == self.aliases
  61. assert artist.init_date == self.init_date
  62. assert artist.end_date == self.end_date
  63. assert artist.ya_money_id == self.ya_money_id
  64. def test_de_json_none(self, client):
  65. assert Artist.de_json({}, client) is None
  66. def test_de_list_none(self, client):
  67. assert Artist.de_list([], client) == []
  68. def test_de_json_required(self, client, cover):
  69. # We don't have any required fields anymore,
  70. # so just make sure we don't throw any errors.
  71. Artist.de_json({}, client)
  72. def test_de_json_ugc(self, client):
  73. # An example of UGC artist from #663
  74. artist = Artist.de_json({'name': self.name}, client)
  75. assert artist.name == self.name
  76. def test_de_json_all(
  77. self, client, cover, counts, ratings, link, track_without_artists, description, artist_decomposed
  78. ):
  79. artist_decomposed_dict = [item if isinstance(item, str) else item.to_dict() for item in artist_decomposed]
  80. json_dict = {
  81. 'id': self.id,
  82. 'reason': self.reason,
  83. 'error': self.error,
  84. 'name': self.name,
  85. 'various': self.various,
  86. 'composer': self.composer,
  87. 'cover': cover.to_dict(),
  88. 'genres': self.genres,
  89. 'op_image': self.op_image,
  90. 'og_image': self.og_image,
  91. 'no_pictures_from_search': self.no_pictures_from_search,
  92. 'counts': counts.to_dict(),
  93. 'available': self.available,
  94. 'ratings': ratings.to_dict(),
  95. 'links': [link.to_dict()],
  96. 'tickets_available': self.tickets_available,
  97. 'likes_count': self.likes_count,
  98. 'popular_tracks': [track_without_artists.to_dict()],
  99. 'regions': self.regions,
  100. 'decomposed': artist_decomposed_dict,
  101. 'full_names': self.full_names,
  102. 'description': description.to_dict(),
  103. 'countries': self.countries,
  104. 'en_wikipedia_link': self.en_wikipedia_link,
  105. 'db_aliases': self.db_aliases,
  106. 'aliases': self.aliases,
  107. 'init_date': self.init_date,
  108. 'end_date': self.end_date,
  109. 'hand_made_description': self.hand_made_description,
  110. 'ya_money_id': self.ya_money_id,
  111. }
  112. artist = Artist.de_json(json_dict, client)
  113. assert artist.id == self.id
  114. assert artist.error == self.error
  115. assert artist.reason == self.reason
  116. assert artist.name == self.name
  117. assert artist.various == self.various
  118. assert artist.composer == self.composer
  119. assert artist.cover == cover
  120. assert artist.genres == self.genres
  121. assert artist.og_image == self.og_image
  122. assert artist.op_image == self.op_image
  123. assert artist.no_pictures_from_search == self.no_pictures_from_search
  124. assert artist.counts == counts
  125. assert artist.available == self.available
  126. assert artist.ratings == ratings
  127. assert artist.links == [link]
  128. assert artist.tickets_available == self.tickets_available
  129. assert artist.likes_count == self.likes_count
  130. assert artist.popular_tracks == [track_without_artists]
  131. assert artist.regions == self.regions
  132. assert artist.decomposed == artist_decomposed
  133. assert artist.full_names == self.full_names
  134. assert artist.hand_made_description == self.hand_made_description
  135. assert artist.description == description
  136. assert artist.countries == self.countries
  137. assert artist.en_wikipedia_link == self.en_wikipedia_link
  138. assert artist.db_aliases == self.db_aliases
  139. assert artist.aliases == self.aliases
  140. assert artist.init_date == self.init_date
  141. assert artist.end_date == self.end_date
  142. assert artist.ya_money_id == self.ya_money_id
  143. def test_equality(self, cover):
  144. a = Artist(self.id)
  145. b = Artist(10)
  146. c = Artist(self.id)
  147. assert a != b
  148. assert hash(a) != hash(b)
  149. assert a is not b
  150. assert a == c
  151. def test_id_required(self, client):
  152. artist = Artist.de_json({'name': self.name}, client)
  153. # Make sure we throw an error if we try to access the id_required property when id is None
  154. with pytest.raises(IdMissingError):
  155. _ = artist.id_required