import pytest

from bottery.plataform.telegram import TelegramAPI, TelegramUser, mixed_case


# TelegramUser

def test_telegram_user_with_last_name():
    sender = {
        'id': 1,
        'first_name': 'Andrew',
        'last_name': 'Martin',
    }

    user = TelegramUser(sender)
    assert str(user) == 'Andrew Martin (1)'


def test_telegram_user_without_last_name():
    sender = {
        'id': 1,
        'first_name': 'Andrew',
    }

    user = TelegramUser(sender)
    assert str(user) == 'Andrew (1)'


# TelegramAPI

def test_mixed_case():
    assert mixed_case('set_webhook') == 'setWebhook'
    assert mixed_case('get_chat_member') == 'getChatMember'


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


def test_telegram_api_method_not_defined():
    api = TelegramAPI('token')
    with pytest.raises(AttributeError):
        api.get_chat_member()

@@ -1,12 +1,39 @@
+from unittest import mock%0A%0A
 import pytes
@@ -1030,8 +1030,420 @@
 ember()%0A
+%0A%0A@mock.patch('bottery.plataform.telegram.requests')%0Adef test_telegram_api_request(mocked_requests):%0A    '''Make sure requests.post is being called with the right args'''%0A%0A    api = TelegramAPI('token')%0A    url = api.make_url('send_message')%0A    data = %7B%0A        'chat_id': 1,%0A        'text': 'Hello World',%0A    %7D%0A    api.send_message(data=data)%0A%0A    mocked_requests.post.assert_called_once_with(url, json=data)%0A

Test requests.post on TelegramAPI