2019-11-10 05:59:22 +09:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
from yandex_music import Block
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='class')
|
|
|
|
def block_with_entity_and_data(block_entity, data):
|
2021-02-03 21:28:10 +09:00
|
|
|
return (
|
|
|
|
Block(
|
|
|
|
TestBlock.id,
|
|
|
|
TestBlock.type,
|
|
|
|
TestBlock.type_for_from,
|
|
|
|
TestBlock.title,
|
|
|
|
[block_entity],
|
|
|
|
TestBlock.description,
|
|
|
|
data,
|
|
|
|
),
|
|
|
|
block_entity,
|
|
|
|
data,
|
|
|
|
)
|
2019-11-10 05:59:22 +09:00
|
|
|
|
|
|
|
|
|
|
|
class TestBlock:
|
|
|
|
id = 'ObsM5DkU'
|
|
|
|
type = 'personal-playlists'
|
|
|
|
type_for_from = 'personal-playlists'
|
|
|
|
title = 'Собрано на основе ваших предпочтений'
|
|
|
|
description = None
|
|
|
|
|
|
|
|
def test_expected_values(self, block_with_entity_and_data):
|
|
|
|
block, block_entity, data = block_with_entity_and_data
|
|
|
|
|
|
|
|
assert block.id == self.id
|
|
|
|
assert block.type == self.type
|
|
|
|
assert block.type_for_from == self.type_for_from
|
|
|
|
assert block.title == self.title
|
|
|
|
assert block.entities == [block_entity]
|
|
|
|
assert block.description == self.description
|
|
|
|
assert block.data == data
|
|
|
|
|
2019-12-29 16:38:24 +09:00
|
|
|
def test_de_json_none(self, client):
|
|
|
|
assert Block.de_json({}, client) is None
|
|
|
|
|
2019-12-29 17:06:27 +09:00
|
|
|
def test_de_list_none(self, client):
|
|
|
|
assert Block.de_list({}, client) == []
|
|
|
|
|
2019-11-10 05:59:22 +09:00
|
|
|
def test_de_json_required(self, client, block_entity):
|
2021-02-03 21:28:10 +09:00
|
|
|
json_dict = {
|
2021-09-19 22:47:19 +09:00
|
|
|
'id': self.id,
|
|
|
|
'type': self.type,
|
2021-02-03 21:28:10 +09:00
|
|
|
'type_for_from': self.type_for_from,
|
|
|
|
'title': self.title,
|
|
|
|
'entities': [block_entity.to_dict()],
|
|
|
|
}
|
2019-11-10 05:59:22 +09:00
|
|
|
block = Block.de_json(json_dict, client)
|
|
|
|
|
|
|
|
assert block.id == self.id
|
|
|
|
assert block.type == self.type
|
|
|
|
assert block.type_for_from == self.type_for_from
|
|
|
|
assert block.title == self.title
|
|
|
|
assert block.entities == [block_entity]
|
|
|
|
|
|
|
|
def test_de_json_all(self, client, block_entity, data_with_type):
|
2021-09-19 22:47:19 +09:00
|
|
|
data, type_ = data_with_type
|
2019-11-10 05:59:22 +09:00
|
|
|
|
2021-02-03 21:28:10 +09:00
|
|
|
json_dict = {
|
2021-09-19 22:47:19 +09:00
|
|
|
'id': self.id,
|
|
|
|
'type': type_,
|
2021-02-03 21:28:10 +09:00
|
|
|
'type_for_from': self.type_for_from,
|
|
|
|
'title': self.title,
|
|
|
|
'entities': [block_entity.to_dict()],
|
|
|
|
'description': self.description,
|
|
|
|
'data': data.to_dict(),
|
|
|
|
}
|
2019-11-10 05:59:22 +09:00
|
|
|
block = Block.de_json(json_dict, client)
|
|
|
|
|
|
|
|
assert block.id == self.id
|
2021-09-19 22:47:19 +09:00
|
|
|
assert block.type == type_
|
2019-11-10 05:59:22 +09:00
|
|
|
assert block.type_for_from == self.type_for_from
|
|
|
|
assert block.title == self.title
|
|
|
|
assert block.entities == [block_entity]
|
|
|
|
assert block.description == self.description
|
|
|
|
assert block.data == data
|
|
|
|
|
|
|
|
def test_equality(self, block_entity):
|
|
|
|
a = Block(self.id, self.type, self.type_for_from, self.title, [block_entity])
|
2019-12-28 22:25:09 +09:00
|
|
|
b = Block('', self.type, self.type_for_from, self.title, [])
|
2019-11-10 05:59:22 +09:00
|
|
|
c = Block(self.id, self.type, self.type_for_from, self.title, [block_entity])
|
|
|
|
|
|
|
|
assert a != b
|
|
|
|
assert hash(a) != hash(b)
|
|
|
|
assert a is not b
|
|
|
|
|
|
|
|
assert a == c
|