2019-11-10 05:59:22 +09:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
from yandex_music import BlockEntity
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='class', params=[3, 4, 6, 7, 8, 9, 10])
|
|
|
|
def block_entity_data_with_type(request, results, types):
|
|
|
|
return results[request.param], types[request.param]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='class', params=[3, 4, 6, 7, 8, 9, 10])
|
|
|
|
def block_entity_with_data_and_type(request, results, types):
|
|
|
|
return BlockEntity(TestBlockEntity.id, types[request.param], results[request.param]), \
|
|
|
|
results[request.param], types[request.param]
|
|
|
|
|
|
|
|
|
|
|
|
class TestBlockEntity:
|
|
|
|
id = 'lze0IVH4'
|
|
|
|
type = 'personal-playlist'
|
|
|
|
|
|
|
|
def test_expected_values(self, block_entity_with_data_and_type):
|
2019-12-29 16:38:24 +09:00
|
|
|
block_entity, data, type_ = block_entity_with_data_and_type
|
2019-11-10 05:59:22 +09:00
|
|
|
|
|
|
|
assert block_entity.id == self.id
|
2019-12-29 16:38:24 +09:00
|
|
|
assert block_entity.type == type_
|
2019-11-10 05:59:22 +09:00
|
|
|
assert block_entity.data == data
|
|
|
|
|
2019-12-29 17:06:27 +09:00
|
|
|
def test_de_list_none(self, client):
|
|
|
|
assert BlockEntity.de_list({}, client) == []
|
|
|
|
|
2019-12-29 16:38:24 +09:00
|
|
|
def test_de_json_none(self, client):
|
|
|
|
assert BlockEntity.de_json({}, client) is None
|
|
|
|
|
2019-11-10 05:59:22 +09:00
|
|
|
def test_de_json_required(self, client, block_entity_data_with_type):
|
2019-12-28 22:25:09 +09:00
|
|
|
data, type_ = block_entity_data_with_type
|
2019-11-10 05:59:22 +09:00
|
|
|
|
2019-12-28 22:25:09 +09:00
|
|
|
json_dict = {'id_': self.id, 'type_': type_, 'data': data.to_dict()}
|
2019-11-10 05:59:22 +09:00
|
|
|
block_entity = BlockEntity.de_json(json_dict, client)
|
|
|
|
|
|
|
|
assert block_entity.id == self.id
|
2019-12-28 22:25:09 +09:00
|
|
|
assert block_entity.type == type_
|
2019-11-10 05:59:22 +09:00
|
|
|
assert block_entity.data == data
|
|
|
|
|
|
|
|
def test_de_json_all(self, client, block_entity_data_with_type):
|
2019-12-28 22:25:09 +09:00
|
|
|
data, type_ = block_entity_data_with_type
|
2019-11-10 05:59:22 +09:00
|
|
|
|
2019-12-28 22:25:09 +09:00
|
|
|
json_dict = {'id_': self.id, 'type_': type_, 'data': data.to_dict()}
|
2019-11-10 05:59:22 +09:00
|
|
|
block_entity = BlockEntity.de_json(json_dict, client)
|
|
|
|
|
|
|
|
assert block_entity.id == self.id
|
2019-12-28 22:25:09 +09:00
|
|
|
assert block_entity.type == type_
|
2019-11-10 05:59:22 +09:00
|
|
|
assert block_entity.data == data
|
|
|
|
|
|
|
|
def test_equality(self, block_entity_data_with_type):
|
|
|
|
data, type = block_entity_data_with_type
|
|
|
|
|
|
|
|
a = BlockEntity(self.id, type, data)
|
2019-12-28 22:25:09 +09:00
|
|
|
b = BlockEntity(self.id, '', data)
|
2019-11-10 05:59:22 +09:00
|
|
|
c = BlockEntity('', type, data)
|
|
|
|
d = BlockEntity(self.id, type, data)
|
|
|
|
|
|
|
|
assert a != b != c
|
|
|
|
assert hash(a) != hash(b) != hash(c)
|
|
|
|
assert a is not b is not c
|
|
|
|
|
|
|
|
assert a == d
|