From 3ea0b3b2868ff8fa5b5b079833db093f699dbb12 Mon Sep 17 00:00:00 2001 From: Daniel Gray Date: Mon, 29 Apr 2024 08:20:41 +0200 Subject: [PATCH] adding git actions tests added ls testing dir change added linting tools added dev requirement file updated install testing tests added cp of .env file checking enviroment files testing cat fixed cat command --- .env.testing | 11 +++++++++++ .github/workflows/testing.yml | 22 ++++++++++++++++++++++ README.md | 6 ------ app/app/settings.py | 9 +++++++++ requirements-test.txt | 3 +++ requirements.txt | 1 + 6 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 .env.testing create mode 100644 .github/workflows/testing.yml create mode 100644 requirements-test.txt diff --git a/.env.testing b/.env.testing new file mode 100644 index 00000000..bfcf91b6 --- /dev/null +++ b/.env.testing @@ -0,0 +1,11 @@ +SECRET_KEY='django-insecure-w!h85bp^$$e8gm%c23r!0%9i7yzd=6w$$s&ic+6!%306&kj8@k*5' +DEBUG=True +DB_HOST=db +DB_PORT=5432 +DB_NAME=term_db +DB_USER=sadilar +DB_PASSWORD=sadilar +LOGGING_FILE=logs/debug.log +LOGGING_HANDLERS_LEVEL=INFO +LOGGING_LOGGERS_LEVEL=INFO +LOGGING_LOGGERS_DJANGO_LEVEL=INFO diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml new file mode 100644 index 00000000..83778423 --- /dev/null +++ b/.github/workflows/testing.yml @@ -0,0 +1,22 @@ +name: Testing Django +on: [ pull_request, push ] # activates the workflow when there is a push or pull request in the repo +jobs: + test_project: + runs-on: ubuntu-latest # operating system your code will run on + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + - name: Install Dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements-test.txt + - name: Run linting tools + run: | + cd app/ + ruff format . + - name: Run Tests + run: | + cp .env.testing app/.env + cd app/ + mkdir static_files + python manage.py test diff --git a/README.md b/README.md index ab4adc6f..194ea783 100644 --- a/README.md +++ b/README.md @@ -23,9 +23,3 @@ About the project: 2. Run `make build` to build the docker image 3. Run `make run` to run the docker container 4. Run `make stop` to stop the docker container - - - - - - diff --git a/app/app/settings.py b/app/app/settings.py index b5266866..bba54394 100644 --- a/app/app/settings.py +++ b/app/app/settings.py @@ -11,11 +11,17 @@ """ import os +import sys from pathlib import Path +import environ + # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent +# Take environment variables from .env file +environ.Env.read_env(os.path.join(BASE_DIR, ".env")) + # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/ @@ -96,6 +102,9 @@ } } +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 diff --git a/requirements-test.txt b/requirements-test.txt new file mode 100644 index 00000000..e00d50bd --- /dev/null +++ b/requirements-test.txt @@ -0,0 +1,3 @@ +-r requirements.txt +django-extensions +ruff diff --git a/requirements.txt b/requirements.txt index 62e806c8..cf164c91 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ django==5.0.2 psycopg2-binary gunicorn whitenoise +django-environ