Skip to content

Commit 3a22aad

Browse files
committed
Use playwright for acceptance testing
Playwright does not run on alpine linux therefore python slim must be used for the development image
1 parent ddd5842 commit 3a22aad

File tree

8 files changed

+220
-42
lines changed

8 files changed

+220
-42
lines changed

Dockerfile

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,62 @@ COPY pyproject.toml poetry.lock ./
3232
RUN pip install poetry
3333
RUN poetry install --without dev --no-root && rm -rf $POETRY_CACHE_DIR
3434

35-
FROM builder AS development
35+
# Alpine doesn't support playwright
36+
FROM python:3.13.5-slim AS development
3637

37-
USER ${USER}
38-
WORKDIR /app
38+
# Set up user like python_base does
39+
ENV USER=app
40+
RUN addgroup --gid 1000 --system ${USER} \
41+
&& adduser --uid 1000 --system ${USER} --ingroup ${USER} --home /home/${USER} \
42+
&& mkdir -p /home/${USER} \
43+
&& chown ${USER}:${USER} /home/${USER}
3944

40-
COPY --chown=${USER}:${USER} . .
45+
ENV HOME=/home/${USER}
46+
47+
ENV VIRTUAL_ENV=/app/.venv
48+
ENV PATH="/app/.venv/bin:$PATH"
4149

4250
USER root
51+
WORKDIR /app
4352

44-
RUN chown ${USER}:${USER} .
45-
RUN poetry install
53+
# Install system dependencies needed for Playwright
54+
RUN apt-get update && apt-get install -y \
55+
fonts-liberation \
56+
libasound2 \
57+
libatk-bridge2.0-0 \
58+
libatk1.0-0 \
59+
libatspi2.0-0 \
60+
libcups2 \
61+
libdbus-1-3 \
62+
libdrm2 \
63+
libexpat1 \
64+
libgbm1 \
65+
libglib2.0-0 \
66+
libgtk-3-0 \
67+
libnspr4 \
68+
libnss3 \
69+
libx11-6 \
70+
libxcomposite1 \
71+
libxdamage1 \
72+
libxext6 \
73+
libxfixes3 \
74+
libxrandr2 \
75+
libxss1 \
76+
libxtst6 \
77+
xdg-utils \
78+
&& rm -rf /var/lib/apt/lists/*
79+
80+
ENV POETRY_NO_INTERACTION=1 \
81+
POETRY_VIRTUALENVS_IN_PROJECT=1 \
82+
POETRY_VIRTUALENVS_CREATE=1
83+
84+
COPY pyproject.toml poetry.lock ./
85+
RUN pip install poetry
86+
RUN poetry install --no-root
87+
RUN poetry run playwright install
4688

4789
USER ${USER}
90+
COPY --chown=${USER}:${USER} . .
4891

4992
FROM python_base
5093

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ services:
1313
- .env
1414
depends_on:
1515
- db
16+
volumes:
17+
- ./lung_cancer_screening:/app/lung_cancer_screening
1618
restart: unless-stopped
1719

1820
asset_builder:
Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
1-
from django.test import TestCase, Client
1+
import os
2+
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
3+
from playwright.sync_api import sync_playwright
24

3-
class TestHomepage(TestCase):
45

5-
def setUp(self):
6-
self.client = Client()
6+
class TestQuestionnaire(StaticLiveServerTestCase):
77

8-
def test_homepage_displays_hello_world(self):
9-
response = self.client.get('/')
10-
self.assertEqual(response.status_code, 200)
11-
self.assertContains(response, "hello world")
8+
@classmethod
9+
def setUpClass(cls):
10+
os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true"
11+
super().setUpClass()
12+
cls.playwright = sync_playwright().start()
13+
cls.browser = cls.playwright.chromium.launch()
14+
15+
@classmethod
16+
def tearDownClass(cls):
17+
super().tearDownClass()
18+
cls.browser.close()
19+
cls.playwright.stop()
20+
21+
def test_full_questionaire_user_journey(self):
22+
page = self.browser.new_page()
23+
page.goto(f"{self.live_server_url}/")

makefiles/dev.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ dev-logs:
1818
$(DOCKER_COMPOSE_CMD) logs -f
1919

2020
dev-shell:
21-
$(DOCKER_COMPOSE_CMD) run web sh
21+
$(DOCKER_COMPOSE_CMD) run web bash
2222

2323
dev-migrate:
2424
$(DOCKER_COMPOSE_CMD) run --rm web python manage.py migrate

poetry.lock

Lines changed: 145 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package-mode = false
1818

1919
[tool.poetry.group.dev.dependencies]
2020
ruff = "^0.12.10"
21+
playwright = "^1.55.0"
2122

2223
[build-system]
2324
requires = ["poetry-core>=2.0.0,<3.0.0"]

scripts/tests/lint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ cd "$(git rev-parse --show-toplevel)"
1717
# tests from here. If you want to run other test suites, see the predefined
1818
# tasks in scripts/lint.mk.
1919

20-
docker compose run --rm web poetry run ruff check lung_cancer_screening
20+
docker compose run --rm web poetry run ruff check --no-cache lung_cancer_screening

scripts/tests/unit.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ cd "$(git rev-parse --show-toplevel)"
1717
# tests from here. If you want to run other test suites, see the predefined
1818
# tasks in scripts/test.mk.
1919

20-
docker compose run web poetry run python manage.py test
20+
docker compose run --rm web poetry run python manage.py test

0 commit comments

Comments
 (0)