Fixtures in Django are essentially dumps of part of the database. They contain data for the various models and can be loaded in automatically for unit tests. This makes it quite easy for us to have various sets of data to test against.

For our tests, we currently have three sets of fixtures:

  1. reviewboard/accounts/fixtures/test_users.json - users and profiles
  2. reviewboard/scmtools/fixtures/test_scmtools/json - repository and SCMTools
  3. reviewboard/site/fixtures/test_site.json - Local Sites

In addition to fixtures, the reviewboard.testing.testcase.TestCase base class includes several methods for creating objects in the database, such as Review Requests, Reviews, Comments, Repositories, and others. These are not included in fixtures because of the variety of data that can be included, and loading fixtures incurs a noticible cost on the time to run the test suite.

Updating Fixtures

It's very rare that you'd need to update fixtures, but if you do need to, you’ll first want to modify settings_local.py, set your database to be sqlite3 (if it’s not already) and change the database name to something like unittests.db. You’ll also need to install the django-reset package. Then:

$ ./reviewboard/manage.py upgrade --noinput
$ ./reviewboard/manage.py reset --noinput scmtools
$ ./reviewboard/manage.py loaddata test_users test_scmtools test_site

This should populate your database with the test data.

After you’ve added to the data set, dump them back out:

$ ./reviewboard/manage.py dumpdata --indent=4 \\
    auth accounts > reviewboard/accounts/fixtures/test_users.json
$ ./reviewboard/manage.py dumpdata --indent=4 \\
    scmtools > reviewboard/scmtools/fixtures/test_scmtools.json
$ ./reviewboard/manage.py dumpdata --indent=4 \\
    site > reviewboard/scmtools/fixtures/test_site.json