def httpretty_registration(uri): logger.debug( 'Registering Stack-In-A-Box at {0} under Python HTTPretty'.format(uri)) StackInABox.update_uri(uri) regex = re.compile('(http)?s?(://)?{0}:?(\d+)?/'.format(uri), re.I) for method in HttpBaseClass.METHODS: register_uri(method, regex, body=httpretty_callback)
def registration(uri): """Responses handler registration. Registers a handler for a given URI with Responses so that it can be intercepted and handed to Stack-In-A-Box. :param uri: URI used for the base of the HTTP requests :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 Responses'.format(uri)) # tell Stack-In-A-Box what URI to match with StackInABox.update_uri(uri) # Build the regex for the URI and register all HTTP verbs # with Responses regex = re.compile(r'(http)?s?(://)?{0}:?(\d+)?/'.format(uri), re.I) METHODS = [ responses.DELETE, responses.GET, responses.HEAD, responses.OPTIONS, responses.PATCH, responses.POST, responses.PUT ] for method in METHODS: responses.add_callback(method, regex, callback=responses_callback)
def registration(uri): """Responses handler registration. Registers a handler for a given URI with Responses so that it can be intercepted and handed to Stack-In-A-Box. :param uri: URI used for the base of the HTTP requests :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 Responses' .format(uri)) # tell Stack-In-A-Box what URI to match with StackInABox.update_uri(uri) # Build the regex for the URI and register all HTTP verbs # with Responses regex = re.compile('(http)?s?(://)?{0}:?(\d+)?/'.format(uri), re.I) METHODS = [ responses.DELETE, responses.GET, responses.HEAD, responses.OPTIONS, responses.PATCH, responses.POST, responses.PUT ] for method in METHODS: responses.add_callback(method, regex, callback=responses_callback)
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'))
def responses_registration(uri): logger.debug( 'Registering Stack-In-A-Box at {0} under Python Responses'.format(uri)) StackInABox.update_uri(uri) regex = re.compile('(http)?s?(://)?{0}:?(\d+)?/'.format(uri), re.I) METHODS = [ responses.DELETE, responses.GET, responses.HEAD, responses.OPTIONS, responses.PATCH, responses.POST, responses.PUT ] for method in METHODS: responses.add_callback(method, regex, callback=responses_callback)
def httpretty_registration(uri): status_data = { 595: 'StackInABoxService - Unknown Route', 596: 'StackInABox - Exception in Service Handler', 597: 'StackInABox - Unknown Service' } for k, v in six.iteritems(status_data): if k not in httpretty.http.STATUSES: httpretty.http.STATUSES[k] = v logger.debug( 'Registering Stack-In-A-Box at {0} under Python HTTPretty'.format(uri)) StackInABox.update_uri(uri) regex = re.compile('(http)?s?(://)?{0}:?(\d+)?/'.format(uri), re.I) for method in HttpBaseClass.METHODS: register_uri(method, regex, body=httpretty_callback)
def httpretty_registration(uri): status_data = { 595: 'StackInABoxService - Unknown Route', 596: 'StackInABox - Exception in Service Handler', 597: 'StackInABox - Unknown Service' } for k, v in six.iteritems(status_data): if k not in httpretty.http.STATUSES: httpretty.http.STATUSES[k] = v logger.debug('Registering Stack-In-A-Box at {0} under Python HTTPretty' .format(uri)) StackInABox.update_uri(uri) regex = re.compile('(http)?s?(://)?{0}:?(\d+)?/'.format(uri), re.I) for method in HttpBaseClass.METHODS: register_uri(method, regex, body=httpretty_callback)
def responses_registration(uri): logger.debug('Registering Stack-In-A-Box at {0} under Python Responses' .format(uri)) StackInABox.update_uri(uri) regex = re.compile('(http)?s?(://)?{0}:?(\d+)?/'.format(uri), re.I) METHODS = [ responses.DELETE, responses.GET, responses.HEAD, responses.OPTIONS, responses.PATCH, responses.POST, responses.PUT ] for method in METHODS: responses.add_callback(method, regex, callback=responses_callback)
def registration(uri): """httpretty handler registration. registers a handler for a given uri with httpretty so that it can be intercepted and handed to stack-in-a-box. :param uri: uri used for the base of the http requests :returns: n/a """ # add the stack-in-a-box specific response codes to # http's status information status_data = { 595: 'StackInABoxService - Unknown Route', 596: 'StackInABox - Exception in Service Handler', 597: 'StackInABox - Unknown Service' } for k, v in six.iteritems(status_data): if k not in httpretty.http.STATUSES: httpretty.http.STATUSES[k] = v # 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 HTTPretty' .format(uri)) # tell stack-in-a-box what uri to match with StackInABox.update_uri(uri) # build the regex for the uri and register all http verbs # with httpretty regex = re.compile('(http)?s?(://)?{0}:?(\d+)?/'.format(uri), re.I) for method in HttpBaseClass.METHODS: register_uri(method, regex, body=httpretty_callback)
def registration(uri): """httpretty handler registration. registers a handler for a given uri with httpretty so that it can be intercepted and handed to stack-in-a-box. :param uri: uri used for the base of the http requests :returns: n/a """ # add the stack-in-a-box specific response codes to # http's status information status_data = { 595: 'StackInABoxService - Unknown Route', 596: 'StackInABox - Exception in Service Handler', 597: 'StackInABox - Unknown Service' } for k, v in six.iteritems(status_data): if k not in httpretty.http.STATUSES: httpretty.http.STATUSES[k] = v # 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 HTTPretty' .format(uri)) # tell stack-in-a-box what uri to match with StackInABox.update_uri(uri) # build the regex for the uri and register all http verbs # with httpretty regex = re.compile(r'(http)?s?(://)?{0}:?(\d+)?/'.format(uri), re.I) for method in HttpBaseClass.METHODS: register_uri(method, regex, body=httpretty_callback)
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'))
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'))