From 1fa5dddce58a76de88288d4a795ec43799eec8ee Mon Sep 17 00:00:00 2001 From: Oliver Falk Date: Tue, 25 Jun 2024 08:32:34 +0000 Subject: [PATCH] Use real database (side container) --- .gitlab-ci.yml | 12 +++++++++++- config.py | 13 +++++++++++++ ivatar/ivataraccount/test_views.py | 6 ++++-- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9c1696a..7aa611a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -14,6 +14,15 @@ variables: test_and_coverage: stage: build coverage: "/^TOTAL.*\\s+(\\d+\\%)$/" + services: + - postgres:latest + variables: + POSTGRES_DB: django_db + POSTGRES_USER: django_user + POSTGRES_PASSWORD: django_password + POSTGRES_HOST: postgres + DATABASE_URL: "postgres://django_user:django_password@postgres/django_db" + PYTHONUNBUFFERED: 1 before_script: - virtualenv -p python3 /tmp/.virtualenv - source /tmp/.virtualenv/bin/activate @@ -31,8 +40,9 @@ test_and_coverage: - echo "DEBUG = True" >> config_local.py - echo "from config import CACHES" >> config_local.py - echo "CACHES['default'] = CACHES['filesystem']" >> config_local.py + - python manage.py sqldsn - python manage.py collectstatic --noinput - - coverage run --source . manage.py test -v3 + - coverage run --source . manage.py test -v3 --noinput - coverage report --fail-under=70 - coverage html artifacts: diff --git a/config.py b/config.py index 0884d41..cb4e18c 100644 --- a/config.py +++ b/config.py @@ -153,6 +153,19 @@ if "POSTGRESQL_DATABASE" in os.environ: "HOST": "postgresql", } +# CI/CD config has different naming +if "POSTGRES_DB" in os.environ: + DATABASES["default"] = { # pragma: no cover + "ENGINE": "django.db.backends.postgresql", + "NAME": os.environ["POSTGRES_DB"], + "USER": os.environ["POSTGRES_USER"], + "PASSWORD": os.environ["POSTGRES_PASSWORD"], + "HOST": os.environ["POSTGRES_HOST"], + "TEST": { + "NAME": os.environ["POSTGRES_DB"], + }, + } + SESSION_SERIALIZER = "django.contrib.sessions.serializers.JSONSerializer" USE_X_FORWARDED_HOST = True diff --git a/ivatar/ivataraccount/test_views.py b/ivatar/ivataraccount/test_views.py index 3dfceca..dda73e6 100644 --- a/ivatar/ivataraccount/test_views.py +++ b/ivatar/ivataraccount/test_views.py @@ -394,9 +394,11 @@ class Tester(TestCase): # pylint: disable=too-many-public-methods # Probably not the best way to access the content type self.assertEqual(response["Content-Type"], "image/jpg", "Content type wrong!?") + print("XXX: %s", type(response.content)) + print("XXX: %s", type(self.user.photo_set.first().data)) self.assertEqual( - response.content, - self.user.photo_set.first().data, + bytes(response.content), + bytes(self.user.photo_set.first().data), "raw_image should return the same content as if we\ read it directly from the DB", )