test_track_short.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import pytest
  2. from yandex_music import TrackShort
  3. @pytest.fixture(scope='class')
  4. def track_short(track, chart):
  5. return TrackShort(
  6. TestTrackShort.id,
  7. TestTrackShort.timestamp,
  8. TestTrackShort.album_id,
  9. TestTrackShort.play_count,
  10. TestTrackShort.recent,
  11. chart,
  12. track,
  13. TestTrackShort.original_index,
  14. )
  15. class TestTrackShort:
  16. id = 21997388
  17. timestamp = '2019-11-07T03:00:00+00:00'
  18. album_id = None
  19. play_count = 0
  20. recent = False
  21. original_index = 23
  22. def test_expected_values(self, track_short, track, chart):
  23. assert track_short.id == self.id
  24. assert track_short.timestamp == self.timestamp
  25. assert track_short.album_id == self.album_id
  26. assert track_short.play_count == self.play_count
  27. assert track_short.recent == self.recent
  28. assert track_short.track == track
  29. assert track_short.chart == chart
  30. assert track_short.original_index == self.original_index
  31. def test_de_json_none(self, client):
  32. assert TrackShort.de_json({}, client) is None
  33. def test_de_list_none(self, client):
  34. assert TrackShort.de_list([], client) == []
  35. def test_de_json_required(self, client):
  36. json_dict = {'id': self.id, 'timestamp': self.timestamp}
  37. track_short = TrackShort.de_json(json_dict, client)
  38. assert track_short.id == self.id
  39. assert track_short.timestamp == self.timestamp
  40. def test_de_json_all(self, client, track, chart):
  41. json_dict = {
  42. 'id': self.id,
  43. 'timestamp': self.timestamp,
  44. 'album_id': self.album_id,
  45. 'play_count': self.play_count,
  46. 'recent': self.recent,
  47. 'track': track.to_dict(),
  48. 'chart': chart.to_dict(),
  49. 'original_index': self.original_index,
  50. }
  51. track_short = TrackShort.de_json(json_dict, client)
  52. assert track_short.id == self.id
  53. assert track_short.timestamp == self.timestamp
  54. assert track_short.album_id == self.album_id
  55. assert track_short.play_count == self.play_count
  56. assert track_short.recent == self.recent
  57. assert track_short.track == track
  58. assert track_short.chart == chart
  59. assert track_short.original_index == self.original_index
  60. def test_equality(self):
  61. a = TrackShort(self.id, self.timestamp, self.album_id)
  62. b = TrackShort(23, self.timestamp, self.album_id)
  63. c = TrackShort(self.id, self.timestamp)
  64. assert a != b
  65. assert hash(a) != hash(b)
  66. assert a is not b
  67. assert a == c