Django Test Tools¶
Simple tests tools to make testing faster and easier. Most of the tools are to do a quick scaffolding for tests.
The tools presume a naming convention:
- Tests: Are named with the convention TestCaseModelName. For a model named Poll the test would be generated as the testing class would be TestCasePoll
- Factories: Are named with the convention ModelName. For a model named Poll the test would be generated as the testing class would be PollFactory
- Serializers: Are named with the convention TestCaseSerializer. For a model named Poll the test would be generated as the testing class would be PollSerializer
Compatibility matrix:
Python version | Django 1.11.x | Django 2.2.x | Django 3.0.x |
3.7 | x | x | x |
3.6 | x | x | x |
Documentation¶
The full documentation is at https://django-test-tools.readthedocs.io.
Quickstart¶
Install Django Test Tools:
pip install django-test-tools
In your settings.py file add it to your INSTALLED_APPS
INSTALLED_APPS = (
...
'django_test_tools',
...
)
Add the settings variable TEST_OUTPUT_PATH
import environ
ROOT_DIR = (
environ.Path(__file__) - 3
) # (alpha_clinic/config/settings/base.py - 3 = alpha_clinic/)
APPS_DIR = ROOT_DIR.path("myapp")
TEST_OUTPUT_PATH = ROOT_DIR.path("output").root
Features¶
Factory Generator¶
$ python manage.py generate_factories project.app
Model Test Case Generator¶
$ python manage.py generate_model_test_cases project.app
Serializer Generator¶
$ python manage.py generate_serializers project.app -s ModelSerializer
Running Tests¶
Does the code actually work?
source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ tox
Builds¶
$ make patch
Check the .travis.yml to make sure the versions of Djago are the latests. Check in https://www.djangoproject.com/download/ for the latest versions.
Close the git-flow release.
Instead of patch you could also use major o minor depending on the level of the release.
make upload