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

Add test for the status page #1054

Merged
merged 1 commit into from
Jul 4, 2023
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
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
!requirements.txt
!poetry.lock
!pyproject.toml
!package.json
!package-lock.json
!tests/screenshot.js
7 changes: 6 additions & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ jobs:
- run: make build
- run: make build-tests
- run: make prospector
- name: pytest
- run: npm install
- run: mkdir -p results/status
- name: Pytest
run: >
docker run --rm --env=PYTHONPATH=/opt/
--volume=$(pwd)/results:/results --volume=$(pwd)/tests:/tests
Expand All @@ -68,6 +70,9 @@ jobs:
--profile --profile-svg --junitxml=/results/test-reports/junit.xml .'
- run: sudo chmod -R go+r results || true
if: failure()
- name: Get the status images
run: cp tests/status/*.png results/status/
if: failure()
- uses: actions/upload-artifact@v3
with:
name: results
Expand Down
10 changes: 8 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
__pycache__
/scan_to_paperless.egg-info/
/tests/prof/
/tests/img-0.png
/tests/img-1.png
/.github/changelog-generator-cache
/docker-compose.override.yaml
/node_modules/
/tests/*.png
!/tests/*.expected.png
!/tests/*.mask.png
/tests/status/*.png
!/tests/status/*.expected.png
!/tests/status/*.mask.png
/tests/status/scan/status.html
39 changes: 31 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
FROM ubuntu:22.04 as base-all
SHELL ["/bin/bash", "-o", "pipefail", "-cux"]

RUN --mount=type=cache,target=/var/lib/apt/lists \
apt-get update \
&& apt-get upgrade --yes

RUN --mount=type=cache,target=/var/lib/apt/lists \
--mount=type=cache,target=/var/cache,sharing=locked \
apt-get install --assume-yes --no-install-recommends python3-pip gnupg fonts-dejavu-core
apt-get update \
&& apt-get upgrade --yes \
&& apt-get install --assume-yes --no-install-recommends python3-pip gnupg fonts-dejavu-core

FROM base-all as poetry

Expand All @@ -24,7 +22,8 @@ RUN poetry export --output=requirements.txt \

RUN --mount=type=cache,target=/var/lib/apt/lists \
--mount=type=cache,target=/var/cache,sharing=locked \
apt-get install --assume-yes --no-install-recommends curl
apt-get update \
&& apt-get install --assume-yes --no-install-recommends curl

FROM base-all as base-dist

Expand Down Expand Up @@ -55,7 +54,8 @@ FROM base-dist as tests-dist

RUN --mount=type=cache,target=/var/lib/apt/lists \
--mount=type=cache,target=/var/cache,sharing=locked \
apt-get install --assume-yes --no-install-recommends poppler-utils ghostscript graphviz
apt-get update \
&& apt-get install --assume-yes --no-install-recommends poppler-utils ghostscript graphviz

RUN --mount=type=cache,target=/root/.cache \
--mount=type=bind,from=poetry,source=/tmp,target=/tmp \
Expand All @@ -73,12 +73,35 @@ CMD ["scan-process"]

FROM tests-dist as tests

SHELL ["/bin/bash", "-o", "pipefail", "-cux"]

COPY . ./
RUN --mount=type=cache,target=/root/.cache \
python3 -m pip install --disable-pip-version-check --no-deps --editable .

RUN --mount=type=cache,target=/var/lib/apt/lists \
--mount=type=cache,target=/var/cache,sharing=locked \
. /etc/os-release \
&& apt-get update \
&& apt-get install --assume-yes --no-install-recommends apt-transport-https gnupg curl \
&& echo "deb https://deb.nodesource.com/node_18.x ${VERSION_CODENAME} main" > /etc/apt/sources.list.d/nodesource.list \
&& curl --silent https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - \
&& apt-get update \
&& apt-get install --assume-yes --no-install-recommends nodejs \
&& echo "For Chrome installed by Pupetter" \
&& DEBIAN_FRONTEND=noninteractive apt-get install --assume-yes --no-install-recommends \
libx11-6 libx11-xcb1 libxcomposite1 libxcursor1 \
libxdamage1 libxext6 libxi6 libxtst6 libnss3 libcups2 libxss1 libxrandr2 libasound2 libatk1.0-0 \
libatk-bridge2.0-0 libpangocairo-1.0-0 libgtk-3.0 libxcb-dri3-0 libgbm1 libxshmfence1

COPY package.json package-lock.json ./
RUN --mount=type=cache,target=/root/.npm \
npm install
COPY tests/screenshot.js ./

FROM base as all

RUN --mount=type=cache,target=/var/lib/apt/lists \
--mount=type=cache,target=/var/cache,sharing=locked \
apt-get install --assume-yes --no-install-recommends tesseract-ocr-all
apt-get update \
&& apt-get install --assume-yes --no-install-recommends tesseract-ocr-all
17 changes: 11 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,25 @@ prospector: build-tests
prospector-fast:
docker run --rm --volume=$$(pwd):/opt/ sbrunner/scan-to-paperless-tests prospector --die-on-tool-error --output=pylint

DOCKER_RUN_TESTS = docker run --rm --env=PYTHONPATH=/opt/ --volume=$$(pwd)/results:/results --volume=$$(pwd)/tests:/tests --volume=$$(pwd)/scan_to_paperless:/opt/scan_to_paperless sbrunner/scan-to-paperless-tests

DOCKER_RUN_TESTS = docker run --rm --env=PYTHONPATH=/opt/ --volume=$$(pwd)/results:/results --volume=$$(pwd)/tests:/tests --volume=$$(pwd)/scan_to_paperless:/opt/scan_to_paperless
DOCKER_RUN_TESTS_IMAGE = $(DOCKER_RUN_TESTS) sbrunner/scan-to-paperless-tests
.PHONY: pytest
pytest: build-tests
$(DOCKER_RUN_TESTS) bash -c 'cd /tests && pytest --durations=0 --verbose --color=yes'
$(DOCKER_RUN_TESTS_IMAGE) bash -c 'cd /tests && pytest --durations=0 --verbose --color=yes'

.PHONY: pytest-last-failed
pytest-last-failed:
$(DOCKER_RUN_TESTS) bash -c 'cd /tests && pytest --durations=0 --verbose --color=yes --last-failed'
$(DOCKER_RUN_TESTS_IMAGE) bash -c 'cd /tests && pytest --durations=0 --verbose --color=yes --last-failed'

.PHONY: pytest-exitfirst
pytest-exitfirst:
$(DOCKER_RUN_TESTS) bash -c 'cd /tests && pytest --durations=0 --verbose --color=yes --exitfirst'
$(DOCKER_RUN_TESTS_IMAGE) bash -c 'cd /tests && pytest --durations=0 --verbose --color=yes --exitfirst'

.PHONY: pytest-failedfirst-exitfirst
pytest-failedfirst-exitfirst:
$(DOCKER_RUN_TESTS) bash -c 'cd /tests && pytest --durations=0 --verbose --color=yes --failed-first --exitfirst'
$(DOCKER_RUN_TESTS_IMAGE) bash -c 'cd /tests && pytest --durations=0 --verbose --color=yes --failed-first --exitfirst'

.PHONY: pytest-c2cwsgiutils-debug
pytest-c2cwsgiutils-debug:
$(DOCKER_RUN_TESTS) --volume=$$(pwd)/../c2cwsgiutils/c2cwsgiutils:/usr/local/lib/python3.10/dist-packages/c2cwsgiutils \
sbrunner/scan-to-paperless-tests bash -c 'cd /tests && pytest --durations=0 --verbose --color=yes'
Loading