Skip to content

Django using a TDD approach, using containerization for agility. API documentation with Swagger, Github Actions to implement a testing pipeline among other things, etc...

Notifications You must be signed in to change notification settings

alexnesov/Advanced_Django_training

Repository files navigation

Advanced_Django_training

Django using a TDD approach, using containerization of it for agility, API documentation with Swagger, Github Actions for automated testing, etc...

Apps

  • app/ - Django project
  • app/core/ - Code shared between multiple apps
  • app/user/ - User related code (User registration & auth tokens)
  • app/recipe/ - Recipe related code (Handling and updating ingrediants and tags and managing tags)

docker_compose_setup

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

run will start a specific container defined in config, to remove the container once is finished running. Important to avoir having lots of containers running in the background.
--rm removes the container
sh -c passes in a shell command

Init project

docker-compose run --rm app sh -c "django-admin startproject app .

Start services

docker-compose up
docker build . once one has the app folder created at root


How we'll test
docker-compose run --rm app sh -c "python manage.py test"

Django installation from within docker
docker-compose run --rm app sh -c "django-admin startproject app ."

Run project with Docker Compose
docker-compose up

Other commands:

Stop all the containers
docker stop $(docker ps -a -q)


Remove all the containers
docker rm $(docker ps -a -q)


Creating a new Django app (example):

Creating core app:
docker-compose run --rm app sh -c "python manage.py startapp core"

DB Migration:

Init:

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

Why using Mocking ?

  • Avoid relying on external services!! (we dont' have necessarily control over these)
    • Ex: sendin email func, but we don't want to actually send an email
  • Speeding up tests (for example bypass sleep funcs)

What is "psycopg2" (important)

Package that you need in order for Django to connect to our database. It's the most popular PostgreSQL adaptor for Python. Supported by Django officially.

  • psycopg2-binary: ok for dev, but not for prod
  • psycopg2: compiled from source, compiled for the OS your running on.Better for reliability and perf.

Dependencies:

  • C compiler
  • python3-dev
  • libq-dev

Equivalent packages for Alpine

  • postgresql-client
  • buildbase
  • postgresql-dev
  • musldev

Check directly of DB works:

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

First migration

Not working: docker-compose run --rm app sh -c "python manage.py makemigrations"

Working: docker-compose run app sh -c "python manage.py makemigrations core"


docker-compose run --rm app sh -c "python manage.py wait_for_db && python manage.py migrate"

Create superuser

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

About

Django using a TDD approach, using containerization for agility. API documentation with Swagger, Github Actions to implement a testing pipeline among other things, etc...

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published