Skip to content

Guide to REST API development with Django (The TDD Way 😎)

License

Notifications You must be signed in to change notification settings

DevDHera/TDD-With-Django-REST

Repository files navigation

Build Status Issue Status License Status Fork Status

TDD-With-Django-REST 😎

This project is a guide to REST API development with the help of Django Rest Framework.

A Test Driven Development approach is used to build out this project and API contains features such as,

  • Fully fledged Authentication mechanisam
  • Image Upload
  • CRUD and relations

and much more.

Summary

Getting Started

Getting started with the TDD-With-Django-REST is easy.

  1. First clone the project.
git clone https://github.com/DevDHera/TDD-With-Django-REST.git
  1. Start your docker machine.

  2. Go to the root of your cloned project and build the docker image.

docker-compose build
  1. Do the neccessary migrations.
docker-compose run --rm app sh -c "python manage.py makemigrations"
  1. Run the app using docker-compose.
docker-compose up
  1. Now head over to our issue board and help solving issues πŸ‘Ό.

Prerequisites

TDD-With-Django-REST uses Docker to manage containers.

In order to successfully run the project install the following.

  • Docker

Configurations

After installing the above you can provision services as you like using the docker-compose.yml file on the root of the project.

Following is the structure that we are using.

version: '3'

services:
  app:
    restart: always
    build:
      context: .
    ports:
      - '8000:8000'
    volumes:
      - ./app:/app
    command: >
      sh -c "python manage.py wait_for_db &&
         python manage.py migrate &&
         python manage.py runserver 0.0.0.0:8000"
    environment:
      - DB_HOST=db
      - DB_NAME=app
      - DB_USER=postgres
      - DB_PASS=supersecretpassword
    depends_on:
      - db

  db:
    image: postgres:12-alpine
    environment:
      - POSTGRES_DB=app
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=supersecretpassword

Running the tests

As the project uses a TDD approach test take a key role. Following describes how you can run the tests and lints.

Break down into tests

Each app contains test folder that will is used to test each part of the API. You can run these tests by using the below script.

docker-compose run --rm app sh -c "python manage.py test"

And coding style tests

Flake8 is used to enforce the coding styles. Lint command as belows.

docker-compose run --rm app sh -c "flake8"

You can run both the tests and lints in one go like below.

docker-compose run --rm app sh -c "python manage.py test && flake8"

Test Look Through

Failing Test

Failing Test GIF

Passing Test

Passing Test GIF

Deployment

To deploy the API first you can use the power of docker-compose.

Simply run the belwo.

docker-compose up

Built With

Contributing

Please read CODE_OF_CONDUCT.md for details on our code of conduct, and the process for submitting pull requests to us.

Authors

  • Devin Herath - Initial work - DevDHera

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • PurpleBooth for this awesome README template ❀️

About

Guide to REST API development with Django (The TDD Way 😎)

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published