Package tlib :: Package base :: Module ApiMockServer
[hide private]
[frames] | no frames]

Module ApiMockServer

source code

Classes [hide private]
  ApiMockServer
Helper Class to interact with the ApiMockServer Provides methods to add, remove mock objects as well as incoming requests
Functions [hide private]
 
generate_error_response(message, status_code)
Method to build an error response and log it
source code
 
shutdown() source code
 
add_response()
This method adds new responses to the mock.
source code
 
clear_responses()
Delete existing responses
source code
 
get_responses()
Get all responses
source code
 
clear_requests()
Delete existing requests
source code
 
get_requests()
Get all requests
source code
 
catch_all(path)
This method will catch all requests for which there are no explicit routes.
source code
Variables [hide private]
  mock_server = <Flask 'tlib.base.ApiMockServer'>
  _rules = OrderedDict()
  _req_urls = []
  _requests = []
  __package__ = 'tlib.base'
Function Details [hide private]

shutdown()

source code 
Decorators:
  • @mock_server.route("/mock/shutdown", methods= ['GET'])

add_response()

source code 

This method adds new responses to the mock.
To add a response send a POST request with a payload like this:

{
    "url_filter": ".*",
    "headers": {
        "Accept": "text/xml"
    },
    "body": "Sample body",
    "status_code": 200
}

Server will validate each matching rule and apply the first match
If there is no match, it will return a 500 response

To add binary responses, send data encoded in base64 and add this value to the request
"encoding": "base64".
For example:

{
    "url_filter": "/file.zip",
    "headers": {
        "Accept": "application/zip"
    },
    "body": "ADRFDRRFJFJJSMMSK",
    "encoding": "base64",
    "status_code": 200
}

Decorators:
  • @mock_server.route("/mock/responses", methods= ['POST'])

clear_responses()

source code 

Delete existing responses

Decorators:
  • @mock_server.route("/mock/responses", methods= ['DELETE'])

get_responses()

source code 

Get all responses

Decorators:
  • @mock_server.route("/mock/responses", methods= ['GET'])

clear_requests()

source code 

Delete existing requests

Decorators:
  • @mock_server.route("/mock/requests", methods= ['DELETE'])

get_requests()

source code 

Get all requests

Decorators:
  • @mock_server.route("/mock/requests", methods= ['GET'])

catch_all(path)

source code 

This method will catch all requests for which there are no explicit routes. Here is where we build responses based on the rules that have been configured It will go though the list of rules and apply one by one until a match is found. If there is no match, it will return a 500 response

Decorators:
  • @mock_server.route('/', defaults= {'path': ''}, methods= ['GET', 'POST', 'PUT', 'DELETE'])
  • @mock_server.route('/', methods= ['GET', 'POST', 'PUT', 'DELETE'])