Python googleapiclient.http.HttpMockSequence() Examples

The following are 3 code examples of googleapiclient.http.HttpMockSequence(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module googleapiclient.http , or try the search function .
Example #1
Source File: utils.py    From sheetfu with MIT License 6 votes vote down vote up
def mock_google_sheets_responses(fixture_files=None):
    """
    Function to mock one or multiple requests to sheets.
    :param fixture_files: Fixture file name (must be located in the fixture folder).
    :return: An HttpMockSequence object.
    """
    mocks = [({'status': '200'}, open_fixture('discovery.json'))]

    # If input is a string, transform it into list of one item
    if isinstance(fixture_files, str):
        fixture_files = [fixture_files]

    # Add each fixture as a request mock if any
    if fixture_files:
        for file in fixture_files:
            mocks.append(({'status': '200'}, open_fixture(file)))
    http_mocks = HttpMockSequence(mocks)
    return http_mocks 
Example #2
Source File: test_messaging.py    From firebase-admin-python with Apache License 2.0 5 votes vote down vote up
def _instrument_batch_messaging_service(self, app=None, status=200, payload=''):
        if not app:
            app = firebase_admin.get_app()
        fcm_service = messaging._get_messaging_service(app)
        if status == 200:
            content_type = 'multipart/mixed; boundary=boundary'
        else:
            content_type = 'application/json'
        fcm_service._transport = http.HttpMockSequence([
            ({'status': str(status), 'content-type': content_type}, payload),
        ])
        return fcm_service 
Example #3
Source File: http_mocks.py    From forseti-security with Apache License 2.0 5 votes vote down vote up
def mock_http_response_sequence(responses):
    """Set the mock response to an http request."""
    http_mock = http.HttpMockSequence(responses)
    _base_repository.LOCAL_THREAD.http = http_mock