test_product.py 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. from yandex_music import Product
  2. class TestProduct:
  3. product_id = 'ru.yandex.mobile.music.1month.autorenewable.native.web.notrial.restricted.cache.99'
  4. type = 'subscription'
  5. common_period_duration = 'P1M'
  6. description = None
  7. duration = 30
  8. trial_duration = 0
  9. feature = 'basic-music'
  10. debug = False
  11. plus = False
  12. cheapest = True
  13. title = 'КиноПоиск HD'
  14. family_sub = False
  15. fb_image = ''
  16. fb_name = 'kinopoisk-plus'
  17. family = False
  18. features = ['basic-music']
  19. available = None
  20. trial_available = None
  21. trial_period_duration = 'P1M'
  22. intro_period_duration = 'P1Y'
  23. start_period_duration = 'P1M'
  24. vendor_trial_available = None
  25. button_text = None
  26. button_additional_text = None
  27. payment_method_types = None
  28. def test_expected_values(self, product, price, licence_text_part):
  29. assert product.product_id == self.product_id
  30. assert product.type == self.type
  31. assert product.common_period_duration == self.common_period_duration
  32. assert product.duration == self.duration
  33. assert product.trial_duration == self.trial_duration
  34. assert product.price == price
  35. assert product.feature == self.feature
  36. assert product.debug == self.debug
  37. assert product.plus == self.plus
  38. assert product.cheapest == self.cheapest
  39. assert product.title == self.title
  40. assert product.family_sub == self.family_sub
  41. assert product.fb_image == self.fb_image
  42. assert product.fb_name == self.fb_name
  43. assert product.family == self.family
  44. assert product.features == self.features
  45. assert product.description == self.description
  46. assert product.available == self.available
  47. assert product.trial_available == self.trial_available
  48. assert product.trial_period_duration == self.trial_period_duration
  49. assert product.intro_period_duration == self.intro_period_duration
  50. assert product.intro_price == price
  51. assert product.start_period_duration == self.start_period_duration
  52. assert product.start_price == price
  53. assert product.licence_text_parts == [licence_text_part]
  54. assert product.vendor_trial_available == self.vendor_trial_available
  55. assert product.button_text == self.button_text
  56. assert product.button_additional_text == self.button_additional_text
  57. assert product.payment_method_types == self.payment_method_types
  58. def test_de_json_none(self, client):
  59. assert Product.de_json({}, client) is None
  60. def test_de_list_none(self, client):
  61. assert Product.de_list([], client) == []
  62. def test_de_json_required(self, client, price):
  63. json_dict = {
  64. 'product_id': self.product_id,
  65. 'type': self.type,
  66. 'duration': self.duration,
  67. 'trial_duration': self.trial_duration,
  68. 'price': price.to_dict(),
  69. 'feature': self.feature,
  70. 'debug': self.debug,
  71. 'plus': self.plus,
  72. }
  73. product = Product.de_json(json_dict, client)
  74. assert product.product_id == self.product_id
  75. assert product.type == self.type
  76. assert product.duration == self.duration
  77. assert product.trial_duration == self.trial_duration
  78. assert product.price == price
  79. assert product.feature == self.feature
  80. assert product.debug == self.debug
  81. assert product.plus == self.plus
  82. def test_de_json_all(self, client, price, licence_text_part):
  83. json_dict = {
  84. 'product_id': self.product_id,
  85. 'type': self.type,
  86. 'common_period_duration': self.common_period_duration,
  87. 'duration': self.duration,
  88. 'trial_duration': self.trial_duration,
  89. 'price': price.to_dict(),
  90. 'feature': self.feature,
  91. 'debug': self.debug,
  92. 'plus': self.plus,
  93. 'features': self.features,
  94. 'description': self.description,
  95. 'available': self.available,
  96. 'trial_available': self.trial_available,
  97. 'vendor_trial_available': self.vendor_trial_available,
  98. 'button_text': self.button_text,
  99. 'button_additional_text': self.button_additional_text,
  100. 'cheapest': self.cheapest,
  101. 'payment_method_types': self.payment_method_types,
  102. 'title': self.title,
  103. 'family': self.family,
  104. 'family_sub': self.family_sub,
  105. 'fb_image': self.fb_image,
  106. 'fb_name': self.fb_name,
  107. 'trial_period_duration': self.trial_period_duration,
  108. 'intro_period_duration': self.intro_period_duration,
  109. 'intro_price': price.to_dict(),
  110. 'start_period_duration': self.start_period_duration,
  111. 'start_price': price.to_dict(),
  112. 'licence_text_parts': [licence_text_part.to_dict()],
  113. }
  114. product = Product.de_json(json_dict, client)
  115. assert product.product_id == self.product_id
  116. assert product.type == self.type
  117. assert product.common_period_duration == self.common_period_duration
  118. assert product.duration == self.duration
  119. assert product.trial_duration == self.trial_duration
  120. assert product.price == price
  121. assert product.feature == self.feature
  122. assert product.debug == self.debug
  123. assert product.plus == self.plus
  124. assert product.cheapest == self.cheapest
  125. assert product.title == self.title
  126. assert product.family_sub == self.family_sub
  127. assert product.fb_image == self.fb_image
  128. assert product.fb_name == self.fb_name
  129. assert product.family == self.family
  130. assert product.features == self.features
  131. assert product.description == self.description
  132. assert product.available == self.available
  133. assert product.trial_available == self.trial_available
  134. assert product.trial_period_duration == self.trial_period_duration
  135. assert product.intro_period_duration == self.intro_period_duration
  136. assert product.intro_price == price
  137. assert product.start_period_duration == self.start_period_duration
  138. assert product.start_price == price
  139. assert product.licence_text_parts == [licence_text_part]
  140. assert product.vendor_trial_available == self.vendor_trial_available
  141. assert product.button_text == self.button_text
  142. assert product.button_additional_text == self.button_additional_text
  143. assert product.payment_method_types == self.payment_method_types
  144. def test_equality(self, price):
  145. a = Product(
  146. self.product_id,
  147. self.type,
  148. self.duration,
  149. self.trial_duration,
  150. price,
  151. self.feature,
  152. self.debug,
  153. self.plus,
  154. )
  155. b = Product(
  156. '',
  157. self.type,
  158. self.duration,
  159. self.trial_duration,
  160. price,
  161. self.feature,
  162. self.debug,
  163. self.plus,
  164. )
  165. c = Product(
  166. self.product_id,
  167. self.type,
  168. self.duration,
  169. self.trial_duration,
  170. price,
  171. self.feature,
  172. self.debug,
  173. self.plus,
  174. )
  175. assert a != b
  176. assert hash(a) != hash(b)
  177. assert a == c