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

Class ApiMockServer

source code

                     object --+    
                              |    
multiprocessing.process.Process --+
                                  |
                                 ApiMockServer

Helper Class to interact with the ApiMockServer Provides methods to add, remove mock objects as well as incoming requests

Instance Methods [hide private]
 
__init__(self, port)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
run(self)
start the mock server
source code
 
start(self)
Start child process
source code
 
stop(self)
Shutdown the server and terminate process :return:
source code
 
add_response(self, url_filter=None, status_code=200, headers=None, body='', encoding='text', data=None)
Add the response to the mock server
source code
 
add_binary_response(self, url_filter=None, status_code=200, headers=None, body='')
Adds a binary response to the mock server
source code
 
add_text_response(self, url_filter=None, status_code=200, headers=None, body='')
Adds a binary response to the mock server
source code
 
get_responses(self)
Returns all the responses stored on the MockServer :return:
source code
 
clear_responses(self)
Delete all the responses stored on the MockServer :return:
source code
 
get_requests(self)
Returns all the requests stored on the MockServer :return:
source code
 
clear_requests(self)
Delete all the requests stored on the MockServer :return:
source code
 
host_ip(self)
Dirty hack to return the localhost IP, works only when you have an internet connection :return:
source code
 
_is_server_running(self)
check if the server is running and port is open
source code
 
_wait_for_server_to_start(self)
Latency to avoid the access when the server is not started yet
source code
 
get_base_url(self) source code

Inherited from multiprocessing.process.Process: __repr__, is_alive, join, terminate

Inherited from multiprocessing.process.Process (private): _bootstrap

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  server = <Flask 'tlib.base.ApiMockServer'>

Inherited from multiprocessing.process.Process (private): _Popen

Properties [hide private]

Inherited from multiprocessing.process.Process: authkey, daemon, exitcode, ident, name, pid

Inherited from object: __class__

Method Details [hide private]

__init__(self, port)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

run(self)

source code 

start the mock server

Overrides: multiprocessing.process.Process.run

start(self)

source code 

Start child process

Overrides: multiprocessing.process.Process.start
(inherited documentation)

add_response(self, url_filter=None, status_code=200, headers=None, body='', encoding='text', data=None)

source code 

Add the response to the mock server

:param url_filter: Regular expression to match the url path :type url_filter: str :param status_code: Expected status code :type status_code: int :param headers: Headers to return in the response :type headers: dict :param body: response body as plain text :type body: str :param encoding: If body is binary, this should be set to string "base64". Otherwise, leave empty or set to "text" :type encoding: str :param payload: a python dictionary :type payload: dict :param data: If provided, it will be the rule to add to the mock. :type data: str :return: Mock server response

add_binary_response(self, url_filter=None, status_code=200, headers=None, body='')

source code 

Adds a binary response to the mock server

:param url_filter: Regular expression to match the url path :type url_filter: str :param status_code: Expected status code :type status_code: int :param headers: Headers to return in the response :type headers: dict :param body: response body as plain text :type body: str :param encoding: If body is binary, this should be set to string "base64". Otherwise, leave empty or set to "text" :type encoding: str :param payload: a python dictionary :type payload: dict :return: Mock server response

add_text_response(self, url_filter=None, status_code=200, headers=None, body='')

source code 

Adds a binary response to the mock server

:param url_filter: Regular expression to match the url path :type url_filter: str :param status_code: Expected status code :type status_code: int :param headers: Headers to return in the response :type headers: dict :param body: response body as plain text :type body: str :param encoding: If body is binary, this should be set to string "base64". Otherwise, leave empty or set to "text" :type encoding: str :param payload: a python dictionary :type payload: dict :return: Mock server response