From 8677eef1ca01642c5d06a921110d0766941b9217 Mon Sep 17 00:00:00 2001 From: Jelmer Draaijer Date: Thu, 6 Apr 2023 13:02:54 +0200 Subject: [PATCH 1/3] Rename database environment variables to align with the docker postgres image --- .github/workflows/test.yml | 17 +++++++++-------- tests/settings.py | 11 +++++------ tox.ini | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 20b5bc2a..097e0846 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,6 +3,9 @@ name: Test on: [push, pull_request] env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: postgres FORCE_COLOR: 1 jobs: @@ -18,9 +21,9 @@ jobs: postgres: image: postgres:12 env: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_DB: postgres + POSTGRES_USER: ${{ env.POSTGRES_USER }} + POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }} + POSTGRES_DB: ${{ env.POSTGRES_DB }} ports: - 5432:5432 options: >- @@ -60,11 +63,9 @@ jobs: run: | tox -v -- --cov --cov-append --cov-report term-missing --cov-report xml env: - DB_NAME: postgres - DB_USER: postgres - DB_PASSWORD: postgres - DB_HOST: localhost - DB_PORT: 5432 + POSTGRES_DB: ${{ env.POSTGRES_DB }} + POSTGRES_USER: ${{ env.POSTGRES_USER }} + POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }} - name: Upload coverage uses: codecov/codecov-action@v3 diff --git a/tests/settings.py b/tests/settings.py index c8ec92a9..74cf26ad 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -15,14 +15,13 @@ DATABASES = { "default": { "ENGINE": "django.db.backends.postgresql", - "NAME": os.environ.get("DB_NAME", "modelutils"), - "USER": os.environ.get("DB_USER", 'postgres'), - "PASSWORD": os.environ.get("DB_PASSWORD", ""), - "HOST": os.environ.get("DB_HOST", "localhost"), - "PORT": os.environ.get("DB_PORT", 5432) + "NAME": os.environ.get("POSTGRES_DB", "modelutils"), + "USER": os.environ.get("POSTGRES_USER", 'postgres'), + "PASSWORD": os.environ.get("POSTGRES_PASSWORD", ""), + "HOST": os.environ.get("POSTGRES_HOST", "localhost"), + "PORT": os.environ.get("POSTGRES_PORT", 5432) }, } - SECRET_KEY = 'dummy' CACHES = { diff --git a/tox.ini b/tox.ini index 39c219e1..2bfdc30d 100644 --- a/tox.ini +++ b/tox.ini @@ -36,7 +36,7 @@ passenv = CI FORCE_COLOR GITHUB_* - DB_* + POSTGRES_* usedevelop = True commands = python -m pytest {posargs} From 1e62e848b6cf5b2acabf94f6bd9721f98dc8d386 Mon Sep 17 00:00:00 2001 From: Jelmer Draaijer Date: Thu, 6 Apr 2023 13:42:35 +0200 Subject: [PATCH 2/3] Add docker-compose for local development --- CONTRIBUTING.rst | 12 ++++++++++++ docker-compose.yml | 9 +++++++++ 2 files changed, 21 insertions(+) create mode 100644 docker-compose.yml diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 433912fd..5b9a4c37 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -74,6 +74,18 @@ To run tox and generate a coverage report (in ``htmlcov`` directory):: make test +A database is required to run the tests. For convince there is a ``docker-compose.yml`` file for spinning up a +database container. To start the database container run: + + docker-compose up -d + +Another way to run the tests with a sqlite database is to export the `SQLITE` variable:: + + export SQLITE=1 + make test + # or + SQLITE=1 python setup.py test + **Please note**: Before a pull request can be merged, all tests must pass and code/branch coverage in tests must be 100%. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..55e54d8a --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,9 @@ +services: + postgres: + image: postgres:13 + environment: + POSTGRES_HOST_AUTH_METHOD: trust + POSTGRES_DB: modelutils + POSTGRES_USER: postgres + ports: + - 5432:5432 From caac9a47a0cc2b9b814e17be502ecf14fe5c28af Mon Sep 17 00:00:00 2001 From: Jelmer Draaijer Date: Fri, 22 Mar 2024 08:09:13 +0100 Subject: [PATCH 3/3] Make use of alpine postgresql image --- .github/workflows/test.yml | 2 +- docker-compose.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 097e0846..839fa31b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,7 +19,7 @@ jobs: services: postgres: - image: postgres:12 + image: postgres:13-alpine env: POSTGRES_USER: ${{ env.POSTGRES_USER }} POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }} diff --git a/docker-compose.yml b/docker-compose.yml index 55e54d8a..6e74ec82 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,6 @@ services: postgres: - image: postgres:13 + image: postgres:13-alpine environment: POSTGRES_HOST_AUTH_METHOD: trust POSTGRES_DB: modelutils