def test_de_json_all_args(self, bot, creator):
        json_dict = {
            "invite_link": self.link,
            "creator": creator.to_dict(),
            "creates_join_request": self.creates_join_request,
            "is_primary": self.primary,
            "is_revoked": self.revoked,
            "expire_date": to_timestamp(self.expire_date),
            "member_limit": self.member_limit,
            "name": self.name,
            "pending_join_request_count": str(self.pending_join_request_count),
        }

        invite_link = ChatInviteLink.de_json(json_dict, bot)

        assert invite_link.invite_link == self.link
        assert invite_link.creator == creator
        assert invite_link.creates_join_request == self.creates_join_request
        assert invite_link.is_primary == self.primary
        assert invite_link.is_revoked == self.revoked
        assert abs(invite_link.expire_date -
                   self.expire_date) < datetime.timedelta(seconds=1)
        assert to_timestamp(invite_link.expire_date) == to_timestamp(
            self.expire_date)
        assert invite_link.member_limit == self.member_limit
        assert invite_link.name == self.name
        assert invite_link.pending_join_request_count == self.pending_join_request_count
    def test_de_json_required_args(self, bot, creator):
        json_dict = {
            'invite_link': self.link,
            'creator': creator.to_dict(),
            'is_primary': self.primary,
            'is_revoked': self.revoked,
        }

        invite_link = ChatInviteLink.de_json(json_dict, bot)

        assert invite_link.invite_link == self.link
        assert invite_link.creator == creator
        assert invite_link.is_primary == self.primary
        assert invite_link.is_revoked == self.revoked
    def de_json(cls, data: Optional[JSONDict],
                bot: 'Bot') -> Optional['ChatJoinRequest']:
        """See :meth:`telegram.TelegramObject.de_json`."""
        data = cls._parse_data(data)

        if not data:
            return None

        data['chat'] = Chat.de_json(data.get('chat'), bot)
        data['from_user'] = User.de_json(data.get('from'), bot)
        data['date'] = from_timestamp(data.get('date', None))
        data['invite_link'] = ChatInviteLink.de_json(data.get('invite_link'),
                                                     bot)

        return cls(bot=bot, **data)
    def test_de_json_required_args(self, bot, creator):
        json_dict = {
            "invite_link": self.link,
            "creator": creator.to_dict(),
            "creates_join_request": self.creates_join_request,
            "is_primary": self.primary,
            "is_revoked": self.revoked,
        }

        invite_link = ChatInviteLink.de_json(json_dict, bot)

        assert invite_link.invite_link == self.link
        assert invite_link.creator == creator
        assert invite_link.creates_join_request == self.creates_join_request
        assert invite_link.is_primary == self.primary
        assert invite_link.is_revoked == self.revoked
Ejemplo n.º 5
0
    def de_json(cls, data: Optional[JSONDict],
                bot: 'Bot') -> Optional['ChatMemberUpdated']:
        data = cls.parse_data(data)

        if not data:
            return None

        data['chat'] = Chat.de_json(data.get('chat'), bot)
        data['from_user'] = User.de_json(data.get('from'), bot)
        data['date'] = from_timestamp(data.get('date'))
        data['old_chat_member'] = ChatMember.de_json(
            data.get('old_chat_member'), bot)
        data['new_chat_member'] = ChatMember.de_json(
            data.get('new_chat_member'), bot)
        data['invite_link'] = ChatInviteLink.de_json(data.get('invite_link'),
                                                     bot)

        return cls(**data)
    def test_de_json_all_args(self, bot, creator):
        json_dict = {
            'invite_link': self.link,
            'creator': creator.to_dict(),
            'is_primary': self.primary,
            'is_revoked': self.revoked,
            'expire_date': to_timestamp(self.expire_date),
            'member_limit': self.member_limit,
        }

        invite_link = ChatInviteLink.de_json(json_dict, bot)

        assert invite_link.invite_link == self.link
        assert invite_link.creator == creator
        assert invite_link.is_primary == self.primary
        assert invite_link.is_revoked == self.revoked
        assert pytest.approx(invite_link.expire_date == self.expire_date)
        assert to_timestamp(invite_link.expire_date) == to_timestamp(self.expire_date)
        assert invite_link.member_limit == self.member_limit