diff --git a/.github/workflows/quality-check.yml b/.github/workflows/quality-check.yml new file mode 100644 index 00000000..fa99fb57 --- /dev/null +++ b/.github/workflows/quality-check.yml @@ -0,0 +1,42 @@ +name: Open Prices unit and integration tests + +on: + push: + paths: + - "**/app/**" + - "pyproject.toml" + - "poetry.lock" + - "tests/**" + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + unit-test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: + - "3.11" + + steps: + #---------------------------------------------- + # check-out repo + #---------------------------------------------- + - name: Check out repository + uses: actions/checkout@v3 + + #---------------------------------------------- + # Launch checks and tests + #---------------------------------------------- + - name: Configure docker + run: | + # ensure a new line for .env file might not have it! + echo "" >> .env + # align user id + echo "USER_UID=$UID" >> .env + echo "PYTHON_VERSION=${{ matrix.python-version }}" >> .env + + - name: Launch tests + run: make tests diff --git a/Dockerfile b/Dockerfile index 32fc4812..4642bd9a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -38,10 +38,10 @@ RUN poetry config virtualenvs.create false ENV POETRY_VIRTUALENVS_IN_PROJECT=false # create off user -ARG OFF_UID=1000 -ARG OFF_GID=$OFF_UID -RUN groupadd -g $OFF_GID off && \ - useradd -u $OFF_UID -g off -m off && \ +ARG USER_UID=1000 +ARG USER_GID=$USER_UID +RUN groupadd -g $USER_GID off && \ + useradd -u $USER_UID -g off -m off && \ mkdir -p /home/off && \ mkdir -p /opt/open-prices && \ chown off:off -R /opt/open-prices /home/off diff --git a/Makefile b/Makefile index 4758a45f..1bc451db 100644 --- a/Makefile +++ b/Makefile @@ -125,6 +125,8 @@ docs: checks: toml-check flake8 black-check mypy isort-check docs +tests: unit-tests integration-tests + unit-tests: @echo "🥫 Running tests …" # change project name to run in isolation diff --git a/app/crud.py b/app/crud.py index 8ef0fb94..f46cbbbc 100644 --- a/app/crud.py +++ b/app/crud.py @@ -418,7 +418,7 @@ def create_proof_file(file: UploadFile) -> tuple[str, str]: # if the current directory contains 1000 images, we create a new one current_dir_id += 1 current_dir = images_dir / str(current_dir_id) - current_dir.mkdir(exist_ok=True) + current_dir.mkdir(exist_ok=True, parents=True) full_file_path = current_dir / f"{file_stem}{extension}" # write the content of the file to the new file with full_file_path.open("wb") as f: diff --git a/tests/integration/test_api.py b/tests/integration/test_api.py index 0a204f73..c2a7b2f3 100644 --- a/tests/integration/test_api.py +++ b/tests/integration/test_api.py @@ -25,6 +25,7 @@ def override_get_db(): db = session() yield db finally: + # close the DB session db.close()