Пример #1
0
def test_SendMediaGroupe():
    photo = api.InputMediaPhoto("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
    req = api.SendMediaGroup(1000, [photo])
    assert req.render() == {
        'chat_id': 1000,
        'media': [{
            'media': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
            'type': 'photo'
        }]
    }
    assert req.render(with_method=True) == {
        'method': 'SendMediaGroup',
        'chat_id': 1000,
        'media': [{
            'media': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
            'type': 'photo'
        }]
    }
    assert req.files() == []

    photo_file_1 = api.InputFile('photo1.jpg', 'image/jpeg', BytesIO())
    photo1 = api.InputMediaPhoto(photo_file_1,
                                 caption="Hello, World!",
                                 parse_mode=api.ParseModeType.html)

    photo_file_2 = api.InputFile('photo2.jpg', 'image/jpeg', BytesIO())
    photo2 = api.InputMediaPhoto(photo_file_2,
                                 caption="Hello, World!",
                                 parse_mode=api.ParseModeType.html)

    req = api.SendMediaGroup(1000, [photo1, photo2],
                             disable_notification=True,
                             reply_to_message_id=100)

    assert req.render() == {
        'chat_id':
        1000,
        'media': [{
            'media': 'attach://photo1.jpg',
            'type': 'photo',
            'caption': 'Hello, World!',
            'parse_mode': 'html'
        }, {
            'media': 'attach://photo2.jpg',
            'type': 'photo',
            'caption': 'Hello, World!',
            'parse_mode': 'html'
        }],
        'disable_notification':
        True,
        'reply_to_message_id':
        100
    }

    assert req.files() == [photo_file_1, photo_file_2]
Пример #2
0
def test_SendVideo():
    req = api.SendVideo(1000, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
    assert req.render() == {
        'chat_id': 1000,
        'video': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    }
    assert req.render(with_method=True) == {
        'method': 'SendVideo',
        'chat_id': 1000,
        'video': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    }
    assert req.files() == []

    video_file = api.InputFile('video.mp4', 'video/mp4', BytesIO())
    thumb_file = api.InputFile('thumb.jpg', 'image/jpeg', BytesIO())

    kb = api.InlineKeyboardMarkup(
        [[api.InlineKeyboardButton('Button', callback_data='data')]])
    req = api.SendVideo(1000,
                        video_file,
                        duration=300,
                        width=640,
                        height=480,
                        supports_streaming=True,
                        thumb=thumb_file,
                        caption="Hello, World!",
                        parse_mode=api.ParseModeType.html,
                        disable_notification=True,
                        reply_to_message_id=100,
                        reply_markup=kb)

    assert req.render() == {
        'chat_id': 1000,
        'video': 'attach://video.mp4',
        'duration': 300,
        'width': 640,
        'height': 480,
        'supports_streaming': True,
        'thumb': 'attach://thumb.jpg',
        'caption': 'Hello, World!',
        'parse_mode': 'html',
        'disable_notification': True,
        'reply_to_message_id': 100,
        'reply_markup': {
            'inline_keyboard': [[{
                'callback_data': 'data',
                'text': 'Button'
            }]]
        }
    }

    assert req.files() == [video_file, thumb_file]
Пример #3
0
def test_SendAudio():
    req = api.SendAudio(1000, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
    assert req.render() == {
        'chat_id': 1000,
        'audio': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    }
    assert req.render(with_method=True) == {
        'method': 'SendAudio',
        'chat_id': 1000,
        'audio': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    }
    assert req.files() == []

    audio_file = api.InputFile('audio.mp3', 'audio/mpeg', BytesIO())
    thumb_file = api.InputFile('thumb.jpg', 'image/jpeg', BytesIO())

    kb = api.InlineKeyboardMarkup(
        [[api.InlineKeyboardButton('Button', callback_data='data')]])
    req = api.SendAudio(1000,
                        audio_file,
                        duration=300,
                        performer="Beethoven",
                        title="Symphony No. 5",
                        thumb=thumb_file,
                        caption="Hello, World!",
                        parse_mode=api.ParseModeType.html,
                        disable_notification=True,
                        reply_to_message_id=100,
                        reply_markup=kb)

    assert req.render() == {
        'chat_id': 1000,
        'audio': 'attach://audio.mp3',
        'duration': 300,
        'performer': "Beethoven",
        'title': "Symphony No. 5",
        'thumb': 'attach://thumb.jpg',
        'caption': 'Hello, World!',
        'parse_mode': 'html',
        'disable_notification': True,
        'reply_to_message_id': 100,
        'reply_markup': {
            'inline_keyboard': [[{
                'callback_data': 'data',
                'text': 'Button'
            }]]
        }
    }

    assert req.files() == [audio_file, thumb_file]
Пример #4
0
def test_SetWebhook():
    req = api.SetWebhook(url='https://www.example.com/bot')

    assert req.render() == {'url': 'https://www.example.com/bot'}
    assert req.render(with_method=True) == {
        'method': 'SetWebhook',
        'url': 'https://www.example.com/bot'
    }
    assert req.files() == []

    req = api.SetWebhook(
        url='https://www.example.com/bot',
        certificate='https://www.example.com/cert/cert.crt',
        max_connections=10,
        allowed_updates=[api.UpdateType.message, api.UpdateType.channel_post])

    assert req.render() == {
        'url': 'https://www.example.com/bot',
        'allowed_updates': ['message', 'channel_post'],
        'max_connections': 10,
        'certificate': 'https://www.example.com/cert/cert.crt'
    }

    file = api.InputFile('cert.crt', 'application/x-x509-ca-cert', BytesIO())
    req = api.SetWebhook(url='https://www.example.com/bot', certificate=file)

    assert req.render() == {
        'url': 'https://www.example.com/bot',
        'certificate': 'attach://cert.crt'
    }
    assert req.files() == [file]
Пример #5
0
def test_SendVideoNote():
    req = api.SendVideoNote(1000, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
    assert req.render() == {
        'chat_id': 1000,
        'video_note': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    }
    assert req.render(with_method=True) == {
        'method': 'SendVideoNote',
        'chat_id': 1000,
        'video_note': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    }
    assert req.files() == []

    note_file = api.InputFile('voice.opus', 'audio/ogg', BytesIO())
    thumb_file = api.InputFile('thumb.jpg', 'image/jpeg', BytesIO())

    kb = api.InlineKeyboardMarkup(
        [[api.InlineKeyboardButton('Button', callback_data='data')]])
    req = api.SendVideoNote(1000,
                            note_file,
                            duration=300,
                            length=500,
                            thumb=thumb_file,
                            disable_notification=True,
                            reply_to_message_id=100,
                            reply_markup=kb)

    assert req.render() == {
        'chat_id': 1000,
        'video_note': 'attach://voice.opus',
        'duration': 300,
        'length': 500,
        'thumb': 'attach://thumb.jpg',
        'disable_notification': True,
        'reply_to_message_id': 100,
        'reply_markup': {
            'inline_keyboard': [[{
                'callback_data': 'data',
                'text': 'Button'
            }]]
        }
    }

    assert req.files() == [note_file, thumb_file]
Пример #6
0
def test_SendDocument():
    req = api.SendDocument(1000, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
    assert req.render() == {
        'chat_id': 1000,
        'document': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    }
    assert req.render(with_method=True) == {
        'method': 'SendDocument',
        'chat_id': 1000,
        'document': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    }
    assert req.files() == []

    document_file = api.InputFile('document.pdf', 'application/pdf', BytesIO())
    thumb_file = api.InputFile('thumb.jpg', 'image/jpeg', BytesIO())

    kb = api.InlineKeyboardMarkup(
        [[api.InlineKeyboardButton('Button', callback_data='data')]])
    req = api.SendDocument(1000,
                           document_file,
                           thumb=thumb_file,
                           caption="Hello, World!",
                           parse_mode=api.ParseModeType.html,
                           disable_notification=True,
                           reply_to_message_id=100,
                           reply_markup=kb)

    assert req.render() == {
        'chat_id': 1000,
        'document': 'attach://document.pdf',
        'thumb': 'attach://thumb.jpg',
        'caption': 'Hello, World!',
        'parse_mode': 'html',
        'disable_notification': True,
        'reply_to_message_id': 100,
        'reply_markup': {
            'inline_keyboard': [[{
                'callback_data': 'data',
                'text': 'Button'
            }]]
        }
    }

    assert req.files() == [document_file, thumb_file]
Пример #7
0
def test_SendVoice():
    req = api.SendVoice(1000, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
    assert req.render() == {
        'chat_id': 1000,
        'voice': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    }
    assert req.render(with_method=True) == {
        'method': 'SendVoice',
        'chat_id': 1000,
        'voice': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    }
    assert req.files() == []

    voice_file = api.InputFile('voice.opus', 'audio/ogg', BytesIO())

    kb = api.InlineKeyboardMarkup(
        [[api.InlineKeyboardButton('Button', callback_data='data')]])
    req = api.SendVoice(1000,
                        voice_file,
                        duration=300,
                        caption="Hello, World!",
                        parse_mode=api.ParseModeType.html,
                        disable_notification=True,
                        reply_to_message_id=100,
                        reply_markup=kb)

    assert req.render() == {
        'chat_id': 1000,
        'voice': 'attach://voice.opus',
        'duration': 300,
        'caption': 'Hello, World!',
        'parse_mode': 'html',
        'disable_notification': True,
        'reply_to_message_id': 100,
        'reply_markup': {
            'inline_keyboard': [[{
                'callback_data': 'data',
                'text': 'Button'
            }]]
        }
    }

    assert req.files() == [voice_file]