test_settings.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. from yandex_music import Settings
  2. class TestSettings:
  3. web_payment_url = 'https://music.yandex.ru/webview/payment'
  4. promo_codes_enabled = True
  5. def test_expected_values(self, settings, product, price):
  6. assert settings.in_app_products == [product]
  7. assert settings.native_products == [product]
  8. assert settings.web_payment_url == self.web_payment_url
  9. assert settings.promo_codes_enabled == self.promo_codes_enabled
  10. assert settings.web_payment_month_product_price == price
  11. def test_de_json_none(self, client):
  12. assert Settings.de_json({}, client) is None
  13. def test_de_json_required(self, client, product):
  14. json_dict = {
  15. 'in_app_products': [product.to_dict()],
  16. 'native_products': [product.to_dict()],
  17. 'web_payment_url': self.web_payment_url,
  18. 'promo_codes_enabled': self.promo_codes_enabled,
  19. }
  20. settings = Settings.de_json(json_dict, client)
  21. assert settings.in_app_products == [product]
  22. assert settings.native_products == [product]
  23. assert settings.web_payment_url == self.web_payment_url
  24. assert settings.promo_codes_enabled == self.promo_codes_enabled
  25. def test_de_json_all(self, client, product, price):
  26. json_dict = {
  27. 'in_app_products': [product.to_dict()],
  28. 'native_products': [product.to_dict()],
  29. 'web_payment_url': self.web_payment_url,
  30. 'promo_codes_enabled': self.promo_codes_enabled,
  31. 'web_payment_month_product_price': price.to_dict(),
  32. }
  33. settings = Settings.de_json(json_dict, client)
  34. assert settings.in_app_products == [product]
  35. assert settings.native_products == [product]
  36. assert settings.web_payment_url == self.web_payment_url
  37. assert settings.promo_codes_enabled == self.promo_codes_enabled
  38. assert settings.web_payment_month_product_price == price
  39. def test_equality(self, product):
  40. a = Settings([product], [product], self.web_payment_url, self.promo_codes_enabled)
  41. b = Settings([product], [product], '', self.promo_codes_enabled)
  42. c = Settings([product], [product], self.web_payment_url, False)
  43. d = Settings([product], [product], self.web_payment_url, self.promo_codes_enabled)
  44. assert a != b != c
  45. assert hash(a) != hash(b) != hash(c)
  46. assert a is not b is not c
  47. assert a == d