Skip to content

Commit

Permalink
update django test
Browse files Browse the repository at this point in the history
  • Loading branch information
javierdelapuente committed Oct 21, 2024
1 parent 72e48d2 commit a0ded81
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
https://docs.djangoproject.com/en/5.1/ref/settings/
"""

import json
import os
import secrets
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
Expand All @@ -20,12 +23,12 @@
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-#!kmjy@xy-q85-qbsheq1f)2je_)48uc+yodn=e0n*ku_22%4)'
SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', secrets.token_hex(32))

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
DEBUG = os.environ.get('DJANGO_DEBUG', 'false') == 'true'

ALLOWED_HOSTS = []
ALLOWED_HOSTS = json.loads(os.environ.get('DJANGO_ALLOWED_HOSTS', '[]'))


# Application definition
Expand Down Expand Up @@ -75,12 +78,15 @@

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
'ENGINE': 'django.db.backends.postgresql',
'NAME': os.environ.get('POSTGRESQL_DB_NAME'),
'USER': os.environ.get('POSTGRESQL_DB_USERNAME'),
'PASSWORD': os.environ.get('POSTGRESQL_DB_PASSWORD'),
'HOST': os.environ.get('POSTGRESQL_DB_HOSTNAME'),
'PORT': os.environ.get('POSTGRESQL_DB_PORT'),
}
}


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

Expand Down
1 change: 1 addition & 0 deletions tests/spread/general/django/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
django
psycopg2-binary
9 changes: 7 additions & 2 deletions tests/spread/general/django/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@ execute: |
CHARMCRAFT_ENABLE_EXPERIMENTAL_EXTENSIONS=true charmcraft fetch-libs
CHARMCRAFT_ENABLE_EXPERIMENTAL_EXTENSIONS=true charmcraft pack
juju deploy postgresql-k8s --trust --channel=latest/edge
juju deploy postgresql-k8s --channel 14/stable --trust
juju deploy ./django-hello-world_ubuntu-22.04-amd64.charm django-hello-world \
--resource django-app-image=localhost:32000/django-hello-world:0.1
# once the django-allowed-hosts base url is ready, we could use directly something like
# curl --fail django-hello-world.testing:8000 --resolve django-hello-world.testing:8000:${UNIT_IP}
juju config django-hello-world django-allowed-hosts='*' django-debug=true
juju integrate postgresql-k8s django-hello-world
juju wait-for application django-hello-world
UNIT_IP=$(juju status --format json | jq -r '.applications.django-hello-world".address') && echo $UNIT_IP
UNIT_IP=$(juju status --format json | jq -r '.applications."django-hello-world".address') && echo $UNIT_IP
retry -n 20 --wait 2 curl --fail "${UNIT_IP}:8000"
[[ \"$(curl --fail "${UNIT_IP}:8000")\" =~ "The install worked successfully!" ]]

0 comments on commit a0ded81

Please sign in to comment.