A one-stop website to find all news, updates, and much more regarding the Artificial Intelligence Club at North Carolina State University.
Install Docker and Docker-Compose or make sure they are updated to the latest version if they are already installed. Build and start the development Docker containers with the following command:
docker compose up --build
If all works well, you should be able to create an admin account with:
docker compose run --rm backend python manage.py createsuperuser
docker compose run --rm backend python manage.py loaddata dev-fixtures.json
docker compose run --rm backend python manage.py dumpdata --exclude=auth --exclude=contenttypes --exclude=admin --exclude=sessions --exclude=users -o dev-fixtures.json
You can run all the backend unit tests at once with the following command:
docker compose run --rm backend coverage run manage.py test
There is also a helper script which runs all the unit tests which can be executed with the following command:
docker compose run --rm backend /test.sh
Additionally, if you would like to skip generating an HTML coverage report, you can do so by including the --no-html
option (-nh
for short) like so:
docker compose run --rm backend /test.sh --no-html
Every backend unit test should be decorated with the Django tag decorator to enable the running of smaller subsets tests that are common in some way. Tags should be defined as attributes of the Tags
enumeration in the core.testcases
module. The following is an example of tagging a test:
from core.testcases import Tags, VerboseTestCase
class ExampleTestCase(VerboseTestCase):
@tag(Tags.MODEL)
def test_model_example(self):
self.fail('Not yet implemented.')
Following from this example, in order to only run units tests with the MODEL
tag, you can run the following command:
docker compose run --rm backend python manage.py test --tag=model
Note that you use the enumeration member value 'model'
rather than the name of the member MODEL
. Also note that coverage cannot be used when running tests in this manner.
For more complex usage of Django tags (e.g., tagging a test with multiple tags, and excluding tests by tag when running tests) please refer to the official documentation.
In order to view the test coverage breakdown of the most recent test execution, run the following command after doing a full run of all the tests:
docker compose run --rm backend coverage report
Alternatively, if you wish to view a more detailed breakdown of the test coverage report, you can generate an HTML version of the report which allows you to explore which lines of code were run, missed or excluded. First, run the following command:
docker compose run --rm backend coverage html
Then, open the generated index.html
file in the backend/htmlcov
directory with your preferred web browser.
There is a shell script included in the backend/scripts
directory to make running all of the backend unit tests and generating an HTML coverage report more convenient. The script can be run with the following command:
docker compose run --rm backend /test.sh
You can also use the optional --no-html
(shorthand -nh
) command-line argument if you want to skip generating an HTML coverage report. For example:
docker compose run --rm backend /test.sh -nh
TODO