From db58195c9493442ea498406735f1b4a8f057a8d4 Mon Sep 17 00:00:00 2001 From: Roman Dyakov Date: Sat, 6 Apr 2024 15:26:24 +0300 Subject: [PATCH 1/5] Fix fastapi update --- marketing_api/routes/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/marketing_api/routes/base.py b/marketing_api/routes/base.py index 5ad80e8..9931be4 100644 --- a/marketing_api/routes/base.py +++ b/marketing_api/routes/base.py @@ -24,7 +24,7 @@ description='API для проведения маркетинговых исследований', version=__version__, # Настраиваем интернет документацию - root_path=settings.ROOT_PATH if __version__ != 'dev' else '/', + root_path=settings.ROOT_PATH if __version__ != 'dev' else '', docs_url=None if __version__ != 'dev' else '/docs', redoc_url=None, ) From 320f7dbdffef4f0e0e4b277f4a070430b30f0b15 Mon Sep 17 00:00:00 2001 From: Roman Dyakov Date: Sat, 6 Apr 2024 15:31:42 +0300 Subject: [PATCH 2/5] Makefile format --- Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Makefile b/Makefile index 4cde912..07ed61c 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,12 @@ format: source ./venv/bin/activate && autoflake -r --in-place --remove-all-unused-imports ./marketing_api source ./venv/bin/activate && isort ./marketing_api source ./venv/bin/activate && black ./marketing_api + source ./venv/bin/activate && autoflake -r --in-place --remove-all-unused-imports ./tests + source ./venv/bin/activate && isort ./tests + source ./venv/bin/activate && black ./tests + source ./venv/bin/activate && autoflake -r --in-place --remove-all-unused-imports ./migrations + source ./venv/bin/activate && isort ./migrations + source ./venv/bin/activate && black ./migrations db: docker run -d -p 5432:5432 -e POSTGRES_HOST_AUTH_METHOD=trust --name db-marketing-backend postgres:15 From cc6c8269a6b25188db8721e27de5bde505c3abf8 Mon Sep 17 00:00:00 2001 From: Roman Dyakov Date: Sat, 6 Apr 2024 15:41:47 +0300 Subject: [PATCH 3/5] Style --- migrations/versions/0ea7185ac58b_useragent.py | 1 + .../versions/cdb1cd1ef17f_no_foreign_key_constraint_for_user.py | 2 +- migrations/versions/d1136ec942ac_no_nesessary_fields.py | 1 + migrations/versions/e2c2d4fe34f1_auth_user_id.py | 1 + migrations/versions/f2d45b6daecf_init.py | 1 + tests/routes.py | 1 - 6 files changed, 5 insertions(+), 2 deletions(-) diff --git a/migrations/versions/0ea7185ac58b_useragent.py b/migrations/versions/0ea7185ac58b_useragent.py index aec50fe..312d66a 100644 --- a/migrations/versions/0ea7185ac58b_useragent.py +++ b/migrations/versions/0ea7185ac58b_useragent.py @@ -5,6 +5,7 @@ Create Date: 2023-05-05 12:25:03.383848 """ + import sqlalchemy as sa from alembic import op diff --git a/migrations/versions/cdb1cd1ef17f_no_foreign_key_constraint_for_user.py b/migrations/versions/cdb1cd1ef17f_no_foreign_key_constraint_for_user.py index 39272bf..4e844cf 100644 --- a/migrations/versions/cdb1cd1ef17f_no_foreign_key_constraint_for_user.py +++ b/migrations/versions/cdb1cd1ef17f_no_foreign_key_constraint_for_user.py @@ -5,7 +5,7 @@ Create Date: 2023-03-16 21:02:42.333305 """ -import sqlalchemy as sa + from alembic import op diff --git a/migrations/versions/d1136ec942ac_no_nesessary_fields.py b/migrations/versions/d1136ec942ac_no_nesessary_fields.py index 1f91497..3805221 100644 --- a/migrations/versions/d1136ec942ac_no_nesessary_fields.py +++ b/migrations/versions/d1136ec942ac_no_nesessary_fields.py @@ -5,6 +5,7 @@ Create Date: 2023-03-16 21:31:00.557581 """ + import sqlalchemy as sa from alembic import op diff --git a/migrations/versions/e2c2d4fe34f1_auth_user_id.py b/migrations/versions/e2c2d4fe34f1_auth_user_id.py index 6523017..bebdd32 100644 --- a/migrations/versions/e2c2d4fe34f1_auth_user_id.py +++ b/migrations/versions/e2c2d4fe34f1_auth_user_id.py @@ -5,6 +5,7 @@ Create Date: 2023-03-16 21:13:20.798843 """ + import sqlalchemy as sa from alembic import op diff --git a/migrations/versions/f2d45b6daecf_init.py b/migrations/versions/f2d45b6daecf_init.py index dd4b2ee..64b9dc8 100644 --- a/migrations/versions/f2d45b6daecf_init.py +++ b/migrations/versions/f2d45b6daecf_init.py @@ -5,6 +5,7 @@ Create Date: 2022-08-27 00:59:23.669445 """ + import sqlalchemy as sa from alembic import op diff --git a/tests/routes.py b/tests/routes.py index cedc64e..f2888b5 100644 --- a/tests/routes.py +++ b/tests/routes.py @@ -2,7 +2,6 @@ from fastapi.testclient import TestClient from pytest_mock import MockerFixture -from sqlalchemy.orm import Session def test_can_post_without_user_id(client: TestClient): From c2f4c1b0d8b8c00bb54f091d68d47dc40642aa7c Mon Sep 17 00:00:00 2001 From: Roman Dyakov Date: Sat, 6 Apr 2024 15:56:52 +0300 Subject: [PATCH 4/5] Better on pr workflow --- .github/workflows/checks.yml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 48757a1..0053765 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -1,9 +1,8 @@ -name: Python package +name: Python tests on: pull_request: - jobs: test: name: Unit tests @@ -18,7 +17,7 @@ jobs: docker run -d -p 5432:5432 -e POSTGRES_HOST_AUTH_METHOD=trust --name db-test postgres:15-alpine - uses: actions/setup-python@v4 with: - python-version: '3.11' + python-version: "3.11" - name: Install dependencies run: | python -m ensurepip @@ -28,6 +27,7 @@ jobs: run: | DB_DSN=postgresql://postgres@localhost:5432/postgres alembic upgrade head - name: Build coverage file + id: pytest run: | DB_DSN=postgresql://postgres@localhost:5432/postgres pytest --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=marketing_api tests/ | tee pytest-coverage.txt - name: Print report @@ -48,6 +48,10 @@ jobs: remove-link-from-badge: false junitxml-path: ./pytest.xml junitxml-title: Summary + - name: Fail on pytest errors + if: steps.pytest.outcome == 'failure' + run: exit 1 + linting: runs-on: ubuntu-latest steps: @@ -60,9 +64,8 @@ jobs: requirementsFiles: "requirements.txt requirements.dev.txt" - uses: psf/black@stable - name: Comment if linting failed - if: ${{ failure() }} + if: failure() uses: thollander/actions-comment-pull-request@v2 with: message: | :poop: Code linting failed, use `black` and `isort` to fix it. - From 80dbbed50620e40f7b14ad8cfbbc44faf6dd1ce3 Mon Sep 17 00:00:00 2001 From: Roman Dyakov Date: Sat, 6 Apr 2024 16:21:33 +0300 Subject: [PATCH 5/5] Service instead docker setup --- .github/workflows/checks.yml | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 0053765..779e7b9 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -7,14 +7,20 @@ jobs: test: name: Unit tests runs-on: ubuntu-latest + services: + postgres: + image: postgres:15 + env: + POSTGRES_HOST_AUTH_METHOD: trust + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + -p 5432:5432 steps: - name: Checkout uses: actions/checkout@v4 - - name: Set up docker - uses: docker-practice/actions-setup-docker@master - - name: Run postgres - run: | - docker run -d -p 5432:5432 -e POSTGRES_HOST_AUTH_METHOD=trust --name db-test postgres:15-alpine - uses: actions/setup-python@v4 with: python-version: "3.11" @@ -30,6 +36,7 @@ jobs: id: pytest run: | DB_DSN=postgresql://postgres@localhost:5432/postgres pytest --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=marketing_api tests/ | tee pytest-coverage.txt + exit ${PIPESTATUS[0]} - name: Print report if: always() run: |