test_tracks_list.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import pytest
  2. from yandex_music import TracksList
  3. @pytest.fixture(scope='class')
  4. def tracks_list(track_short):
  5. return TracksList(TestTracksList.uid, TestTracksList.revision, [track_short])
  6. class TestTracksList:
  7. uid = None
  8. revision = None
  9. def test_expected_values(self, tracks_list, track_short):
  10. assert tracks_list.uid == self.uid
  11. assert tracks_list.revision == self.revision
  12. assert tracks_list.tracks == [track_short]
  13. def test_de_json_none(self, client):
  14. assert TracksList.de_json({}, client) is None
  15. def test_de_json_required(self, client, track_short):
  16. json_dict = {'uid': self.uid, 'revision': self.revision, 'tracks': [track_short.to_dict()]}
  17. tracks_list = TracksList.de_json(json_dict, client)
  18. assert tracks_list.uid == self.uid
  19. assert tracks_list.revision == self.revision
  20. assert tracks_list.tracks == [track_short]
  21. def test_de_json_all(self, client, track_short):
  22. json_dict = {'uid': self.uid, 'revision': self.revision, 'tracks': [track_short.to_dict()]}
  23. tracks_list = TracksList.de_json(json_dict, client)
  24. assert tracks_list.uid == self.uid
  25. assert tracks_list.revision == self.revision
  26. assert tracks_list.tracks == [track_short]
  27. def test_equality(self, track_short):
  28. a = TracksList(self.uid, self.revision, [track_short])
  29. b = TracksList(123, self.revision, [track_short])
  30. c = TracksList(self.uid, 10, [track_short])
  31. assert a != b
  32. assert hash(a) != hash(b)
  33. assert a is not b
  34. assert a == c
  35. def test_len(self, tracks_list):
  36. assert len(tracks_list) == len(tracks_list.tracks)
  37. def test_getitem(self, tracks_list):
  38. assert tracks_list[0] == tracks_list.tracks[0]
  39. def test_iter(self, tracks_list):
  40. assert list(tracks_list) == tracks_list.tracks