test_promotion.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. from yandex_music import Promotion
  2. class TestPromotion:
  3. promo_id = '5db861cfa6245a2c8c63445d'
  4. title = '«Никакого андеграунда!»'
  5. subtitle = 'на новой пластинке группы «Папин Олимпос»'
  6. heading = 'Мини-альбом'
  7. url = '/album/8839440'
  8. url_scheme = 'yandexmusic://album/8839440'
  9. text_color = ''
  10. gradient = ''
  11. image = 'avatars.yandex.net/get-music-feed-promotion/69892/5db861cfa6245a2c8c63445d-landing.image/%%'
  12. def test_expected_values(self, promotion):
  13. assert promotion.promo_id == self.promo_id
  14. assert promotion.title == self.title
  15. assert promotion.subtitle == self.subtitle
  16. assert promotion.heading == self.heading
  17. assert promotion.url == self.url
  18. assert promotion.url_scheme == self.url_scheme
  19. assert promotion.text_color == self.text_color
  20. assert promotion.gradient == self.gradient
  21. assert promotion.image == self.image
  22. def test_de_list_none(self, client):
  23. assert Promotion.de_list([], client) == []
  24. def test_de_json_none(self, client):
  25. assert Promotion.de_json({}, client) is None
  26. def test_de_json_required(self, client):
  27. json_dict = {
  28. 'promo_id': self.promo_id,
  29. 'title': self.title,
  30. 'subtitle': self.subtitle,
  31. 'heading': self.heading,
  32. 'url': self.url,
  33. 'url_scheme': self.url_scheme,
  34. 'text_color': self.text_color,
  35. 'gradient': self.gradient,
  36. 'image': self.image,
  37. }
  38. promotion = Promotion.de_json(json_dict, client)
  39. assert promotion.promo_id == self.promo_id
  40. assert promotion.title == self.title
  41. assert promotion.subtitle == self.subtitle
  42. assert promotion.heading == self.heading
  43. assert promotion.url == self.url
  44. assert promotion.url_scheme == self.url_scheme
  45. assert promotion.text_color == self.text_color
  46. assert promotion.gradient == self.gradient
  47. assert promotion.image == self.image
  48. def test_de_json_all(self, client):
  49. json_dict = {
  50. 'promo_id': self.promo_id,
  51. 'title': self.title,
  52. 'subtitle': self.subtitle,
  53. 'heading': self.heading,
  54. 'url': self.url,
  55. 'url_scheme': self.url_scheme,
  56. 'text_color': self.text_color,
  57. 'gradient': self.gradient,
  58. 'image': self.image,
  59. }
  60. promotion = Promotion.de_json(json_dict, client)
  61. assert promotion.promo_id == self.promo_id
  62. assert promotion.title == self.title
  63. assert promotion.subtitle == self.subtitle
  64. assert promotion.heading == self.heading
  65. assert promotion.url == self.url
  66. assert promotion.url_scheme == self.url_scheme
  67. assert promotion.text_color == self.text_color
  68. assert promotion.gradient == self.gradient
  69. assert promotion.image == self.image
  70. def test_equality(self):
  71. a = Promotion(
  72. self.promo_id,
  73. self.title,
  74. self.subtitle,
  75. self.heading,
  76. self.url,
  77. self.url_scheme,
  78. self.text_color,
  79. self.gradient,
  80. self.image,
  81. )
  82. b = Promotion(
  83. '', self.title, self.subtitle, '', self.url, self.url_scheme, self.text_color, self.gradient, self.image
  84. )
  85. c = Promotion(
  86. self.promo_id,
  87. '',
  88. self.subtitle,
  89. self.heading,
  90. self.url,
  91. self.url_scheme,
  92. self.text_color,
  93. self.gradient,
  94. '',
  95. )
  96. d = Promotion(
  97. self.promo_id,
  98. self.title,
  99. self.subtitle,
  100. self.heading,
  101. self.url,
  102. self.url_scheme,
  103. self.text_color,
  104. self.gradient,
  105. self.image,
  106. )
  107. assert a != b != c
  108. assert hash(a) != hash(b) != hash(c)
  109. assert a is not b is not c
  110. assert a == d