Uemerson / restful-todo-list-django

API RESTful To-Do List

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

About

RESTful API To-Do List implemented using Django.

Technologies used:

  • Python
  • Django
  • Django Rest framework
  • Redis
  • PostgreSQL
  • Django Debug Toolbar
  • OpenAPI 3 with drf-spectacular

Bash scripts

  • The script up.dev.v2.sh contains bash instructions to bring up the application using Docker v2 and stop the containers by pressing Ctrl+C.

  • The script test.v2.sh contains bash instructions to run unit tests and integration tests.

  • The script coverage.v2.sh contains bash instructions to run to run code coverage.

Instructions

This project uses Docker and Docker Compose, so it's necessary to install them.

After installation, rename the files .env.dev.example to .env.dev and .env.test.example to .env.test. Both are files containing environment variables with default values.

  • .env.dev: It's used to set the environment variables used by the application.
  • .env.test: It's used to set the environment variables used to run the coverage bash script.

Afterwards, you can bring up the containers using the bash script below:

$ bash up.dev.v2.sh

or if you don't want to use the bash script:

$ docker compose -f docker-compose.dev.yml --env-file .env.dev up -d --build --remove-orphans

After bringing up the application with the default values from .env.example, the API should be running at localhost:8000. To access the API documentation, go to the API Documentation section.

API Documentation

After bringing up the application, you can access the documentation via the following link Open API Swagger-UI

Tests

The tests were conducted using the python standard library module unittest and django test framework. Therefore, the tests require the 'up' database. The bash script test.v2.sh already brings up the application containers and runs the tests on top of it. You can run tests using the commands below:

$ bash test.v2.sh

or if you don't want to use the bash script:

$ docker compose -f docker-compose.dev.yml run api sh -c "cd api/ && python manage.py test --pattern='test*.py'"

Coverage

This project has 100% code coverage (excluding the 'manage.py' file and the folder containing the project configurations)

To execute code coverage, it's recommended to have an virtual environments and install both project dependencies from the requirements.txt file and development dependencies from the requirements-dev.txt (including coverage). You can do this using the commands below:

(.venv) $ pip install -r requirements.txt

and

(.venv) $ pip install -r requirements_dev.txt

After installing the dependencies and having the .env.test file (see instructions), you can covarage using the bash script below:

(.venv) $ bash coverage.v2.sh

or if you don't want to use the bash script:

(.venv) $ export $(cat .env.test | xargs)
(.venv) $ docker compose -f docker-compose.dev.yml up -d
(.venv) $ python -m coverage run --source='api' --omit 'api/manage.py,api/config/*' api/manage.py test api/ --pattern='test*.py'
(.venv) $ python -m coverage report
(.venv) $ python -m coverage html

Note

If you are using Docker version 1 and Docker Compose version 1, please replace docker compose with docker-compose in the bash scripts.

If you are on localhost, upon opening the API in the browser, you should see the Django Debug Toolbar on the side. It is used to display information about request times, executed SQL commands, and other useful information.

About

API RESTful To-Do List

License:MIT License


Languages

Language:Python 94.4%Language:Shell 5.6%