2019-11-08 02:09:39 +09:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
from yandex_music import Feed
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='class')
|
2019-11-10 05:59:22 +09:00
|
|
|
def feed(generated_playlist, day):
|
2021-02-03 21:28:10 +09:00
|
|
|
return Feed(
|
|
|
|
TestFeed.can_get_more_events,
|
|
|
|
TestFeed.pumpkin,
|
|
|
|
TestFeed.is_wizard_passed,
|
|
|
|
[generated_playlist],
|
|
|
|
TestFeed.headlines,
|
|
|
|
TestFeed.today,
|
|
|
|
[day],
|
|
|
|
TestFeed.next_revision,
|
|
|
|
)
|
2019-11-08 02:09:39 +09:00
|
|
|
|
|
|
|
|
|
|
|
class TestFeed:
|
2019-11-10 05:59:22 +09:00
|
|
|
can_get_more_events = True
|
|
|
|
pumpkin = False
|
|
|
|
is_wizard_passed = True
|
|
|
|
headlines = []
|
|
|
|
today = '2019-11-09'
|
|
|
|
next_revision = '2019-11-08'
|
|
|
|
|
|
|
|
def test_expected_values(self, feed, generated_playlist, day):
|
2019-11-08 02:09:39 +09:00
|
|
|
assert feed.can_get_more_events == self.can_get_more_events
|
|
|
|
assert feed.pumpkin == self.pumpkin
|
|
|
|
assert feed.is_wizard_passed == self.is_wizard_passed
|
2019-11-10 05:59:22 +09:00
|
|
|
assert feed.generated_playlists == [generated_playlist]
|
2019-11-08 02:09:39 +09:00
|
|
|
assert feed.headlines == self.headlines
|
|
|
|
assert feed.today == self.today
|
2019-11-10 05:59:22 +09:00
|
|
|
assert feed.days == [day]
|
2019-11-08 02:09:39 +09:00
|
|
|
assert feed.next_revision == self.next_revision
|
|
|
|
|
2019-12-29 16:38:24 +09:00
|
|
|
def test_de_json_none(self, client):
|
|
|
|
assert Feed.de_json({}, client) is None
|
|
|
|
|
2019-11-10 05:59:22 +09:00
|
|
|
def test_de_json_required(self, client, generated_playlist, day):
|
2021-02-03 21:28:10 +09:00
|
|
|
json_dict = {
|
|
|
|
'can_get_more_events': self.can_get_more_events,
|
|
|
|
'pumpkin': self.pumpkin,
|
|
|
|
'is_wizard_passed': self.is_wizard_passed,
|
|
|
|
'generated_playlists': [generated_playlist.to_dict()],
|
|
|
|
'headlines': self.headlines,
|
|
|
|
'today': self.today,
|
|
|
|
'days': [day.to_dict()],
|
|
|
|
}
|
2019-11-08 02:09:39 +09:00
|
|
|
feed = Feed.de_json(json_dict, client)
|
|
|
|
|
|
|
|
assert feed.can_get_more_events == self.can_get_more_events
|
|
|
|
assert feed.pumpkin == self.pumpkin
|
|
|
|
assert feed.is_wizard_passed == self.is_wizard_passed
|
2019-11-10 05:59:22 +09:00
|
|
|
assert feed.generated_playlists == [generated_playlist]
|
2019-11-08 02:09:39 +09:00
|
|
|
assert feed.headlines == self.headlines
|
|
|
|
assert feed.today == self.today
|
2019-11-10 05:59:22 +09:00
|
|
|
assert feed.days == [day]
|
2019-11-08 02:09:39 +09:00
|
|
|
|
2019-11-10 05:59:22 +09:00
|
|
|
def test_de_json_all(self, client, generated_playlist, day):
|
2021-02-03 21:28:10 +09:00
|
|
|
json_dict = {
|
|
|
|
'can_get_more_events': self.can_get_more_events,
|
|
|
|
'pumpkin': self.pumpkin,
|
|
|
|
'is_wizard_passed': self.is_wizard_passed,
|
|
|
|
'generated_playlists': [generated_playlist.to_dict()],
|
|
|
|
'headlines': self.headlines,
|
|
|
|
'today': self.today,
|
|
|
|
'days': [day.to_dict()],
|
|
|
|
'next_revision': self.next_revision,
|
|
|
|
}
|
2019-11-08 02:09:39 +09:00
|
|
|
feed = Feed.de_json(json_dict, client)
|
|
|
|
|
|
|
|
assert feed.can_get_more_events == self.can_get_more_events
|
|
|
|
assert feed.pumpkin == self.pumpkin
|
|
|
|
assert feed.is_wizard_passed == self.is_wizard_passed
|
2019-11-10 05:59:22 +09:00
|
|
|
assert feed.generated_playlists == [generated_playlist]
|
2019-11-08 02:09:39 +09:00
|
|
|
assert feed.headlines == self.headlines
|
|
|
|
assert feed.today == self.today
|
2019-11-10 05:59:22 +09:00
|
|
|
assert feed.days == [day]
|
2019-11-08 02:09:39 +09:00
|
|
|
assert feed.next_revision == self.next_revision
|
|
|
|
|
2019-11-10 05:59:22 +09:00
|
|
|
def test_equality(self, generated_playlist, day):
|
2021-02-03 21:28:10 +09:00
|
|
|
a = Feed(
|
|
|
|
self.can_get_more_events,
|
|
|
|
self.pumpkin,
|
|
|
|
self.is_wizard_passed,
|
|
|
|
[generated_playlist],
|
|
|
|
self.headlines,
|
|
|
|
self.today,
|
|
|
|
[day],
|
|
|
|
)
|
2019-12-28 22:25:09 +09:00
|
|
|
b = Feed(False, self.pumpkin, self.is_wizard_passed, [], self.headlines, self.today, [day])
|
2021-02-03 21:28:10 +09:00
|
|
|
c = Feed(
|
|
|
|
self.can_get_more_events,
|
|
|
|
self.pumpkin,
|
|
|
|
self.is_wizard_passed,
|
|
|
|
[generated_playlist],
|
|
|
|
self.headlines,
|
|
|
|
self.today,
|
|
|
|
[day],
|
|
|
|
)
|
2019-11-10 05:59:22 +09:00
|
|
|
|
|
|
|
assert a != b
|
|
|
|
assert hash(a) != hash(b)
|
|
|
|
assert a is not b
|
|
|
|
|
|
|
|
assert a == c
|