Flask TDD Docker
Developing a Flask REST API with Docker, using TDD principles
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
Table of Contents
About The Project
The repo represents my learning progress with the testdriven.io course with Flask and Docker.
See a live demo on Heroku.
Built With
- Flask
- Flask-RESTful
- Docker
- pytest
Getting Started
To get a local copy up and running follow these steps.
Prerequisites
- Docker 19.03.4
- docker-compose 1.25.0
Installation
- Get the flask-tdd-docker repository
or, if you have Node.js on your machine:
git clone https://github.com/sophiabrandt/flask-tdd-docker.git
npx degit https://github.com/sophiabrandt/flask-tdd-docker.git flask-tdd-docker
- Build docker containers
docker-compose build
- Run docker containers
docker-compose up -d
Usage
-
Run tests:
docker-compose exec users pytest "project/tests" -p no:warnings
-
Run test coverage:
docker-compose exec users pytest "project/tests" -p no:warnings --cov="project"
-
Recreate database:
docker-compose exec users python manage.py recreate_db
-
Seed database:
docker-compose exec users python manage.py seed_db
-
Run flake8, black, isort:
docker-compose exec users flake8 project docker-compose exec users black project docker-compose exec users /bin/sh -c "isort project/*/*.py"
-
Query all users:
curl http://localhost:5001/users
curl https://desolate-cliffs-02122.herokuapp.com/users
-
Query specific user (by id):
curl http://localhost:5001/users/1
curl https://desolate-cliffs-02122.herokuapp.com/users/1
-
Create new user:
curl -d '{"username":"jane","email":"jane@test.cc"}' -H "Content-Type: application/json" -X POST http://localhost:5001/users
curl -d '{"username":"jane","email":"jane@test.cc"}' -H "Content-Type: application/json" -X POST https://desolate-cliffs-02122.herokuapp.com/users
-
Update a user:
curl -d '{"username":"jane","email":"jane@test.cc"}' -H "Content-Type: application/json" -X PUT http://localhost:5001/users/1
curl -d '{"username":"jane","email":"jane@test.cc"}' -H "Content-Type: application/json" -X PUT https://desolate-cliffs-02122.herokuapp.com/users/1
-
Delete a user:
curl -X DELETE http://localhost:5001/users/1
curl -X DELETE https://desolate-cliffs-02122.herokuapp.com/users/1
Roadmap
See the open issues for a list of proposed features (and known issues).
Contributing
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Please note that this is a learning repository, not a real project.
As the code is not mine, I can't give it an open-source license.
License
Code is © Michael Herman 2019, with minor modifications by Sophia Brandt.
Contact
Sophia Brandt - @hisophiabrandt
Project Link: https://github.com/sophiabrandt/flask-tdd-docker