Testing

RESTArt provides a small set of tools that come in handy when writing tests.

The test client

The test client is a Python class that acts as a dummy Web client, allowing you to test your resources and interact with your RESTArt-powered APIs programmatically.

class restart.testing.Client(api)

The class used as a test client.

Example:

client = Client(api)
# GET /examples
response = client.get('/examples')
# POST /examples
response = client.post('/examples', data='{"name": "test"}',
                       content_type='application/json')
Parameters:api – the RESTArt API object.

The request factory

The RequestFactory provides a way to generate a request instance that can be used as the first argument to any resource. This means you can test a resource very easy.

class restart.testing.RequestFactory(keep_initial_request=False)

The class used to generate request objects.

Example:

factory = RequestFactory()
# GET /examples
request = factory.get('/examples')
# POST /examples
request = factory.post('/examples', data='{"name": "test"}',
                       content_type='application/json')
Parameters:keep_initial_request – a boolean value. If set to True, the request object generated by the factory will be the initial request object, which is framework-specific. If not specified, defaults to False, then the final adapted request object will be generated.