test_feed.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import pytest
  2. from yandex_music import Feed
  3. @pytest.fixture(scope='class')
  4. def feed(generated_playlist, day):
  5. return Feed(
  6. TestFeed.can_get_more_events,
  7. TestFeed.pumpkin,
  8. TestFeed.is_wizard_passed,
  9. [generated_playlist],
  10. TestFeed.headlines,
  11. TestFeed.today,
  12. [day],
  13. TestFeed.next_revision,
  14. )
  15. class TestFeed:
  16. can_get_more_events = True
  17. pumpkin = False
  18. is_wizard_passed = True
  19. headlines = []
  20. today = '2019-11-09'
  21. next_revision = '2019-11-08'
  22. def test_expected_values(self, feed, generated_playlist, day):
  23. assert feed.can_get_more_events == self.can_get_more_events
  24. assert feed.pumpkin == self.pumpkin
  25. assert feed.is_wizard_passed == self.is_wizard_passed
  26. assert feed.generated_playlists == [generated_playlist]
  27. assert feed.headlines == self.headlines
  28. assert feed.today == self.today
  29. assert feed.days == [day]
  30. assert feed.next_revision == self.next_revision
  31. def test_de_json_none(self, client):
  32. assert Feed.de_json({}, client) is None
  33. def test_de_json_required(self, client, generated_playlist, day):
  34. json_dict = {
  35. 'can_get_more_events': self.can_get_more_events,
  36. 'pumpkin': self.pumpkin,
  37. 'is_wizard_passed': self.is_wizard_passed,
  38. 'generated_playlists': [generated_playlist.to_dict()],
  39. 'headlines': self.headlines,
  40. 'today': self.today,
  41. 'days': [day.to_dict()],
  42. }
  43. feed = Feed.de_json(json_dict, client)
  44. assert feed.can_get_more_events == self.can_get_more_events
  45. assert feed.pumpkin == self.pumpkin
  46. assert feed.is_wizard_passed == self.is_wizard_passed
  47. assert feed.generated_playlists == [generated_playlist]
  48. assert feed.headlines == self.headlines
  49. assert feed.today == self.today
  50. assert feed.days == [day]
  51. def test_de_json_all(self, client, generated_playlist, day):
  52. json_dict = {
  53. 'can_get_more_events': self.can_get_more_events,
  54. 'pumpkin': self.pumpkin,
  55. 'is_wizard_passed': self.is_wizard_passed,
  56. 'generated_playlists': [generated_playlist.to_dict()],
  57. 'headlines': self.headlines,
  58. 'today': self.today,
  59. 'days': [day.to_dict()],
  60. 'next_revision': self.next_revision,
  61. }
  62. feed = Feed.de_json(json_dict, client)
  63. assert feed.can_get_more_events == self.can_get_more_events
  64. assert feed.pumpkin == self.pumpkin
  65. assert feed.is_wizard_passed == self.is_wizard_passed
  66. assert feed.generated_playlists == [generated_playlist]
  67. assert feed.headlines == self.headlines
  68. assert feed.today == self.today
  69. assert feed.days == [day]
  70. assert feed.next_revision == self.next_revision
  71. def test_equality(self, generated_playlist, day):
  72. a = Feed(
  73. self.can_get_more_events,
  74. self.pumpkin,
  75. self.is_wizard_passed,
  76. [generated_playlist],
  77. self.headlines,
  78. self.today,
  79. [day],
  80. )
  81. b = Feed(False, self.pumpkin, self.is_wizard_passed, [], self.headlines, self.today, [day])
  82. c = Feed(
  83. self.can_get_more_events,
  84. self.pumpkin,
  85. self.is_wizard_passed,
  86. [generated_playlist],
  87. self.headlines,
  88. self.today,
  89. [day],
  90. )
  91. assert a != b
  92. assert hash(a) != hash(b)
  93. assert a is not b
  94. assert a == c