Exemple #1
0
    def test_equality(self, block_entity_data_with_type):
        data, type = block_entity_data_with_type

        a = BlockEntity(self.id, type, data)
        b = BlockEntity(self.id, '', data)
        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
Exemple #2
0
    def de_json(cls, data: dict, client: 'Client') -> Optional['Block']:
        """Десериализация объекта.

        Args:
            data (:obj:`dict`): Поля и значения десериализуемого объекта.
            client (:obj:`yandex_music.Client`, optional): Клиент Yandex Music.

        Returns:
            :obj:`yandex_music.Block`: Блок лендинга.
        """
        if not data:
            return None

        data = super(Block, cls).de_json(data, client)
        from yandex_music import BlockEntity, PlayContextsData, PersonalPlaylistsData

        data['entities'] = BlockEntity.de_list(data.get('entities'), client)

        block_type = data.get('type_')
        if block_type == 'personal-playlists':
            data['data'] = PersonalPlaylistsData.de_json(
                data.get('data'), client)
        elif block_type == 'play-contexts':
            data['data'] = PlayContextsData.de_json(data.get('data'), client)

        return cls(client=client, **data)
Exemple #3
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.Block`: Объект класса :class:`yandex_music.Block`.
        """
        if not data:
            return None

        data = super(Block, cls).de_json(data, client)
        from yandex_music import BlockEntity, PlayContextsData, PersonalPlaylistsData
        data['entities'] = BlockEntity.de_list(data.get('entities'), client)

        block_type = data.get('type_')
        if block_type == 'personal-playlists':
            data['data'] = PersonalPlaylistsData.de_json(
                data.get('data'), client)
        elif block_type == 'play-contexts':
            data['data'] = PlayContextsData.de_json(data.get('data'), client)

        return cls(client=client, **data)
Exemple #4
0
    def test_de_json_all(self, client, block_entity_data_with_type):
        data, type_ = block_entity_data_with_type

        json_dict = {'id_': self.id, 'type_': type_, 'data': data.to_dict()}
        block_entity = BlockEntity.de_json(json_dict, client)

        assert block_entity.id == self.id
        assert block_entity.type == type_
        assert block_entity.data == data
    def test_de_json_required(self, client, block_entity_data_with_type):
        data, type = block_entity_data_with_type

        json_dict = {'id': self.id, 'type': type, 'data': data.to_dict()}
        block_entity = BlockEntity.de_json(json_dict, client)

        assert block_entity.id == self.id
        assert block_entity.type == type
        assert block_entity.data == data
Exemple #6
0
    def de_json(cls, data: dict, client: 'Client') -> Optional['Block']:
        if not data:
            return None

        data = super(Block, cls).de_json(data, client)
        from yandex_music import BlockEntity, PlayContextsData, PersonalPlaylistsData
        data['entities'] = BlockEntity.de_list(data.get('entities'), client)

        block_type = data.get('type_')
        if block_type == 'personal-playlists':
            data['data'] = PersonalPlaylistsData.de_json(data.get('data'), client)
        elif block_type == 'play-contexts':
            data['data'] = PlayContextsData.de_json(data.get('data'), client)

        return cls(client=client, **data)
Exemple #7
0
def block_entity(request, results, types):
    return BlockEntity(TestBlockEntity.id, types[request.param], results[request.param])
Exemple #8
0
 def test_de_json_none(self, client):
     assert BlockEntity.de_json({}, client) is None
Exemple #9
0
 def test_de_list_none(self, client):
     assert BlockEntity.de_list({}, client) == []
Exemple #10
0
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],
    )