Skip to content

Commit

Permalink
Merge pull request #75 from SADiLaR/feature/tests-change-postges
Browse files Browse the repository at this point in the history
Feature/tests change postges
  • Loading branch information
daniel-gray-tangent authored Jun 13, 2024
2 parents 6a2a1fc + f73f983 commit 833ca2b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .env.testing
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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/
Expand Down
4 changes: 1 addition & 3 deletions app/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
}
}

Expand All @@ -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
Expand Down
14 changes: 9 additions & 5 deletions app/general/tests/test_dev_mass_upload.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import random
import unittest
from unittest.mock import MagicMock

Expand Down Expand Up @@ -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="",
)

Expand Down

0 comments on commit 833ca2b

Please sign in to comment.