test_chart_info.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. from yandex_music import ChartInfo
  2. class TestChartInfo:
  3. id = 'KpXst7X4'
  4. type = 'chart'
  5. type_for_from = 'chart'
  6. title = 'Треки, популярные на Яндекс.Музыке прямо сейчас'
  7. chart_description = 'Слушателей за день'
  8. def test_expected_values(self, chart_info, chart_info_menu, playlist):
  9. assert chart_info.id == self.id
  10. assert chart_info.type == self.type
  11. assert chart_info.type_for_from == self.type_for_from
  12. assert chart_info.title == self.title
  13. assert chart_info.chart == playlist
  14. assert chart_info.menu == chart_info_menu
  15. def test_de_json_none(self, client):
  16. assert ChartInfo.de_json({}, client) is None
  17. def test_de_json_required(self, playlist, chart_info_menu, client):
  18. json_dict = {
  19. 'id': self.id,
  20. 'type': self.type,
  21. 'type_for_from': self.type_for_from,
  22. 'title': self.title,
  23. 'chart_description': self.chart_description,
  24. 'menu': chart_info_menu.to_dict(),
  25. 'chart': playlist.to_dict(),
  26. }
  27. chart_info = ChartInfo.de_json(json_dict, client)
  28. assert chart_info.id == self.id
  29. assert chart_info.type == self.type
  30. assert chart_info.type_for_from == self.type_for_from
  31. assert chart_info.title == self.title
  32. assert chart_info.chart_description == self.chart_description
  33. def test_de_json_all(self, client, playlist, chart_info_menu):
  34. json_dict = {
  35. 'id': self.id,
  36. 'type': self.type,
  37. 'type_for_from': self.type_for_from,
  38. 'title': self.title,
  39. 'chart_description': self.chart_description,
  40. 'menu': chart_info_menu.to_dict(),
  41. 'chart': playlist.to_dict(),
  42. }
  43. chart_info = ChartInfo.de_json(json_dict, client)
  44. assert chart_info.id == self.id
  45. assert chart_info.type == self.type
  46. assert chart_info.type_for_from == self.type_for_from
  47. assert chart_info.title == self.title
  48. assert chart_info.chart_description == self.chart_description
  49. assert chart_info.menu == chart_info_menu
  50. assert chart_info.chart == playlist
  51. def test_equality(self, playlist, chart_info_menu):
  52. a = ChartInfo(
  53. self.id, self.type, self.type_for_from, self.title, self.chart_description, chart_info_menu, playlist
  54. )
  55. b = ChartInfo(
  56. 'no_id', self.type, self.type_for_from, self.title, self.chart_description, chart_info_menu, playlist
  57. )
  58. c = ChartInfo(
  59. self.id, self.type, self.type_for_from, self.title, self.chart_description, chart_info_menu, playlist
  60. )
  61. assert a != b
  62. assert hash(a) != hash(b)
  63. assert a is not b
  64. assert a == c