Пример #1
0
    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
Пример #2
0
    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)
Пример #3
0
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,
    )
Пример #4
0
    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]
Пример #5
0
    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)
Пример #6
0
    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)
Пример #7
0
    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
Пример #8
0
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)
Пример #9
0
 def test_de_list_none(self, client):
     assert Block.de_list({}, client) == []
Пример #10
0
 def test_de_json_none(self, client):
     assert Block.de_json({}, client) is None