test_alert.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. from yandex_music import Alert
  2. class TestAlert:
  3. alert_id = 'xxx'
  4. text = 'тест Подписка скоро закончится. А вместе с ней закончатся музыка и подкасты без ограничений. Не надо так.'
  5. bg_color = '#FF5038'
  6. text_color = '#FFFFFF'
  7. alert_type = 'Churn_SubscriptionEnd_Music'
  8. close_button = False
  9. def test_expected_values(self, alert, alert_button):
  10. assert alert.alert_id == self.alert_id
  11. assert alert.text == self.text
  12. assert alert.bg_color == self.bg_color
  13. assert alert.text_color == self.text_color
  14. assert alert.alert_type == self.alert_type
  15. assert alert.button == alert_button
  16. assert alert.close_button == self.close_button
  17. def test_de_json_none(self, client):
  18. assert Alert.de_json({}, client) is None
  19. def test_de_json_required(self, client, alert_button):
  20. json_dict = {
  21. 'alert_id': self.alert_id,
  22. 'text': self.text,
  23. 'bg_color': self.bg_color,
  24. 'text_color': self.text_color,
  25. 'alert_type': self.alert_type,
  26. 'button': alert_button.to_dict(),
  27. 'close_button': self.close_button,
  28. }
  29. alert = Alert.de_json(json_dict, client)
  30. assert alert.alert_id == self.alert_id
  31. assert alert.text == self.text
  32. assert alert.bg_color == self.bg_color
  33. assert alert.text_color == self.text_color
  34. assert alert.alert_type == self.alert_type
  35. assert alert.button == alert_button
  36. assert alert.close_button == self.close_button
  37. def test_de_json_all(self, client, alert_button):
  38. json_dict = {
  39. 'alert_id': self.alert_id,
  40. 'text': self.text,
  41. 'bg_color': self.bg_color,
  42. 'text_color': self.text_color,
  43. 'alert_type': self.alert_type,
  44. 'button': alert_button.to_dict(),
  45. 'close_button': self.close_button,
  46. }
  47. alert = Alert.de_json(json_dict, client)
  48. assert alert.alert_id == self.alert_id
  49. assert alert.text == self.text
  50. assert alert.bg_color == self.bg_color
  51. assert alert.text_color == self.text_color
  52. assert alert.alert_type == self.alert_type
  53. assert alert.button == alert_button
  54. assert alert.close_button == self.close_button
  55. def test_equality(self, alert_button):
  56. a = Alert(
  57. self.alert_id, self.text, self.bg_color, self.text_color, self.alert_type, alert_button, self.close_button
  58. )
  59. b = Alert('', self.text, self.bg_color, self.text_color, self.alert_type, alert_button, self.close_button)
  60. c = Alert(
  61. self.alert_id, self.text, self.bg_color, self.text_color, self.alert_type, alert_button, self.close_button
  62. )
  63. assert a != b
  64. assert hash(a) != hash(b)
  65. assert a is not b
  66. assert a == c