def test_equality(self, block_entity): a = Block(self.id, self.type, self.type_for_from, self.title, [block_entity]) b = Block('', self.type, self.type_for_from, self.title, None) 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
def de_json(cls, data, client): if not data: return None data = super(Landing, cls).de_json(data, client) from yandex_music import Block data['blocks'] = Block.de_list(data.get('blocks'), client) return cls(client=client, **data)
def block_with_entity_and_data(block_entity, data): return ( Block( TestBlock.id, TestBlock.type, TestBlock.type_for_from, TestBlock.title, [block_entity], TestBlock.description, data, ), block_entity, data, )
def test_de_json_required(self, client, block_entity): json_dict = { 'id': self.id, 'type': self.type, 'type_for_from': self.type_for_from, 'title': self.title, 'entities': [block_entity.to_dict()] } 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 de_json(cls, data: dict, client: 'Client') -> Optional['Landing']: """Десериализация объекта. Args: data (:obj:`dict`): Поля и значения десериализуемого объекта. client (:obj:`yandex_music.Client`, optional): Клиент Yandex Music. Returns: :obj:`yandex_music.Landing`: Лендинг. """ if not data: return None data = super(Landing, cls).de_json(data, client) from yandex_music import Block data['blocks'] = Block.de_list(data.get('blocks'), client) return cls(client=client, **data)
def de_json(cls, data, client): """Десериализация объекта. Args: data (:obj:`dict`): Поля и значения десериализуемого объекта. client (:obj:`yandex_music.Client`): Объект класса :class:`yandex_music.Client`, представляющий клиент Yandex Music. Returns: :obj:`yandex_music.Landing`: Объект класса :class:`yandex_music.Landing`. """ if not data: return None data = super(Landing, cls).de_json(data, client) from yandex_music import Block data['blocks'] = Block.de_list(data.get('blocks'), client) return cls(client=client, **data)
def test_de_json_all(self, client, block_entity, data_with_type): data, type = data_with_type json_dict = { 'id': self.id, 'type': type, 'type_for_from': self.type_for_from, 'title': self.title, 'entities': [block_entity.to_dict()], 'description': self.description, 'data': data.to_dict() } block = Block.de_json(json_dict, client) assert block.id == self.id assert block.type == 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
def block(block_entity, data_with_type): data, type_ = data_with_type return Block(TestBlock.id, type_, TestBlock.type_for_from, TestBlock.title, [block_entity], TestBlock.description, data)
def test_de_list_none(self, client): assert Block.de_list({}, client) == []
def test_de_json_none(self, client): assert Block.de_json({}, client) is None