Run a testserver

When you want to develop a client library and want to build testcases that use a running RestAuth instance, you can easily run a testserver on your own.


The testserver uses an in-memory SQLite database and never touches any existing databases, it should even be save to run this on production systems.

Use virtualenv

The quickest way to get a testserver running is using virtualenv, which creates isolated Python environments. Using virtualenv, your system is not polluted with dependencies. Setting up a virtualenv is very simple:

virtualenv .
source bin/activate
pip install -r requirements.txt


If you don’t have pip installed, you have to install it using easy_install pip.

Run default testserver

You can run a testserver simply by executing

python testserver

This will create a testserver listing on ::1, port 8000. The testserver has some services preconfigured:

service password Notes nopass Has all permissions. nopass Has all permissions and the group orggroup predefined. nopass Only has group-permissions and the predefined group netgroup, which is a subgroup of the group orggroup in the service. nopass Does have all permissions, but you can’t connect to it from anywhere, because no hosts are defined for it.

No users or properties are preconfigured.

Running a custom testserver

It might be necessary for you to run a custom testserver. To do so, you have to use restauth-manage directly to start the testserver. The equivalent to the above is:

python RestAuth/ testserver --ipv6 RestAuth/fixtures/testserver.json

The testserver command provides a variety of options, simply run:

python RestAuth/ testserver --help

for a comprehensive list.

You might need your own testdata (for example, with some users and/or groups preconfigured), in which case you have to create a fixture. To do this, create a fresh database, add all necessary data and dump the data to a new fixture:

# create empty database:
python RestAuth/ syncdb --noinput
python RestAuth/ migrate
python RestAuth/ flush --noinput

# create testdata:
RestAuth/bin/ add --password=foobar
RestAuth/bin/ set-hosts ::1
RestAuth/bin/ set-permissions user* group* prop*
RestAuth/bin/ add --password=example example

# create fixture:
python RestAuth/ dumpdata > /path/to/your/library/fixtures/testserver.json

You can then run the testserver with your new fixture by running:

python RestAuth/ testserver --ipv6 /path/to/your/library/fixtures/testserver.json

Table Of Contents

Previous topic

How to contribute

Next topic

Custom backends

This Page