Loading...
 

Python Mocking

Mocking

HTTP

import mock
from googleapiclient.http import HttpMock
from googleapiclient import discovery

response_file = 'path/to/mocked_response_payload.json'
http_mock = HttpMock(response_file, {'status': '200'})
service_object = discovery.build('storage', 'v1', http=http_mock)

thing_to_mock = mock.MagicMock()
expected_response = {'my_leu': 'my value'}
thing_to_mock.someClass.function_being_mocked.return_value = expected_response
service_object.attribute_to_query = mock.MagicMock(return_value=http_mock)

function_to_test(service_object, **kwargs)