test_auto_renewable.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. from yandex_music import AutoRenewable
  2. class TestAutoRenewable:
  3. expires = '2019-11-30T23:59:59+03:00'
  4. vendor = 'Yandex'
  5. vendor_help_url = 'https://www.yandex.ru/support/music-app/subscription.xml'
  6. product_id = 'ru.yandex.mobile.music.1month.autorenewable.native.web.notrial.restricted.cache.99'
  7. finished = False
  8. order_id = 39385401
  9. def test_expected_values(self, auto_renewable, product, user):
  10. assert auto_renewable.expires == self.expires
  11. assert auto_renewable.vendor == self.vendor
  12. assert auto_renewable.vendor_help_url == self.vendor_help_url
  13. assert auto_renewable.product_id == self.product_id
  14. assert auto_renewable.product == product
  15. assert auto_renewable.finished == self.finished
  16. assert auto_renewable.master_info == user
  17. assert auto_renewable.order_id == self.order_id
  18. def test_de_json_none(self, client):
  19. assert AutoRenewable.de_json({}, client) is None
  20. def test_de_list_none(self, client):
  21. assert AutoRenewable.de_list([], client) == []
  22. def test_de_json_required(self, client, product):
  23. json_dict = {
  24. 'expires': self.expires,
  25. 'vendor': self.vendor,
  26. 'vendor_help_url': self.vendor_help_url,
  27. 'product': product.to_dict(),
  28. 'finished': self.finished,
  29. }
  30. auto_renewable = AutoRenewable.de_json(json_dict, client)
  31. assert auto_renewable.expires == self.expires
  32. assert auto_renewable.vendor == self.vendor
  33. assert auto_renewable.vendor_help_url == self.vendor_help_url
  34. assert auto_renewable.product == product
  35. assert auto_renewable.finished == self.finished
  36. def test_de_json_all(self, client, product, user):
  37. json_dict = {
  38. 'expires': self.expires,
  39. 'vendor': self.vendor,
  40. 'vendor_help_url': self.vendor_help_url,
  41. 'product_id': self.product_id,
  42. 'product': product.to_dict(),
  43. 'finished': self.finished,
  44. 'order_id': self.order_id,
  45. 'master_info': user.to_dict(),
  46. }
  47. auto_renewable = AutoRenewable.de_json(json_dict, client)
  48. assert auto_renewable.expires == self.expires
  49. assert auto_renewable.vendor == self.vendor
  50. assert auto_renewable.vendor_help_url == self.vendor_help_url
  51. assert auto_renewable.product_id == self.product_id
  52. assert auto_renewable.product == product
  53. assert auto_renewable.finished == self.finished
  54. assert auto_renewable.master_info == user
  55. assert auto_renewable.order_id == self.order_id
  56. def test_equality(self, product):
  57. a = AutoRenewable(self.expires, self.vendor, self.vendor_help_url, product, self.finished)
  58. b = AutoRenewable(self.expires, '', self.vendor_help_url, None, self.finished)
  59. c = AutoRenewable(self.expires, self.vendor, self.vendor_help_url, product, self.finished)
  60. assert a != b
  61. assert hash(a) != hash(b)
  62. assert a is not b
  63. assert a == c