mirror of
https://github.com/Hopiu/django-model-utils.git
synced 2026-03-16 20:00:23 +00:00
Merge pull request #563 from foarsitter/docker_postgresql
Postgresql docker container for local development
This commit is contained in:
commit
8bef73cd99
5 changed files with 37 additions and 16 deletions
19
.github/workflows/test.yml
vendored
19
.github/workflows/test.yml
vendored
|
|
@ -3,6 +3,9 @@ name: Test
|
|||
on: [push, pull_request]
|
||||
|
||||
env:
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_PASSWORD: postgres
|
||||
POSTGRES_DB: postgres
|
||||
FORCE_COLOR: 1
|
||||
|
||||
jobs:
|
||||
|
|
@ -16,11 +19,11 @@ jobs:
|
|||
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:12
|
||||
image: postgres:13-alpine
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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%.
|
||||
|
||||
|
|
|
|||
9
docker-compose.yml
Normal file
9
docker-compose.yml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
services:
|
||||
postgres:
|
||||
image: postgres:13-alpine
|
||||
environment:
|
||||
POSTGRES_HOST_AUTH_METHOD: trust
|
||||
POSTGRES_DB: modelutils
|
||||
POSTGRES_USER: postgres
|
||||
ports:
|
||||
- 5432:5432
|
||||
|
|
@ -15,14 +15,13 @@ else:
|
|||
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 = {
|
||||
|
|
|
|||
2
tox.ini
2
tox.ini
|
|
@ -36,7 +36,7 @@ passenv =
|
|||
CI
|
||||
FORCE_COLOR
|
||||
GITHUB_*
|
||||
DB_*
|
||||
POSTGRES_*
|
||||
usedevelop = True
|
||||
commands =
|
||||
python -m pytest {posargs}
|
||||
|
|
|
|||
Loading…
Reference in a new issue