test_ad_params.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. from yandex_music import AdParams
  2. class TestAdParams:
  3. partner_id = '146552'
  4. category_id = '0'
  5. page_ref = 'http://music.yandex.ru'
  6. target_ref = 'http://music.yandex.ru'
  7. other_params = 'user:561231028'
  8. ad_volume = -15
  9. genre_id = None
  10. genre_name = None
  11. def test_expected_values(self, ad_params):
  12. assert ad_params.partner_id == self.partner_id
  13. assert ad_params.category_id == self.category_id
  14. assert ad_params.page_ref == self.page_ref
  15. assert ad_params.target_ref == self.target_ref
  16. assert ad_params.other_params == self.other_params
  17. assert ad_params.ad_volume == self.ad_volume
  18. assert ad_params.genre_id == self.genre_id
  19. assert ad_params.genre_name == self.genre_name
  20. def test_de_json_none(self, client):
  21. assert AdParams.de_json({}, client) is None
  22. def test_de_json_required(self, client):
  23. json_dict = {
  24. 'partner_id': self.partner_id,
  25. 'category_id': self.category_id,
  26. 'page_ref': self.page_ref,
  27. 'target_ref': self.target_ref,
  28. 'other_params': self.other_params,
  29. 'ad_volume': self.ad_volume,
  30. }
  31. ad_params = AdParams.de_json(json_dict, client)
  32. assert ad_params.partner_id == self.partner_id
  33. assert ad_params.category_id == self.category_id
  34. assert ad_params.page_ref == self.page_ref
  35. assert ad_params.target_ref == self.target_ref
  36. assert ad_params.other_params == self.other_params
  37. assert ad_params.ad_volume == self.ad_volume
  38. def test_de_json_all(self, client):
  39. json_dict = {
  40. 'partner_id': self.partner_id,
  41. 'category_id': self.category_id,
  42. 'page_ref': self.page_ref,
  43. 'target_ref': self.target_ref,
  44. 'other_params': self.other_params,
  45. 'ad_volume': self.ad_volume,
  46. 'genre_id': self.genre_id,
  47. 'genre_name': self.genre_name,
  48. }
  49. ad_params = AdParams.de_json(json_dict, client)
  50. assert ad_params.partner_id == self.partner_id
  51. assert ad_params.category_id == self.category_id
  52. assert ad_params.page_ref == self.page_ref
  53. assert ad_params.target_ref == self.target_ref
  54. assert ad_params.other_params == self.other_params
  55. assert ad_params.ad_volume == self.ad_volume
  56. assert ad_params.genre_id == self.genre_id
  57. assert ad_params.genre_name == self.genre_name
  58. def test_equality(self):
  59. a = AdParams(
  60. self.partner_id, self.category_id, self.page_ref, self.target_ref, self.other_params, self.ad_volume
  61. )
  62. b = AdParams(self.partner_id, '10', self.page_ref, self.target_ref, self.other_params, self.ad_volume)
  63. c = AdParams(self.partner_id, self.category_id, '', self.target_ref, self.other_params, -30)
  64. d = AdParams(
  65. self.partner_id, self.category_id, self.page_ref, self.target_ref, self.other_params, self.ad_volume
  66. )
  67. assert a != b != c
  68. assert hash(a) != hash(b) != hash(c)
  69. assert a is not b is not c
  70. assert a == d