test_block_entity.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import pytest
  2. from yandex_music import BlockEntity
  3. @pytest.fixture(scope='class', params=[3, 4, 6, 7, 8, 9, 10])
  4. def block_entity_data_with_type(request, results, types):
  5. return results[request.param], types[request.param]
  6. @pytest.fixture(scope='class', params=[3, 4, 6, 7, 8, 9, 10])
  7. def block_entity_with_data_and_type(request, results, types):
  8. return (
  9. BlockEntity(TestBlockEntity.id, types[request.param], results[request.param]),
  10. results[request.param],
  11. types[request.param],
  12. )
  13. class TestBlockEntity:
  14. id = 'lze0IVH4'
  15. type = 'personal-playlist'
  16. def test_expected_values(self, block_entity_with_data_and_type):
  17. block_entity, data, type_ = block_entity_with_data_and_type
  18. assert block_entity.id == self.id
  19. assert block_entity.type == type_
  20. assert block_entity.data == data
  21. def test_de_list_none(self, client):
  22. assert BlockEntity.de_list([], client) == []
  23. def test_de_json_none(self, client):
  24. assert BlockEntity.de_json({}, client) is None
  25. def test_de_json_required(self, client, block_entity_data_with_type):
  26. data, type_ = block_entity_data_with_type
  27. json_dict = {'id': self.id, 'type': type_, 'data': data.to_dict()}
  28. block_entity = BlockEntity.de_json(json_dict, client)
  29. assert block_entity.id == self.id
  30. assert block_entity.type == type_
  31. assert block_entity.data == data
  32. def test_de_json_all(self, client, block_entity_data_with_type):
  33. data, type_ = block_entity_data_with_type
  34. json_dict = {'id': self.id, 'type': type_, 'data': data.to_dict()}
  35. block_entity = BlockEntity.de_json(json_dict, client)
  36. assert block_entity.id == self.id
  37. assert block_entity.type == type_
  38. assert block_entity.data == data
  39. def test_equality(self, block_entity_data_with_type):
  40. data, type = block_entity_data_with_type
  41. a = BlockEntity(self.id, type, data)
  42. b = BlockEntity(self.id, '', data)
  43. c = BlockEntity('', type, data)
  44. d = BlockEntity(self.id, type, data)
  45. assert a != b != c
  46. assert hash(a) != hash(b) != hash(c)
  47. assert a is not b is not c
  48. assert a == d