'How to mock messagebird client in python
I'm creating test in python, but I need to mock a messagebird client.
So, in the code, I'm creating a messagebird cliente then I call the message_create function, that is the function that I need to mock, like this:
client = messagebird.Client(settings.SMS_CLIENT_KEY)
client.message_create(
sender,
phone,
template,
{
'reference': f'cId-{id}',
'shortenUrls': True
}
)
And then, in my mock I'm doing this:
from messagebird import Client
def mock_messagebird_client_message_create():
with mock.patch.object(Client, 'message_create') as mocked_message_create:
mocked_message_create.return_value = True
yield mocked_message_create
But when I'm debugging apparently this doesn't work.
My question is, how can I mock a client from a external package, like the messagebird?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
