예제 #1
0
def test_telegram_api_request(mocked_requests):
    '''Make sure requests.post is being called with the right args'''

    api = TelegramAPI('token')
    url = api.make_url('send_message')
    data = {
        'chat_id': 1,
        'text': 'Hello World',
    }
    api.send_message(data=data)

    mocked_requests.post.assert_called_once_with(url, json=data)
예제 #2
0
async def test_telegram_api_request(token, session):
    '''Make sure session.post is being called with the right args'''

    api = TelegramAPI(token, session)

    expected_url = api.make_url('send_message')
    expected_data = {
        'chat_id': 1,
        'text': 'Hello World',
    }

    await api.send_message(**expected_data)
    expected_url = 'https://api.telegram.org/bot{}/sendMessage'.format(token)
    session.post.assert_called_once_with(expected_url, json=expected_data)
예제 #3
0
async def test_telegram_api_method_not_defined(token, session):
    api = TelegramAPI(token, session)
    with pytest.raises(AttributeError):
        # This is returning a warning but I do not know why:
        # RuntimeWarning: coroutine 'session.<locals>.fake_post' was never
        # awaited.
        await api.get_chat_member()
예제 #4
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.api = TelegramAPI(self.token, session=self.session)

        # If no `mode` was defined at settings.py, use by default
        # polling mode. We need to test if `mode` is either `polling`
        # or `webhook`, if not, raise ImproperlyConfigured.
        if not hasattr(self, 'mode'):
            self.mode = 'polling'
예제 #5
0
def test_telegram_api_method_not_defined():
    api = TelegramAPI('token')
    with pytest.raises(AttributeError):
        api.get_chat_member()
예제 #6
0
def test_telegram_api_url():
    token = 123
    api = TelegramAPI(token)
    expected_url = 'https://api.telegram.org/bot123/setWebhook'
    assert api.make_url('set_webhook') == expected_url
예제 #7
0
def test_telegram_api_url(token, session):
    api = TelegramAPI(token, session)
    expected_url = 'https://api.telegram.org/bot{}/setWebhook'.format(token)
    assert api.make_url('set_webhook') == expected_url