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
 
stop(self)
Shutdown the server and terminate process :return:
source code
 
add_response(self, url_filter=None, status_code=200, headers=None, body='', data=None)
Add the response to the mock server if the payload is provided, other parameters are ignored
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, start, 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

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

source code 

Add the response to the mock server if the payload is provided, other parameters are ignored

:param url_filter: Regular expression to match the url path :param status_code: Expected status code :param headers: Headers as a dictionary :param body: response body as plain text :param payload: a python dictionary :return: HTTP status code