Skip to content

Testing

AB edited this page May 5, 2021 · 1 revision

Contents

  1. Django Tests
  2. React Tests

Tests

Django

Django tests are run using Django's test system, based on the standard python unittest module.

A custom settings settings module is available for testing, which tells Django to use an in-memory sqlite3 database instead of the postgresql database and to use an in-memory cache instead of Redis. To run the full test suite locally:

$ cd hackathon_site
$ python manage.py test --settings=hackathon_site.settings.ci

Fixtures

Django has fixtures which are hardcoded files (YAML/JSON) that provide initial data for models. They are placed in a fixtures folder under each app.

More information at this link.

To load fixtures into the database, use the command python manage.py loaddata <fixturename> where <fixturename> is the name of the fixture file you’ve created. Each time you run loaddata, the data will be read from the fixture and re-loaded into the database. Note this means that if you change one of the rows created by a fixture and then run loaddata again, you’ll wipe out any changes you’ve made.

React

React tests are handled by Jest. To run the full suite of React tests:

$ cd hackathon_site/dashboard/frontend
$ yarn test