From 9a27eb025d1147b4944c469bfac0c5f3b010074b Mon Sep 17 00:00:00 2001 From: Daniel Gray Date: Thu, 13 Jun 2024 12:20:10 +0200 Subject: [PATCH 1/3] updated settings file to use postgress --- app/app/settings.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/app/settings.py b/app/app/settings.py index 26b59e85..88064c6b 100644 --- a/app/app/settings.py +++ b/app/app/settings.py @@ -108,6 +108,7 @@ "NAME": os.environ.get("DB_NAME"), "USER": os.environ.get("DB_USER"), "PASSWORD": os.environ.get("DB_PASSWORD"), + "TEST": {"NAME": "test_db"}, } } @@ -122,9 +123,6 @@ "host.docker.internal", ] -# Check if the application is under testing -if "test" in sys.argv or "test_coverage" in sys.argv: # Covers regular testing and django-coverage - DATABASES["default"]["ENGINE"] = "django.db.backends.sqlite3" # Password validation # https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators From 90726bf3cc68dc610adf068cd97fe78e0cfe1083 Mon Sep 17 00:00:00 2001 From: Daniel Gray Date: Thu, 13 Jun 2024 12:23:59 +0200 Subject: [PATCH 2/3] added postgres to pipeline tests --- .env.testing | 2 +- .github/workflows/testing.yml | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.env.testing b/.env.testing index d8d2568a..deeebc6c 100644 --- a/.env.testing +++ b/.env.testing @@ -1,6 +1,6 @@ SECRET_KEY='django-insecure-w!h85bp^$$e8gm%c23r!0%9i7yzd=6w$$s&ic+6!%306&kj8@k*5' DEBUG=True -DB_HOST=db +DB_HOST=localhost DB_PORT=5432 DB_NAME=term_db DB_USER=sadilar diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index defaa2d2..f0b7be32 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -3,6 +3,16 @@ on: [ pull_request, push ] # activates the workflow when there is a push or pull jobs: test_project: runs-on: ubuntu-latest # operating system your code will run on + services: + postgres: + image: postgres:13 + env: + POSTGRES_USER: sadilar + POSTGRES_PASSWORD: sadilar + POSTGRES_DB: test_db_1 + ports: + - 5432:5432 + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 @@ -20,6 +30,7 @@ jobs: sudo chown runner:runner /logging - name: Run validate_templates run: | + export DJANGO_TEST_PROCESSES=1 cp .env.testing app/.env cd app/ mkdir -p static_files @@ -30,6 +41,9 @@ jobs: cd app/ mkdir -p static_files python manage.py test + env: + DJANGO_SETTINGS_MODULE: app.settings + DATABASE_URL: postgres://sadilar:sadilar@localhost:5432/test_db - name: Manager Check run: | cd app/ From f73f9836b3bc56fe1068fb4b889c82766c5330f3 Mon Sep 17 00:00:00 2001 From: Daniel Gray Date: Thu, 13 Jun 2024 12:28:58 +0200 Subject: [PATCH 3/3] updated tests --- app/general/tests/test_dev_mass_upload.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/general/tests/test_dev_mass_upload.py b/app/general/tests/test_dev_mass_upload.py index 3a0a8055..85c7bbe0 100644 --- a/app/general/tests/test_dev_mass_upload.py +++ b/app/general/tests/test_dev_mass_upload.py @@ -1,4 +1,5 @@ import os +import random import unittest from unittest.mock import MagicMock @@ -44,12 +45,15 @@ def test_check_file_type_pdf(self): def test_save_data(self): self.command = Command() # Create some Institutions instances for testing - for _ in range(20): + for i in range(1, 30): + random_number = random.randint(1, 1000) + Institution.objects.create( - name=self.fake.company(), - abbreviation=self.fake.company_suffix(), - url=self.fake.url(), - email=self.fake.company_email(), + id=i, + name=str(random_number) + "_" + self.fake.company(), + abbreviation=str(random_number) + "_" + self.fake.company_suffix(), + url=str(random_number) + "_" + self.fake.url(), + email=str(random_number) + "_" + self.fake.company_email(), logo="", )