#NEWLINE# def assert_dispatch_to_spi( self , request , config , spi_path , expected_spi_body_json = None ) : #NEWLINE# #INDENT# 'Assert that dispatching a request to the SPI works.\n\n    Mock out the dispatcher.add_request and handle_spi_response, and use these\n    to ensure that the correct request is being sent to the back end when\n    Dispatch is called.\n\n    Args:\n      request: An ApiRequest, the request to dispatch.\n      config: A dict containing the API configuration.\n      spi_path: A string containing the relative path to the SPI.\n      expected_spi_body_json: If not None, this is a JSON object containing\n        the mock response sent by the back end.  If None, this will create an\n        empty response.\n    ' #NEWLINE# self . prepare_dispatch ( config ) #NEWLINE# spi_headers = [ ( 'Content-Type' , 'application/json' ) ] #NEWLINE# spi_body_json = ( expected_spi_body_json or { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# spi_response = dispatcher . ResponseTuple ( '200 OK' , [ ] , 'Test' ) #NEWLINE# self . mock_dispatcher . add_request ( 'POST' , spi_path , spi_headers , JsonMatches ( spi_body_json ) , request . source_ip ) . AndReturn ( spi_response ) #NEWLINE# self . mox . StubOutWithMock ( self . server , 'handle_spi_response' ) #NEWLINE# self . server . handle_spi_response ( mox . IsA ( api_request . ApiRequest ) , mox . IsA ( api_request . ApiRequest ) , spi_response , mox . IsA ( dict ) , self . start_response ) . AndReturn ( 'Test' ) #NEWLINE# self . mox . ReplayAll ( ) #NEWLINE# response = self . server . dispatch ( request , self . start_response ) #NEWLINE# self . mox . VerifyAll ( ) #NEWLINE# self . assertEqual ( 'Test' , response )