This is a Python project built using Django framework built using TDD practices. This README file provides instructions on setting up the project and running various tasks such as creating a virtual environment, running the local development server, managing migrations, and running tests.
Before setting up the project, ensure that you have the following prerequisites installed on your system:
- Python 3.11.x (latest Python 3.11 patch-level)
- pip package manager
- Clone the project repository:
git clone [email protected]:eduardorezaghi/tdd-python-django.git
cd tdd-python-django
- Create and activate a virtual environment using
virtualenvwrapper
. If you don't havevirtualenvwrapper
installed, you can install it using pip:
pip install virtualenvwrapper
After the installation completes, you need to configure your shell to work with virtualenvwrapper
. The configuration involves setting up environment variables and updating your shell's startup file (~/.bashrc
, ~/.bash_profile
, or ~/.zshrc
, depending on your shell).
- Open the shell's startup file in a text editor:
nano ~/.bashrc # or ~/.bash_profile or ~/.zshrc
- Add the following lines at the end of the file:
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python # Path to your Python interpreter
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh # Path to virtualenvwrapper.sh
Note: If the virtualenvwrapper.sh file is located in a different path, adjust the source line accordingly.
Reload the shell's startup file to apply the changes. Run one of the following commands depending on your shell:
For Bash or Zsh:
source ~/.bashrc # or ~/.zshrc
With the shell reloaded, you should now be able to use virtualenvwrapper commands. Test it by running:
workon
This command should list any existing virtual environments or display an empty list if none exist yet.
- Create a virtual environment named
tdd-python-django
:
mkvirtualenv tdd-python-django
- Activate the virtual environment:
workon tdd-python-django
To deactivate the virtual environment and return to your default system environment, execute:
deactivate
- Install the project dependencies:
pip install -r requirements.txt
- Run database migrations:
cd superlists/
python manage.py migrate
- To start the local development server, execute the following command:
cd superlists/
python manage.py runserver
By default, the server will run on http://localhost:8000/. Open this URL in your web browser to access the application.
Django provides a built-in migration system to manage changes to your database schema. To create and apply new migrations, use the following commands (while being on superlists/
folder):
- Create a new migration based on the changes you made to your models:
python manage.py makemigrations
- Apply pending migrations to the database:
python manage.py migrate
This project includes unit and functional tests that can be run either by a manage.py command or by using the functional_tests.py file. To execute the tests, use the following command (while being on superlists/
folder):
- Unit tests:
python manage.py tests
- Functional (or E2E) tests:
python manage.py test functional_tests