def requests_mock_session_registration(uri, session):
    logger.debug('Registering Stack-In-A-Box at {0} under Python Requests-Mock'
                 .format(uri))
    logger.debug('Session has id {0}'.format(id(session)))

    StackInABox.update_uri(uri)
    StackInABox.hold_onto('adapter', requests_mock.Adapter())
    StackInABox.hold_out('adapter').add_matcher(RequestMockCallable(uri))

    session.mount('http://{0}'.format(uri), StackInABox.hold_out('adapter'))
    session.mount('https://{0}'.format(uri), StackInABox.hold_out('adapter'))
Example #2
0
def session_registration(uri, session):
    """Requests-mock registration with a specific Session.

    :param uri: base URI to match against
    :param session: Python requests' Session object

    :returns: n/a
    """
    # log the URI that is used to access the Stack-In-A-Box services
    logger.debug('Registering Stack-In-A-Box at {0} under Python Requests-Mock'
                 .format(uri))
    logger.debug('Session has id {0}'.format(id(session)))

    # tell Stack-In-A-Box what URI to match with
    StackInABox.update_uri(uri)

    # Create a Python Requests Adapter object for handling the session
    StackInABox.hold_onto('adapter', requests_mock.Adapter())
    # Add the Request handler object for the URI
    StackInABox.hold_out('adapter').add_matcher(RequestMockCallable(uri))

    # Tell the session about the adapter and the URI
    session.mount('http://{0}'.format(uri), StackInABox.hold_out('adapter'))
    session.mount('https://{0}'.format(uri), StackInABox.hold_out('adapter'))
Example #3
0
def session_registration(uri, session):
    """Requests-mock registration with a specific Session.

    :param uri: base URI to match against
    :param session: Python requests' Session object

    :returns: n/a
    """
    # log the URI that is used to access the Stack-In-A-Box services
    logger.debug('Registering Stack-In-A-Box at {0} under Python Requests-Mock'
                 .format(uri))
    logger.debug('Session has id {0}'.format(id(session)))

    # tell Stack-In-A-Box what URI to match with
    StackInABox.update_uri(uri)

    # Create a Python Requests Adapter object for handling the session
    StackInABox.hold_onto('adapter', requests_mock.Adapter())
    # Add the Request handler object for the URI
    StackInABox.hold_out('adapter').add_matcher(RequestMockCallable(uri))

    # Tell the session about the adapter and the URI
    session.mount('http://{0}'.format(uri), StackInABox.hold_out('adapter'))
    session.mount('https://{0}'.format(uri), StackInABox.hold_out('adapter'))