test_subscription.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. from yandex_music import Subscription
  2. class TestSubscription:
  3. can_start_trial = False
  4. mcdonalds = False
  5. end = None
  6. had_any_subscription = False
  7. def test_expected_values(self, subscription, renewable_remainder, auto_renewable, non_auto_renewable, operator):
  8. assert subscription.non_auto_renewable_remainder == renewable_remainder
  9. assert subscription.auto_renewable == [auto_renewable]
  10. assert subscription.family_auto_renewable == [auto_renewable]
  11. assert subscription.operator == [operator]
  12. assert subscription.non_auto_renewable == non_auto_renewable
  13. assert subscription.can_start_trial == self.can_start_trial
  14. assert subscription.mcdonalds == self.mcdonalds
  15. assert subscription.end == self.end
  16. assert subscription.had_any_subscription == self.had_any_subscription
  17. def test_de_json_none(self, client):
  18. assert Subscription.de_json({}, client) is None
  19. def test_de_json_required(self, client, renewable_remainder, auto_renewable):
  20. json_dict = {
  21. 'non_auto_renewable_remainder': renewable_remainder.to_dict(),
  22. 'auto_renewable': [auto_renewable.to_dict()],
  23. 'family_auto_renewable': [auto_renewable.to_dict()],
  24. 'had_any_subscription': self.had_any_subscription,
  25. }
  26. subscription = Subscription.de_json(json_dict, client)
  27. assert subscription.non_auto_renewable_remainder == renewable_remainder
  28. assert subscription.auto_renewable == [auto_renewable]
  29. assert subscription.family_auto_renewable == [auto_renewable]
  30. assert subscription.had_any_subscription == self.had_any_subscription
  31. def test_de_json_all(self, client, renewable_remainder, auto_renewable, non_auto_renewable, operator):
  32. json_dict = {
  33. 'auto_renewable': [auto_renewable.to_dict()],
  34. 'can_start_trial': self.can_start_trial,
  35. 'mcdonalds': self.mcdonalds,
  36. 'end': self.end,
  37. 'non_auto_renewable_remainder': renewable_remainder.to_dict(),
  38. 'family_auto_renewable': [auto_renewable.to_dict()],
  39. 'non_auto_renewable': non_auto_renewable.to_dict(),
  40. 'operator': [operator.to_dict()],
  41. 'had_any_subscription': self.had_any_subscription,
  42. }
  43. subscription = Subscription.de_json(json_dict, client)
  44. assert subscription.non_auto_renewable_remainder == renewable_remainder
  45. assert subscription.auto_renewable == [auto_renewable]
  46. assert subscription.family_auto_renewable == [auto_renewable]
  47. assert subscription.operator == [operator]
  48. assert subscription.non_auto_renewable == non_auto_renewable
  49. assert subscription.can_start_trial == self.can_start_trial
  50. assert subscription.mcdonalds == self.mcdonalds
  51. assert subscription.end == self.end
  52. assert subscription.had_any_subscription == self.had_any_subscription
  53. def test_equality(self, renewable_remainder, auto_renewable):
  54. a = Subscription(renewable_remainder, [auto_renewable], [auto_renewable], self.had_any_subscription)
  55. b = Subscription(renewable_remainder, [], [auto_renewable], self.had_any_subscription)
  56. assert a != b != auto_renewable
  57. assert hash(a) != hash(b) != hash(auto_renewable)
  58. assert a is not auto_renewable