def de_json(cls, data: dict, client: 'Client') -> Optional['Subscription']:
        """Десериализация объекта.

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

        Returns:
            :obj:`yandex_music.Subscription`: Информация о подписках пользователя.
        """
        if not data:
            return None

        data = super(Subscription, cls).de_json(data, client)
        from yandex_music import AutoRenewable, RenewableRemainder, NonAutoRenewable, Operator

        data['auto_renewable'] = AutoRenewable.de_list(data.get('auto_renewable'), client)
        data['family_auto_renewable'] = AutoRenewable.de_list(data.get('family_auto_renewable'), client)
        data['non_auto_renewable_remainder'] = RenewableRemainder.de_json(
            data.get('non_auto_renewable_remainder'), client
        )
        data['non_auto_renewable'] = NonAutoRenewable.de_json(data.get('non_auto_renewable'), client)
        data['operator'] = Operator.de_list(data.get('operator'), client)

        return cls(client=client, **data)
示例#2
0
    def test_equality(self, product):
        a = AutoRenewable(self.expires, self.vendor, self.vendor_help_url,
                          product, self.finished)
        b = AutoRenewable(self.expires, '', self.vendor_help_url, None,
                          self.finished)
        c = AutoRenewable(self.expires, self.vendor, self.vendor_help_url,
                          product, self.finished)

        assert a != b
        assert hash(a) != hash(b)
        assert a is not b

        assert a == c
示例#3
0
def auto_renewable(product, user):
    return AutoRenewable(
        TestAutoRenewable.expires,
        TestAutoRenewable.vendor,
        TestAutoRenewable.vendor_help_url,
        product,
        TestAutoRenewable.finished,
        user,
        TestAutoRenewable.product_id,
        TestAutoRenewable.order_id,
    )
示例#4
0
    def test_de_json_required(self, client, product):
        json_dict = {
            'expires': self.expires,
            'vendor': self.vendor,
            'vendor_help_url': self.vendor_help_url,
            'product': product.to_dict(),
            'finished': self.finished,
        }
        auto_renewable = AutoRenewable.de_json(json_dict, client)

        assert auto_renewable.expires == self.expires
        assert auto_renewable.vendor == self.vendor
        assert auto_renewable.vendor_help_url == self.vendor_help_url
        assert auto_renewable.product == product
        assert auto_renewable.finished == self.finished
    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.Subscription`: Объект класса :class:`yandex_music.Subscription`.
        """
        if not data:
            return None

        data = super(Subscription, cls).de_json(data, client)
        from yandex_music import AutoRenewable
        data['auto_renewable'] = AutoRenewable.de_list(data.get('auto_renewable'), client)

        return cls(client=client, **data)
示例#6
0
    def test_de_json_all(self, client, product, user):
        json_dict = {
            'expires': self.expires,
            'vendor': self.vendor,
            'vendor_help_url': self.vendor_help_url,
            'product_id': self.product_id,
            'product': product.to_dict(),
            'finished': self.finished,
            'order_id': self.order_id,
            'master_info': user.to_dict(),
        }
        auto_renewable = AutoRenewable.de_json(json_dict, client)

        assert auto_renewable.expires == self.expires
        assert auto_renewable.vendor == self.vendor
        assert auto_renewable.vendor_help_url == self.vendor_help_url
        assert auto_renewable.product_id == self.product_id
        assert auto_renewable.product == product
        assert auto_renewable.finished == self.finished
        assert auto_renewable.master_info == user
        assert auto_renewable.order_id == self.order_id
示例#7
0
 def test_de_list_none(self, client):
     assert AutoRenewable.de_list({}, client) == []
示例#8
0
 def test_de_json_none(self, client):
     assert AutoRenewable.de_json({}, client) is None