This is a simple project to demonstrate how to build a FastAPI application using Test Driven Development (TDD) as a development process. The project uses Docker and docker compose
to containerize the application and Postgres database. Pytest is used as the testing framework.
.
├── app
│ ├── __init__.py
│ ├── main.py
│ ├── config.py
│ ├── db.py
│ ├── models
│ │ ├── __init__.py
│ │ └── tortoise.py
├── db
│ ├── Dockerfile
│ └── create.sql
├── migrations
│ ├── models
├── .dockerignore
├── .gitignore
├── docker-compose.yml
├── Dockerfile
├── entrypoint.sh
├── Pipfile
├── Pipfile.lock
├── README.md
└── pyproject.toml
- FastAPI
- Docker
- Postgres
- Pytest
- Tortoise ORM
- Aerich
- Clone the repository
git clone https://github.com/dhavalsavalia/fastapi-tdd-docker.git
- Change directory to the project directory
cd fastapi-tdd-docker
- Build the Docker images
docker compose build --no-cache
- Run the Docker containers
docker compose up -d --build
To run the tests, execute the following command:
docker-compose exec web python -m pytest
To run migrations, execute the following command:
docker-compose exec web aerich upgrade