test_chart.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. from yandex_music import Chart
  2. class TestChart:
  3. position = 2
  4. progress = 'same'
  5. listeners = 1433
  6. shift = 0
  7. bg_color = '#666A61'
  8. def test_expected_values(self, chart, track_id):
  9. assert chart.position == self.position
  10. assert chart.progress == self.progress
  11. assert chart.listeners == self.listeners
  12. assert chart.shift == self.shift
  13. assert chart.track_id == track_id
  14. assert chart.bg_color == self.bg_color
  15. def test_de_json_none(self, client):
  16. assert Chart.de_json({}, client) is None
  17. def test_de_list_none(self, client):
  18. assert Chart.de_list([], client) == []
  19. def test_de_json_required(self, client):
  20. json_dict = {
  21. 'position': self.position,
  22. 'progress': self.progress,
  23. 'listeners': self.listeners,
  24. 'shift': self.shift,
  25. }
  26. chart = Chart.de_json(json_dict, client)
  27. assert chart.position == self.position
  28. assert chart.progress == self.progress
  29. assert chart.listeners == self.listeners
  30. assert chart.shift == self.shift
  31. def test_de_json_all(self, client, track_id):
  32. json_dict = {
  33. 'position': self.position,
  34. 'progress': self.progress,
  35. 'listeners': self.listeners,
  36. 'shift': self.shift,
  37. 'bg_color': self.bg_color,
  38. 'track_id': track_id.to_dict(),
  39. }
  40. chart = Chart.de_json(json_dict, client)
  41. assert chart.position == self.position
  42. assert chart.progress == self.progress
  43. assert chart.listeners == self.listeners
  44. assert chart.shift == self.shift
  45. assert chart.track_id == track_id
  46. assert chart.bg_color == self.bg_color
  47. def test_equality(self):
  48. a = Chart(self.position, self.progress, self.listeners, self.shift)
  49. b = Chart(10, self.progress, self.listeners, self.shift)
  50. c = Chart(self.position, self.progress, 10, self.shift)
  51. d = Chart(self.position, self.progress, self.listeners, self.shift)
  52. assert a != b != c
  53. assert hash(a) != hash(b) != hash(c)
  54. assert a is not b is not c
  55. assert a == d