test_play_context.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. from yandex_music import PlayContext
  2. class TestPlayContext:
  3. client_ = 'android'
  4. context = 'playlist'
  5. context_item = '503646255:69814820'
  6. def test_expected_values(self, play_context, track_short_old):
  7. assert play_context.client_ == self.client_
  8. assert play_context.context == self.context
  9. assert play_context.context_item == self.context_item
  10. assert play_context.tracks == [track_short_old]
  11. def test_de_json_none(self, client):
  12. assert PlayContext.de_json({}, client) is None
  13. def test_de_json_required(self, client, track_short_old):
  14. json_dict = {
  15. 'client_': self.client_,
  16. 'context': self.context,
  17. 'context_item': self.context_item,
  18. 'tracks': [track_short_old.to_dict()],
  19. }
  20. play_context = PlayContext.de_json(json_dict, client)
  21. assert play_context.client_ == self.client_
  22. assert play_context.context == self.context
  23. assert play_context.context_item == self.context_item
  24. assert play_context.tracks == [track_short_old]
  25. def test_de_json_all(self, client, track_short_old):
  26. json_dict = {
  27. 'client_': self.client_,
  28. 'context': self.context,
  29. 'context_item': self.context_item,
  30. 'tracks': [track_short_old.to_dict()],
  31. }
  32. play_context = PlayContext.de_json(json_dict, client)
  33. assert play_context.client_ == self.client_
  34. assert play_context.context == self.context
  35. assert play_context.context_item == self.context_item
  36. assert play_context.tracks == [track_short_old]
  37. def test_equality(self, track_short_old):
  38. a = PlayContext(self.client_, self.context, self.context_item, [track_short_old])
  39. b = PlayContext('', self.context, self.context_item, [])
  40. c = PlayContext(self.client_, self.context, self.context_item, [track_short_old])
  41. assert a != b
  42. assert hash(a) != hash(b)
  43. assert a is not b
  44. assert a == c