Skip to content

kmjawadurrahman/fastapi-tdd-docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Test-Driven Development with FastAPI and Docker

Learn how to build, test, and deploy a text summarization microservice with Python, FastAPI and Docker.

Continuous Integration and Delivery

Table of contents

About

fastapi-tdd-docker is a code-along to the course Test-Driven Development with FastAPI and Docker by Michael Herman.

Link to original repo.

Tools and technologies

  • Python
  • FastAPI
  • Docker & Docker Compose
  • Postgres
  • Tortoise ORM
  • Pytest
  • Uvicorn
  • Coverage.py
  • flake8
  • Black
  • isort
  • HTTPie
  • GitHub Actions
  • GitHub Packages
  • Gunicorn
  • Heroku
  • Swagger/OpenAPI

Project structure

├── .github
│   └── workflows
│       └── main.yml
├── .gitignore
├── README.md
├── docker-compose.yml
├── project
│   ├── .coverage
│   ├── .coveragerc
│   ├── .dockerignore
│   ├── Dockerfile
│   ├── Dockerfile.prod
│   ├── app
│   │   ├── __init__.py
│   │   ├── api
│   │   │   ├── __init__.py
│   │   │   ├── crud.py
│   │   │   ├── ping.py
│   │   │   └── summaries.py
│   │   ├── config.py
│   │   ├── db.py
│   │   ├── main.py
│   │   ├── models
│   │   │   ├── __init__.py
│   │   │   ├── pydantic.py
│   │   │   └── tortoise.py
│   │   └── summarizer.py
│   ├── db
│   │   ├── Dockerfile
│   │   └── create.sql
│   ├── entrypoint.sh
│   ├── htmlcov
│   ├── requirements-dev.txt
│   ├── requirements.txt
│   ├── setup.cfg
│   └── tests
│       ├── __init__.py
│       ├── conftest.py
│       ├── test_ping.py
│       ├── test_summaries.py
│       └── test_summaries_unit.py
└── release.sh

Installation

Prerequisites:

1. Clone the repository

$ git clone https://github.com/kmjawadurrahman/fastapi-tdd-docker.git && cd fastapi-tdd-docker

2. Use Docker and Docker Compose

$ docker-compose up -d --build

3. Create the database

$ docker-compose exec web python app/db.py

Usage

$ docker-compose up -d

Docs

Go to http://localhost:8002/docs.

Access the database via psql

$ docker-compose exec web-db psql -U postgres

Tests

$ docker-compose exec web python -m pytest

Unit Tests with Monkey-patching:

$ docker-compose exec web pytest -k "unit" -n auto