Skip to content
Draft
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
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.git
.github
.mypy_cache
db.sqlite3
tests_e2e/database
tests_e2e/frontend/node_modules
tmp
venv
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,8 @@ dmypy.json
.pyre/

# PyCharm
.idea/
.idea/

# Tests E2E mounts
tests_e2e/database/db/
tests_e2e/frontend/node_modules/
41 changes: 28 additions & 13 deletions django_async_include_example/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@

BASE_DIR = Path(__file__).resolve().parent.parent


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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-grn)lg!oyaf@bl^21$zkogzk^s1)qqc(v#^$qicb(e@&3z*-3('

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

ALLOWED_HOSTS: List[str] = []

Expand Down Expand Up @@ -68,14 +67,27 @@

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

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
database = os.environ.get('DATABASE', 'sqlite')
if database == 'sqlite':
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
}

elif database == 'postgresql':
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': os.environ.get('POSTGRES_NAME'),
'USER': os.environ.get('POSTGRES_USER'),
'PASSWORD': os.environ.get('POSTGRES_PASSWORD'),
'HOST': 'database',
'PORT': 5432,
}
}
else:
raise ValueError(f"{database} database engine not recognized")

# Password validation
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
Expand Down Expand Up @@ -115,10 +127,13 @@

STATIC_URL = '/static/'

STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)

use_collect_static = os.environ.get('USE_COLLECT_STATIC', 'true')
if use_collect_static == 'true':
STATIC_ROOT = os.path.join(BASE_DIR, "static")
else:
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)

# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
Expand Down
2 changes: 1 addition & 1 deletion django_async_include_example/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,4 @@
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Django>=3.2.6
Django>=4.0.0
django-async-include==0.6.10
django-ws-include==0.3.0
django-stubs>=1.9.0
django-stubs>=1.9.0
psycopg2
18 changes: 18 additions & 0 deletions tests_e2e/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
build:
docker-compose build

down:
docker-compose down

up:
docker-compose up

backend-sh: build
docker-compose run --rm backend /bin/bash

frontend-sh: build
docker-compose run --rm frontend /bin/bash

frontend-run: build
docker-compose run --rm frontend node frontend-entrypoint.js

8 changes: 8 additions & 0 deletions tests_e2e/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# syntax=docker/dockerfile:1
FROM python:3
WORKDIR /app
COPY requirements.txt requirements.txt
RUN apt install -y libpq-dev
RUN pip install -r requirements.txt
RUN mkdir -p /app/static
COPY . .
6 changes: 6 additions & 0 deletions tests_e2e/backend/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

python manage.py collectstatic --noinput
python manage.py migrate
python manage.py loaddata /app/shop_list/fixtures/shop_list.json
python manage.py runserver 0.0.0.0:8000
49 changes: 49 additions & 0 deletions tests_e2e/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
version: '3.9'
services:
database:
image: postgres
user: postgres
volumes:
- ./database/db:/var/lib/postgresql/data
environment:
- POSTGRES_NAME=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
healthcheck:
test: [ "CMD-SHELL", "pg_isready" ]
interval: 10s
timeout: 5s
retries: 5

backend:
build:
dockerfile: ./tests_e2e/backend/Dockerfile
context: ../
command: ./tests_e2e/backend/entrypoint.sh
ports:
- "8000:8000"
environment:
- DEBUG=true
- USE_COLLECT_STATIC=true
- DATABASE=postgresql
- POSTGRES_NAME=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
depends_on:
database:
condition: service_healthy
healthcheck:
test: "curl --fail --silent --write-out 'HTTP CODE : %{http_code}\n' --output /dev/null http://127.0.0.1:8000/"
start_period: 60s
interval: 10s
timeout: 5s
retries: 10

frontend:
build:
dockerfile: ./tests_e2e/frontend/Dockerfile
context: ../
command: node entrypoint.js
depends_on:
backend:
condition: service_healthy
7 changes: 7 additions & 0 deletions tests_e2e/frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM node:18
WORKDIR /app
COPY tests_e2e/frontend/package.json ./
COPY tests_e2e/frontend/package-lock.json ./
COPY tests_e2e/frontend/jest.config.js ./
RUN npm install
COPY tests_e2e/frontend/entrypoint.js ./
15 changes: 15 additions & 0 deletions tests_e2e/frontend/entrypoint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import expect from 'expect-puppeteer'

describe('Django Async Include', () => {
beforeAll(async () => {
await page.goto('https://backend:8000');
});

it('Page h1 title', async () => {
const browser = await puppeteer.launch()
const page = await browser.newPage()
await page.goto('https://backend:8000')

await expect(page).toSelect('h1', 'Shop lists')
});
});
7 changes: 7 additions & 0 deletions tests_e2e/frontend/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const config = {
verbose: true,
injectGlobals: true,
preset: "jest-puppeteer"
};

module.exports = config;
Loading