You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We've been successfully testing our requests to Plivo and mocking Plivo responses with https://github.com/patrys/httmock. A sample code looks like this:
def test_delete_phone_number(self):
requests_list = [] # track all the requests made to plivo
@urlmatch(netloc='api\.plivo\.com')
def response_content(url, request):
requests_list.append((request.method, url.geturl()))
return { 'status_code': 204, 'content': '' }
with HTTMock(response_content):
resp = self.delete('/api/v1/phone_number/{}/'.format(pn.pk), api_key=test_api_key)
response_success(resp)
# Assert that we only made a single DELETE request to Plivo
self.assertEqual(requests_list, [
('DELETE', 'https://api.plivo.com/v1/Account/TEST_PLIVO_AUTH_ID/Number/16503334444/')
])
You can also have a more sophisticated logic of what to respond with depending on the request data/url and you can put asserts inside of response_content. Hope this is helpful.
--use-mirrors
The text was updated successfully, but these errors were encountered: