Create a Python virtual environment.
python3.9 -m venv venvActivate it (on linux).
source ./venv/bin/activateInstall the requirements.
pip install -r requirements.txt
pip install -r requirements_dev.txtOn Windows there is a specific requirements file in tools/requirements_windows.txt.
Collect static files.
./manage.py collectstaticMigrate the database.
./manage.py migrateYou can now run the development server. Next time you want to start the server, this is the only command you will need (after activating your virtual environment).
./manage.py runserverAdditionnaly you can load a fixture located in dhost/demo/fixture.json. More informations in dhost/demo/README.md.
./manage.py loaddata demoIf you don't want to load the data in the database but still want to use the fixture, you can use the testserver.
./manage.py testserver dhost/demo/fixture.jsonRedis is used by Celery to execute tasks.
To start it manually
docker run -p 6379:6379 redis
To start Celery manually
celery -A dhost worker -l INFO
Note that you'll need to start Redis first.
To start Celery Flower manually
celery -A dhost flower
There is specific test settings available, this greatly improve speed, to use them simply specify the file when starting them.
./manage.py test --settings dhost.settings.testsNote that the test command is modified for this project, the new command can be found in dhost/core/management/commands/test.py, it's a minor modification witch delete the TEST_DIR located in the .cache folder (by default at the root of the project).
The TEST_DIR folder contain test datas and can be deleted safely after running a test. You can also delete it manually using the deltestdir command.
./manage.py deltestdirThe flag --noinput is available for the deltestdir command, it will tell Django to not prompt the user for any input, in this case the input is the delete confirmation.
Note that you can also choose to keep the test datas with the --keepdata flag when running tests:
./manage.py test --keepdataThe test command is modified to allow the testing of user models wich generate an avatar that is stored in the MEDIA_ROOT wich should be modified. The TEST_DIR can be modified in the settings or in env variables of the same name.
To use the custom MEDIA_ROOT in your test use the override_settings:
from django.conf import settings
from django.test import TestCase, override_settings
@override_settings(MEDIA_ROOT=settings.TEST_MEDIA_ROOT)
class ExampleTestCase(TestCase):
[...]To use coverage with django use:
coverage run manage.py testTo see the report use:
coverage report -mTo see the report in HTML format use:
coverage html