示例#1
0
    def test_de_json_required_args(self, bot, user):
        json_dict = {'user': user.to_dict(), 'status': self.status}

        chat_member = ChatMember.de_json(json_dict, bot)

        assert chat_member.user == user
        assert chat_member.status == self.status
    def test_de_json_required_args(self, bot, user):
        json_dict = {'user': user.to_dict(), 'status': self.status}

        chat_member = ChatMember.de_json(json_dict, bot)

        assert chat_member.user == user
        assert chat_member.status == self.status
    def test_de_json_all_args(self, bot, chat_member_type):
        json_dict = make_json_dict(chat_member_type, include_optional_args=True)
        const_chat_member = ChatMember.de_json(json_dict, bot)

        assert isinstance(const_chat_member, ChatMember)
        assert isinstance(const_chat_member, chat_member_type.__class__)
        for c_mem_type_at, const_c_mem_at in iter_args(chat_member_type, const_chat_member, True):
            assert c_mem_type_at == const_c_mem_at
示例#4
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_required_args(self, bot, chat_member_type):
        cls = chat_member_type.__class__
        assert cls.de_json({}, bot) is None

        json_dict = make_json_dict(chat_member_type)
        const_chat_member = ChatMember.de_json(json_dict, bot)

        assert isinstance(const_chat_member, ChatMember)
        assert isinstance(const_chat_member, cls)
        for chat_mem_type_at, const_chat_mem_at in iter_args(chat_member_type, const_chat_member):
            assert chat_mem_type_at == const_chat_mem_at
    def test_de_json_required_args(self, bot, chat_member_class_and_status, user):
        cls = chat_member_class_and_status[0]
        status = chat_member_class_and_status[1]

        assert cls.de_json({}, bot) is None

        json_dict = {'status': status, 'user': user.to_dict()}
        chat_member_type = ChatMember.de_json(json_dict, bot)

        assert isinstance(chat_member_type, ChatMember)
        assert isinstance(chat_member_type, cls)
        assert chat_member_type.status == status
        assert chat_member_type.user == user
示例#7
0
    def test_de_json_all_args(self, bot, user):
        time = datetime.datetime.utcnow()
        custom_title = 'custom_title'

        json_dict = {
            'user': user.to_dict(),
            'status': self.status,
            'custom_title': custom_title,
            'is_anonymous': True,
            'until_date': to_timestamp(time),
            'can_be_edited': False,
            'can_change_info': True,
            'can_post_messages': False,
            'can_edit_messages': True,
            'can_delete_messages': True,
            'can_invite_users': False,
            'can_restrict_members': True,
            'can_pin_messages': False,
            'can_promote_members': True,
            'can_send_messages': False,
            'can_send_media_messages': True,
            'can_send_polls': False,
            'can_send_other_messages': True,
            'can_add_web_page_previews': False,
            'can_manage_chat': True,
            'can_manage_voice_chats': True,
        }

        chat_member = ChatMember.de_json(json_dict, bot)

        assert chat_member.user == user
        assert chat_member.status == self.status
        assert chat_member.custom_title == custom_title
        assert chat_member.is_anonymous is True
        assert chat_member.can_be_edited is False
        assert chat_member.can_change_info is True
        assert chat_member.can_post_messages is False
        assert chat_member.can_edit_messages is True
        assert chat_member.can_delete_messages is True
        assert chat_member.can_invite_users is False
        assert chat_member.can_restrict_members is True
        assert chat_member.can_pin_messages is False
        assert chat_member.can_promote_members is True
        assert chat_member.can_send_messages is False
        assert chat_member.can_send_media_messages is True
        assert chat_member.can_send_polls is False
        assert chat_member.can_send_other_messages is True
        assert chat_member.can_add_web_page_previews is False
        assert chat_member.can_manage_chat is True
        assert chat_member.can_manage_voice_chats is True
