test_queue.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import pytest
  2. from yandex_music import Queue
  3. @pytest.fixture(scope='session')
  4. def queue(context, track_id):
  5. return Queue(context, [track_id], TestQueue.current_index, TestQueue.modified, TestQueue.id_, TestQueue.from_)
  6. class TestQueue:
  7. current_index = 1
  8. modified = '2020-06-20T13:29:09Z'
  9. id_ = '5eee0f257c28205469d8433c'
  10. from_ = 'mobile-home-playlist_of_the_day-default'
  11. def test_expected_values(self, queue, context, track_id):
  12. assert queue.context == context
  13. assert queue.tracks == [track_id]
  14. assert queue.current_index == self.current_index
  15. assert queue.modified == self.modified
  16. assert queue.id == self.id_
  17. assert queue.from_ == self.from_
  18. def test_de_json_none(self, client):
  19. assert Queue.de_json({}, client) is None
  20. def test_de_json_required(self, client, context, track_id):
  21. json_dict = {
  22. 'context': context.to_dict(),
  23. 'modified': self.modified,
  24. 'current_index': self.current_index,
  25. 'tracks': [track_id.to_dict()],
  26. }
  27. queue = Queue.de_json(json_dict, client)
  28. assert queue.context == context
  29. assert queue.tracks == [track_id]
  30. assert queue.current_index == self.current_index
  31. assert queue.modified == self.modified
  32. def test_de_json_all(self, client, context, track_id):
  33. json_dict = {
  34. 'context': context.to_dict(),
  35. 'modified': self.modified,
  36. 'id': self.id_,
  37. 'from_': self.from_,
  38. 'current_index': self.current_index,
  39. 'tracks': [track_id.to_dict()],
  40. }
  41. queue = Queue.de_json(json_dict, client)
  42. assert queue.context == context
  43. assert queue.tracks == [track_id]
  44. assert queue.current_index == self.current_index
  45. assert queue.modified == self.modified
  46. assert queue.id == self.id_
  47. assert queue.from_ == self.from_
  48. def test_equality(self, context, track_id):
  49. a = Queue(context, [track_id], self.current_index, self.modified)
  50. b = Queue(context, [], self.current_index, self.modified)
  51. c = Queue(context, [track_id], self.current_index, self.modified)
  52. assert a != b
  53. assert hash(a) != hash(b)
  54. assert a is not b
  55. assert a == c