Stack

class stackinabox.stack.StackInABox

Stack-In-A-Box Testing Service.

StackInABox provides a testing framework for RESTful APIs

The framework provides a thread-local instance holding the StackInABoxService objects that are representing the RESTful APIs.

The StackInABox object provides a means of accessing it from anywhere in a thread; however, it is not necessarily thread-safe at this time. If one is careful o setup StackInABox and write StackInABoxService’s that are thread-safe themselves, then there is no reason it could not be used in a multi-threaded or multi-processed test.

base_url

Base URL property.

call(method, request, uri, headers)

Make a call into the thread’s StackInABox instance.

Parameters:
  • method – HTTP Method (e.g GET, POST)
  • request – a Request object containing the request data
  • uri – the URI of the request submitted with the method
  • headers – the return headers in a Case-Insensitive dict
Returns:

A tuple containing - (i) the Status Code, (ii) the response headers, and (iii) the response body data

This function should not emit any Exceptions

classmethod call_into(method, request, uri, headers)

Make a call into the thread’s StackInABox instance.

Parameters:
  • method – HTTP Method (e.g GET, POST)
  • request – a Request object containing the request data
  • uri – the URI of the request submitted with the method
  • headers – the return headers in a Case-Insensitive dict

For return value and errors see StackInABox.call()

from_hold(name)

Get data from the storage area provided by the framework.

Note: The data is retrieved from the thread local instance.

Parameters:name – name of the data to be retrieved
Returns:The data associated with the specified name.
Raises:Lookup/KeyError error if the name does not match a value in the storage
static get_services_url(base_url)

Get the URI from a given URL.

Returns:URI within the URL
classmethod hold_onto(name, obj)

Add data into the a storage area provided by the framework.

Note: The data is stored with the thread local instance.

Parameters:
  • name – name of the data to be stored
  • obj – data to be stored

For return value and errors see StackInABox.into_hold()

classmethod hold_out(name)

Get data from the storage area provided by the framework.

Note: The data is retrieved from the thread local instance.

Parameters:name – name of the data to be retrieved
Returns:The data associated with the specified name.

For errors see StackInABox.from_hold()

into_hold(name, obj)

Add data into the a storage area provided by the framework.

Note: The data is stored with the thread local instance.

Parameters:
  • name – name of the data to be stored
  • obj – data to be stored
Returns:

N/A

Raises:

N/A

register(service)

Add a service to the thread’s StackInABox instance.

Parameters:service – StackInABoxService instance to add to the test
Returns:None
Raises:ServiceAlreadyRegisteredError if the service already exists
classmethod register_service(service)

Add a service to the thread’s StackInABox instance.

Parameters:service – StackInABoxService instance to add to the test

For return value and errors see StackInABox.register()

reset()

Reset StackInABox to a like-new state.

classmethod reset_services()

Reset the thread’s StackInABox instance.

classmethod update_uri(uri)

Set the URI of the StackInABox framework.

Parameters:uri – the base URI used to match the service.