Django minimal example application and testing experiments.
VIRT_ENV_DIR - environmental variable containing the virtual environment path
PROJECT_ROOT_DIR - top project root directory
Once the virtual environment is installed, set it up in the
activate it and verify:
which pip- points to the
python -c "import django; print(django.get_version())"
pip install -r requirements.txt
Project set up
django-admin startproject MYPROJECT
The automatically created files locations were manipulated with and the paths in the files adjusted.
- description of the projects's created [here](files: https://docs.djangoproject.com/en/1.8/intro/tutorial01)
These files will already work as a first simple application themselves - test that the files are functional and that the application loads - start the development server.
Create a web application within the projects into which the business logic will be implemented:
cd $PROJECT_ROOT_DIR python manage.py startapp pollsapp
This creates views, models, etc empty files.
Database set up - PostgreSQL
- start and set up database (see
settings.py) (database user):
createdb myapp_experiment psql myapp_experiment
On the opened PostgreSQL console:
create user myapp_user with password 'my_very_secret_password'; alter database myapp_experiment owner to myapp_user; alter user myapp_user CREATEDB; # will be creating databases during testing
Set up schema for the requisite Django components (as defined in
python manage.py migrate
Start the development server
python manage.py runserver 8080
The main test framework is py.test.
The database server needs to be up and running prior running the test suite.
Running the test suite:
source venv/bin/activate py.test -vv -rfsX -s tests
The command will look up only in the
test directory and won't pick up
all the test files from Django, etc from the
It's either necessary to set
or use the
pytest.ini file with the same setting.
Force re-running a migration
We want to run a previously run existing migration
0002. So we'll fake the
python manage.py migrate --fake pollsapp 0001 python manage.py migrate