示例#8
0
    def test_de_json_all_args(self, bot, user):
        time = datetime.datetime.now()
        json_dict = {
            'user': user.to_dict(),
            'status': self.status,
            'until_date': to_timestamp(time),
            'can_be_edited': False,
            'can_change_info': True,
            'can_post_messages': False,
            'can_edit_messages': True,
            'can_delete_messages': True,
            'can_invite_users': False,
            'can_restrict_members': True,
            'can_pin_messages': False,
            'can_promote_members': True,
            'can_send_messages': False,
            'can_send_media_messages': True,
            'can_send_other_messages': False,
            'can_add_web_page_previews': True
        }

        chat_member = ChatMember.de_json(json_dict, bot)

        assert chat_member.user == user
        assert chat_member.status == self.status
        assert chat_member.can_be_edited is False
        assert chat_member.can_change_info is True
        assert chat_member.can_post_messages is False
        assert chat_member.can_edit_messages is True
        assert chat_member.can_delete_messages is True
        assert chat_member.can_invite_users is False
        assert chat_member.can_restrict_members is True
        assert chat_member.can_pin_messages is False
        assert chat_member.can_promote_members is True
        assert chat_member.can_send_messages is False
        assert chat_member.can_send_media_messages is True
        assert chat_member.can_send_other_messages is False
        assert chat_member.can_add_web_page_previews is True
    def test_de_json_all_args(self, bot, user):
        time = datetime.datetime.now()
        json_dict = {'user': user.to_dict(),
                     'status': self.status,
                     'until_date': to_timestamp(time),
                     'can_be_edited': False,
                     'can_change_info': True,
                     'can_post_messages': False,
                     'can_edit_messages': True,
                     'can_delete_messages': True,
                     'can_invite_users': False,
                     'can_restrict_members': True,
                     'can_pin_messages': False,
                     'can_promote_members': True,
                     'can_send_messages': False,
                     'can_send_media_messages': True,
                     'can_send_other_messages': False,
                     'can_add_web_page_previews': True}

        chat_member = ChatMember.de_json(json_dict, bot)

        assert chat_member.user == user
        assert chat_member.status == self.status
        assert chat_member.can_be_edited is False
        assert chat_member.can_change_info is True
        assert chat_member.can_post_messages is False
        assert chat_member.can_edit_messages is True
        assert chat_member.can_delete_messages is True
        assert chat_member.can_invite_users is False
        assert chat_member.can_restrict_members is True
        assert chat_member.can_pin_messages is False
        assert chat_member.can_promote_members is True
        assert chat_member.can_send_messages is False
        assert chat_member.can_send_media_messages is True
        assert chat_member.can_send_other_messages is False
        assert chat_member.can_add_web_page_previews is True
    def test_de_json_all_args(self, bot, chat_member_class_and_status, user):
        cls = chat_member_class_and_status[0]
        status = chat_member_class_and_status[1]
        time = datetime.datetime.utcnow()

        json_dict = {
            'user': user.to_dict(),
            'status': status,
            'custom_title': 'PTB',
            'is_anonymous': True,
            'until_date': to_timestamp(time),
            'can_be_edited': False,
            'can_change_info': True,
            'can_post_messages': False,
            'can_edit_messages': True,
            'can_delete_messages': True,
            'can_invite_users': False,
            'can_restrict_members': True,
            'can_pin_messages': False,
            'can_promote_members': True,
            'can_send_messages': False,
            'can_send_media_messages': True,
            'can_send_polls': False,
            'can_send_other_messages': True,
            'can_add_web_page_previews': False,
            'can_manage_chat': True,
            'can_manage_voice_chats': True,
        }
        chat_member_type = ChatMember.de_json(json_dict, bot)

        assert isinstance(chat_member_type, ChatMember)
        assert isinstance(chat_member_type, cls)
        assert chat_member_type.user == user
        assert chat_member_type.status == status
        if chat_member_type.custom_title is not None:
            assert chat_member_type.custom_title == 'PTB'
            assert type(chat_member_type) in {ChatMemberOwner, ChatMemberAdministrator}
        if chat_member_type.is_anonymous is not None:
            assert chat_member_type.is_anonymous is True
            assert type(chat_member_type) in {ChatMemberOwner, ChatMemberAdministrator}
        if chat_member_type.until_date is not None:
            assert type(chat_member_type) in {ChatMemberBanned, ChatMemberRestricted}
        if chat_member_type.can_be_edited is not None:
            assert chat_member_type.can_be_edited is False
            assert type(chat_member_type) == ChatMemberAdministrator
        if chat_member_type.can_change_info is not None:
            assert chat_member_type.can_change_info is True
            assert type(chat_member_type) in {ChatMemberAdministrator, ChatMemberRestricted}
        if chat_member_type.can_post_messages is not None:
            assert chat_member_type.can_post_messages is False
            assert type(chat_member_type) == ChatMemberAdministrator
        if chat_member_type.can_edit_messages is not None:
            assert chat_member_type.can_edit_messages is True
            assert type(chat_member_type) == ChatMemberAdministrator
        if chat_member_type.can_delete_messages is not None:
            assert chat_member_type.can_delete_messages is True
            assert type(chat_member_type) == ChatMemberAdministrator
        if chat_member_type.can_invite_users is not None:
            assert chat_member_type.can_invite_users is False
            assert type(chat_member_type) in {ChatMemberAdministrator, ChatMemberRestricted}
        if chat_member_type.can_restrict_members is not None:
            assert chat_member_type.can_restrict_members is True
            assert type(chat_member_type) == ChatMemberAdministrator
        if chat_member_type.can_pin_messages is not None:
            assert chat_member_type.can_pin_messages is False
            assert type(chat_member_type) in {ChatMemberAdministrator, ChatMemberRestricted}
        if chat_member_type.can_promote_members is not None:
            assert chat_member_type.can_promote_members is True
            assert type(chat_member_type) == ChatMemberAdministrator
        if chat_member_type.can_send_messages is not None:
            assert chat_member_type.can_send_messages is False
            assert type(chat_member_type) == ChatMemberRestricted
        if chat_member_type.can_send_media_messages is not None:
            assert chat_member_type.can_send_media_messages is True
            assert type(chat_member_type) == ChatMemberRestricted
        if chat_member_type.can_send_polls is not None:
            assert chat_member_type.can_send_polls is False
            assert type(chat_member_type) == ChatMemberRestricted
        if chat_member_type.can_send_other_messages is not None:
            assert chat_member_type.can_send_other_messages is True
            assert type(chat_member_type) == ChatMemberRestricted
        if chat_member_type.can_add_web_page_previews is not None:
            assert chat_member_type.can_add_web_page_previews is False
            assert type(chat_member_type) == ChatMemberRestricted
        if chat_member_type.can_manage_chat is not None:
            assert chat_member_type.can_manage_chat is True
            assert type(chat_member_type) == ChatMemberAdministrator
        if chat_member_type.can_manage_voice_chats is not None:
            assert chat_member_type.can_manage_voice_chats is True
            assert type(chat_member_type) == ChatMemberAdministrator
    def test_de_json_invalid_status(self, bot, user):
        json_dict = {'status': 'invalid', 'user': user.to_dict()}
        chat_member_type = ChatMember.de_json(json_dict, bot)

        assert type(chat_member_type) is ChatMember
        assert chat_member_type.status == 'invalid'
    def test_de_json_invalid_status(self, chat_member_type, bot):
        json_dict = {"status": "invalid", "user": CMDefaults.user.to_dict()}
        chat_member_type = ChatMember.de_json(json_dict, bot)

        assert type(chat_member_type) is ChatMember
        assert chat_member_type.status == "invalid"