test_block.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import pytest
  2. from yandex_music import Block
  3. @pytest.fixture(scope='class')
  4. def block_with_entity_and_data(block_entity, data):
  5. return (
  6. Block(
  7. TestBlock.id,
  8. TestBlock.type,
  9. TestBlock.type_for_from,
  10. TestBlock.title,
  11. [block_entity],
  12. TestBlock.description,
  13. data,
  14. ),
  15. block_entity,
  16. data,
  17. )
  18. class TestBlock:
  19. id = 'ObsM5DkU'
  20. type = 'personal-playlists'
  21. type_for_from = 'personal-playlists'
  22. title = 'Собрано на основе ваших предпочтений'
  23. description = None
  24. def test_expected_values(self, block_with_entity_and_data):
  25. block, block_entity, data = block_with_entity_and_data
  26. assert block.id == self.id
  27. assert block.type == self.type
  28. assert block.type_for_from == self.type_for_from
  29. assert block.title == self.title
  30. assert block.entities == [block_entity]
  31. assert block.description == self.description
  32. assert block.data == data
  33. def test_de_json_none(self, client):
  34. assert Block.de_json({}, client) is None
  35. def test_de_list_none(self, client):
  36. assert Block.de_list([], client) == []
  37. def test_de_json_required(self, client, block_entity):
  38. json_dict = {
  39. 'id': self.id,
  40. 'type': self.type,
  41. 'type_for_from': self.type_for_from,
  42. 'title': self.title,
  43. 'entities': [block_entity.to_dict()],
  44. }
  45. block = Block.de_json(json_dict, client)
  46. assert block.id == self.id
  47. assert block.type == self.type
  48. assert block.type_for_from == self.type_for_from
  49. assert block.title == self.title
  50. assert block.entities == [block_entity]
  51. def test_de_json_all(self, client, block_entity, data_with_type):
  52. data, type_ = data_with_type
  53. json_dict = {
  54. 'id': self.id,
  55. 'type': type_,
  56. 'type_for_from': self.type_for_from,
  57. 'title': self.title,
  58. 'entities': [block_entity.to_dict()],
  59. 'description': self.description,
  60. 'data': data.to_dict(),
  61. }
  62. block = Block.de_json(json_dict, client)
  63. assert block.id == self.id
  64. assert block.type == type_
  65. assert block.type_for_from == self.type_for_from
  66. assert block.title == self.title
  67. assert block.entities == [block_entity]
  68. assert block.description == self.description
  69. assert block.data == data
  70. def test_equality(self, block_entity):
  71. a = Block(self.id, self.type, self.type_for_from, self.title, [block_entity])
  72. b = Block('', self.type, self.type_for_from, self.title, [])
  73. c = Block(self.id, self.type, self.type_for_from, self.title, [block_entity])
  74. assert a != b
  75. assert hash(a) != hash(b)
  76. assert a is not b
  77. assert a == c