Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests #3

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,18 @@ jobs:
git config --global user.email "[email protected]"
git config --global user.name "My Name"
- run: ./test.sh
env:
DATABASE_URL: postgresql://postgres:postgrespass@localhost:5432/testdb

services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgrespass
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
18 changes: 18 additions & 0 deletions 30-django.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
poetry add 'django=*'
poetry add --group dev 'pytest-django==*'

# Check if the DJANGO_PROJECT_NAME environment variable is set
if [[ -z "$DJANGO_PROJECT_NAME" ]]; then
Expand All @@ -12,6 +13,23 @@ fi
# Run django-admin startproject with the project name
poetry run django-admin startproject "$DJANGO_PROJECT_NAME" .

# create pytest-django configuration
sed -i "/\[tool\.pytest\.ini_options\]/a\\
DJANGO_SETTINGS_MODULE = \"$DJANGO_PROJECT_NAME.settings\"\\
FAIL_INVALID_TEMPLATE_VARS = true" pyproject.toml

# create smoke test
cat > "test_no_smoke.py" <<EOL
import pytest
from django.urls import reverse


@pytest.mark.django_db
def test_admin_root(admin_client):
response = admin_client.get(reverse('admin:index'))
assert response.status_code == 200
EOL

poetry run isort .
git add --all
git commit -m "Initialize Django project"
12 changes: 12 additions & 0 deletions 40-heroku.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,22 @@ cat > app.json <<EOL
"quantity": 1,
"size": "basic"
}
},
"environments": {
"test": {
"addons": ["heroku-postgresql:in-dyno"],
"scripts": {
"test-setup": "python manage.py collectstatic --no-input",
"test": "flake8 . && pytest"
}
}
}
}
EOL

# add heroku stuff to flake8 exclude
sed -i '/\[tool\.flake8\]/a exclude = [\n ".heroku",\n ".local",\n]' pyproject.toml

# Commit the changes
git add --all
git commit -m "Configure the project for Heroku deployment"
9 changes: 9 additions & 0 deletions example/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,14 @@
"quantity": 1,
"size": "basic"
}
},
"environments": {
"test": {
"addons": ["heroku-postgresql:in-dyno"],
"scripts": {
"test-setup": "python manage.py collectstatic --no-input",
"test": "flake8 . && pytest"
}
}
}
}
17 changes: 9 additions & 8 deletions example/commits.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@
example/urls.py | 23 ++++++++++
example/wsgi.py | 17 +++++++
manage.py | 22 ++++++++++
poetry.lock | 62 +++++++++++++++++++++++++-
pyproject.toml | 1 +
8 files changed, 265 insertions(+), 1 deletion(-)
poetry.lock | 80 ++++++++++++++++++++++++++++++++-
pyproject.toml | 4 ++
test_no_smoke.py | 8 ++++
9 files changed, 294 insertions(+), 1 deletion(-)

--- Configure Django settings with django-environ

Expand Down Expand Up @@ -72,17 +73,17 @@
--- Install and configure Sentry

example/settings.py | 8 ++++++
poetry.lock | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
poetry.lock | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
pyproject.toml | 1 +
3 files changed, 89 insertions(+), 1 deletion(-)
3 files changed, 90 insertions(+), 1 deletion(-)

--- Configure the project for Heroku deployment

Procfile | 2 ++
app.json | 28 ++++++++++++++++++++++++++++
app.json | 37 +++++++++++++++++++++++++++++++++++++
poetry.lock | 23 ++++++++++++++++++++++-
pyproject.toml | 1 +
4 files changed, 53 insertions(+), 1 deletion(-)
pyproject.toml | 5 +++++
4 files changed, 66 insertions(+), 1 deletion(-)

--- Custom user model using UUID4 as the primary key

Expand Down
2 changes: 1 addition & 1 deletion example/example/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.0/howto/deployment/asgi/
https://docs.djangoproject.com/en/5.1/howto/deployment/asgi/
"""

import os
Expand Down
18 changes: 9 additions & 9 deletions example/example/settings.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""
Django settings for example project.

Generated by 'django-admin startproject' using Django 5.0.6.
Generated by 'django-admin startproject' using Django 5.1.

For more information on this file, see
https://docs.djangoproject.com/en/5.0/topics/settings/
https://docs.djangoproject.com/en/5.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.0/ref/settings/
https://docs.djangoproject.com/en/5.1/ref/settings/
"""

from pathlib import Path
Expand All @@ -23,7 +23,7 @@


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = env.str('SECRET_KEY')
Expand Down Expand Up @@ -79,15 +79,15 @@


# Database
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases

DATABASES = {
'default': env.db('DATABASE_URL')
}


# Password validation
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
Expand All @@ -106,7 +106,7 @@


# Internationalization
# https://docs.djangoproject.com/en/5.0/topics/i18n/
# https://docs.djangoproject.com/en/5.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

Expand All @@ -118,12 +118,12 @@


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.0/howto/static-files/
# https://docs.djangoproject.com/en/5.1/howto/static-files/

STATIC_URL = 'static/'

# Default primary key field type
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

Expand Down
2 changes: 1 addition & 1 deletion example/example/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
URL configuration for example project.

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/5.0/topics/http/urls/
https://docs.djangoproject.com/en/5.1/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
Expand Down
2 changes: 1 addition & 1 deletion example/example/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.0/howto/deployment/wsgi/
https://docs.djangoproject.com/en/5.1/howto/deployment/wsgi/
"""

import os
Expand Down
Loading
Loading