test_like.py 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import pytest
  2. from yandex_music import Like
  3. @pytest.fixture(scope='class', params=[2, 3, 4])
  4. def like_with_param(request, results, types):
  5. return (
  6. Like(
  7. types[request.param],
  8. TestLike.id,
  9. TestLike.timestamp,
  10. short_description=TestLike.short_description,
  11. description=TestLike.description,
  12. is_premiere=TestLike.is_premiere,
  13. is_banner=TestLike.is_banner,
  14. **{types[request.param]: results[request.param]},
  15. ),
  16. request.param,
  17. )
  18. class TestLike:
  19. id = 5246018
  20. timestamp = '2019-09-03T19:59:56+00:00'
  21. short_description = 'Учим английский нескучно'
  22. description = (
  23. 'Английский по песням – это аудио- и видеоподкаст радио Unistar о том, как учить английский язык '
  24. 'по песням – хитам 90-х и 2000-х, которые звучат на Unistar. Никакого занудства, грамматических '
  25. 'правил и зубрежки. Только нескучный английский! Вы узнаете, о чем поют в любимых песнях, и как '
  26. 'это может помочь вам в общении во время путешествий.'
  27. )
  28. is_premiere = False
  29. is_banner = True
  30. def test_expected_values(self, results, types, like_with_param):
  31. like, param = like_with_param
  32. assert like.type == types[param]
  33. assert like.id == self.id
  34. assert like.timestamp == self.timestamp
  35. assert like.short_description == self.short_description
  36. assert like.description == self.description
  37. assert like.is_premiere == self.is_premiere
  38. assert like.is_banner == self.is_banner
  39. assert getattr(like, like.type) == results[param]
  40. def test_de_json_none(self, client):
  41. assert Like.de_json({}, client) is None
  42. def test_de_list_none(self, client):
  43. assert Like.de_list([], client) == []
  44. @pytest.mark.parametrize('param', [2, 3, 4])
  45. def test_de_json_all(self, results, types, client, param):
  46. result, type_ = results[param], types[param]
  47. json_dict = {
  48. 'timestamp': self.timestamp,
  49. 'id': self.id,
  50. type_: result.to_dict(),
  51. 'short_description': self.short_description,
  52. 'description': self.description,
  53. 'is_premiere': self.is_premiere,
  54. 'is_banner': self.is_banner,
  55. }
  56. like = Like.de_json(json_dict, client, type_)
  57. assert like.type == type_
  58. assert like.id == self.id
  59. assert like.timestamp == self.timestamp
  60. assert like.short_description == self.short_description
  61. assert like.description == self.description
  62. assert like.is_premiere == self.is_premiere
  63. assert like.is_banner == self.is_banner
  64. assert getattr(like, type_) == result
  65. @pytest.mark.parametrize('param', [2, 3, 4])
  66. def test_equality(self, results, types, param):
  67. result, type_ = results[param], types[param]
  68. a = Like(type_, self.id, self.timestamp, **{type_: result})
  69. b = Like(type_, '', self.timestamp, **{type_: result})
  70. c = Like(type_, self.id, '', **{type_: result})
  71. d = Like(type_, self.id, self.timestamp, **{type_: result})
  72. assert a != b != c
  73. assert hash(a) != hash(b) != hash(c)
  74. assert a is not b is not c
  75. assert a == d