File tree Expand file tree Collapse file tree 8 files changed +196
-18
lines changed
lung_cancer_screening/core/tests/acceptance Expand file tree Collapse file tree 8 files changed +196
-18
lines changed Original file line number Diff line number Diff line change @@ -32,19 +32,62 @@ COPY pyproject.toml poetry.lock ./
3232RUN pip install poetry
3333RUN 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
4250USER 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
4789USER ${USER}
90+ COPY --chown=${USER}:${USER} . .
4891
4992FROM python_base
5093
Original file line number Diff line number Diff 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 :
Original file line number Diff line number Diff line change 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 } /" )
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ dev-logs:
1818 $(DOCKER_COMPOSE_CMD ) logs -f
1919
2020dev-shell :
21- $(DOCKER_COMPOSE_CMD ) run web sh
21+ $(DOCKER_COMPOSE_CMD ) run web bash
2222
2323dev-migrate :
2424 $(DOCKER_COMPOSE_CMD ) run --rm web python manage.py migrate
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ package-mode = false
1818
1919[tool .poetry .group .dev .dependencies ]
2020ruff = " ^0.12.5"
21+ playwright = " ^1.55.0"
2122
2223[build-system ]
2324requires = [" poetry-core>=2.0.0,<3.0.0" ]
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments