test_vinyl.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. from yandex_music import Vinyl
  2. class TestVinyl:
  3. url = 'http://www.ozon.ru/context/detail/id/29504873/?partner=yandexmusic'
  4. picture = 'avatars.yandex.net/get-music-misc/2413828/vinyl.29504873image/%%'
  5. title = 'The Prodigy.Their Law The Singles 1990-2005 (2 LP)'
  6. year = 2005
  7. media = '2 Грампластинка (LP)'
  8. price = 4483
  9. offer_id = 28640019
  10. artist_ids = [4, 24326, 618511, 2643503]
  11. def test_expected_values(self, vinyl):
  12. assert vinyl.url == self.url
  13. assert vinyl.picture == self.picture
  14. assert vinyl.title == self.title
  15. assert vinyl.year == self.year
  16. assert vinyl.price == self.price
  17. assert vinyl.media == self.media
  18. assert vinyl.offer_id == self.offer_id
  19. assert vinyl.artist_ids == self.artist_ids
  20. def test_de_json_none(self, client):
  21. assert Vinyl.de_json({}, client) is None
  22. def test_de_list_none(self, client):
  23. assert Vinyl.de_list([], client) == []
  24. def test_de_json_required(self, client):
  25. json_dict = {
  26. 'url': self.url,
  27. 'title': self.title,
  28. 'year': self.year,
  29. 'price': self.price,
  30. 'media': self.media,
  31. 'offer_id': self.offer_id,
  32. 'artist_ids': self.artist_ids,
  33. }
  34. vinyl = Vinyl.de_json(json_dict, client)
  35. assert vinyl.url == self.url
  36. assert vinyl.title == self.title
  37. assert vinyl.year == self.year
  38. assert vinyl.price == self.price
  39. assert vinyl.media == self.media
  40. assert vinyl.offer_id == self.offer_id
  41. assert vinyl.artist_ids == self.artist_ids
  42. def test_de_json_all(self, client):
  43. json_dict = {
  44. 'url': self.url,
  45. 'picture': self.picture,
  46. 'title': self.title,
  47. 'year': self.year,
  48. 'price': self.price,
  49. 'media': self.media,
  50. 'offer_id': self.offer_id,
  51. 'artist_ids': self.artist_ids,
  52. }
  53. vinyl = Vinyl.de_json(json_dict, client)
  54. assert vinyl.url == self.url
  55. assert vinyl.picture == self.picture
  56. assert vinyl.title == self.title
  57. assert vinyl.year == self.year
  58. assert vinyl.price == self.price
  59. assert vinyl.media == self.media
  60. assert vinyl.offer_id == self.offer_id
  61. assert vinyl.artist_ids == self.artist_ids
  62. def test_equality(self):
  63. a = Vinyl(self.url, self.title, 2020, 200, self.media, self.offer_id, [10])
  64. b = Vinyl(self.url, self.title, self.year, self.price, self.media, self.offer_id, self.artist_ids)
  65. c = Vinyl(self.url, self.title, self.year, self.price, self.media, self.offer_id, self.artist_ids)
  66. assert a != b
  67. assert hash(a) != hash(b)
  68. assert a is not b
  69. assert b == c