Skip to content

Commit e5a1cc1

Browse files
authored
Fixes in Makefile and Workflows (#174)
1 parent 7691904 commit e5a1cc1

13 files changed

Lines changed: 32 additions & 58 deletions
Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
1-
name: Python package
1+
name: Python tests
22

33
on:
44
pull_request:
55

6-
76
jobs:
87
test:
98
name: Unit tests
109
runs-on: ubuntu-latest
11-
continue-on-error: true
10+
services:
11+
postgres:
12+
image: postgres:15
13+
env:
14+
POSTGRES_HOST_AUTH_METHOD: trust
15+
options: >-
16+
--health-cmd pg_isready
17+
--health-interval 10s
18+
--health-timeout 5s
19+
--health-retries 5
20+
-p 5432:5432
1221
steps:
1322
- name: Checkout
1423
uses: actions/checkout@v4
15-
- name: Set up docker
16-
uses: docker-practice/actions-setup-docker@master
17-
- name: Run postgres
18-
run: |
19-
docker run -d -p 5432:5432 -e POSTGRES_HOST_AUTH_METHOD=trust --name db-test postgres:15-alpine
2024
- uses: actions/setup-python@v4
2125
with:
22-
python-version: '3.11'
26+
python-version: "3.11"
2327
- name: Install dependencies
2428
run: |
2529
python -m ensurepip
@@ -29,14 +33,17 @@ jobs:
2933
run: |
3034
DB_DSN=postgresql://postgres@localhost:5432/postgres alembic upgrade head
3135
- name: Build coverage file
36+
id: pytest
3237
run: |
3338
DB_DSN=postgresql://postgres@localhost:5432/postgres pytest --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=auth_backend tests/ | tee pytest-coverage.txt
39+
exit ${PIPESTATUS[0]}
3440
- name: Print report
3541
if: always()
3642
run: |
3743
cat pytest-coverage.txt
3844
- name: Pytest coverage comment
3945
uses: MishaKav/pytest-coverage-comment@main
46+
if: always()
4047
with:
4148
pytest-coverage-path: ./pytest-coverage.txt
4249
title: Coverage Report
@@ -49,6 +56,10 @@ jobs:
4956
remove-link-from-badge: false
5057
junitxml-path: ./pytest.xml
5158
junitxml-title: Summary
59+
- name: Fail on pytest errors
60+
if: steps.pytest.outcome == 'failure'
61+
run: exit 1
62+
5263
linting:
5364
runs-on: ubuntu-latest
5465
steps:
@@ -61,7 +72,7 @@ jobs:
6172
requirementsFiles: "requirements.txt requirements.dev.txt"
6273
- uses: psf/black@stable
6374
- name: Comment if linting failed
64-
if: ${{ failure() }}
75+
if: failure()
6576
uses: thollander/actions-comment-pull-request@v2
6677
with:
6778
message: |

migrations/versions/6c27352ee53b_unique_scopes.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
Create Date: 2023-03-12 23:39:28.891033
55
"""
66

7-
import sqlalchemy as sa
87
from alembic import op
98

109

migrations/versions/c03c6b509881_rollback_unique_scopes.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
77
"""
88

9-
import sqlalchemy as sa
109
from alembic import op
1110

1211

migrations/versions/dcb89e72d446_session_security_scopes.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,10 @@
66
77
"""
88

9-
import sqlalchemy as sa
109
from alembic import op
1110
from sqlalchemy.orm import Session
1211

13-
from auth_backend.models.db import (
14-
DynamicOption,
15-
Group,
16-
GroupScope,
17-
Scope,
18-
User,
19-
UserGroup,
20-
UserSession,
21-
UserSessionScope,
22-
)
12+
from auth_backend.models.db import DynamicOption, Group, Scope, User, UserSession
2313

2414

2515
# revision identifiers, used by Alembic.

tests/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import datetime
22
import errno
3-
from unittest.mock import AsyncMock, patch
3+
from unittest.mock import patch
44

55
import pytest
66
from fastapi.testclient import TestClient
77
from sqlalchemy import create_engine
88
from sqlalchemy.orm import sessionmaker
99
from starlette import status
1010

11-
from auth_backend.auth_plugins import Email, YandexAuth
11+
from auth_backend.auth_plugins import YandexAuth
1212
from auth_backend.auth_plugins.auth_method import random_string
1313
from auth_backend.models import AuthMethod, User
1414
from auth_backend.models.db import AuthMethod, Group, GroupScope, Scope, User, UserGroup, UserSession, UserSessionScope
1515
from auth_backend.routes.base import app
16-
from auth_backend.settings import Settings, get_settings
16+
from auth_backend.settings import get_settings
1717

1818

1919
@pytest.fixture

tests/test_routes/test_change_password.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import pytest
21
from fastapi.testclient import TestClient
32
from sqlalchemy.orm import Session
43
from starlette import status

tests/test_routes/test_delete_last_auth_method.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
1-
import asyncio
2-
import errno
3-
import random
4-
import string
5-
61
import pytest
7-
import pytest_asyncio
8-
from sqlalchemy import create_engine
9-
from sqlalchemy.orm import Session, sessionmaker
102

11-
from auth_backend.auth_plugins import Email, YandexAuth
12-
from auth_backend.auth_plugins.auth_method import random_string
3+
from auth_backend.auth_plugins import YandexAuth
134
from auth_backend.exceptions import LastAuthMethodDelete
14-
from auth_backend.models import AuthMethod, User
15-
from auth_backend.settings import Settings, get_settings
5+
from auth_backend.settings import get_settings
166

177

188
pytest_plugins = ('pytest_asyncio',)

tests/test_routes/test_email_message_delay.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import pytest
21
from fastapi.testclient import TestClient
32
from sqlalchemy.orm import Session
43
from starlette import status
54

6-
from auth_backend.models.db import UserMessageDelay
7-
from auth_backend.settings import Settings, get_settings
5+
from auth_backend.settings import get_settings
86

97

108
settings = get_settings()

tests/test_routes/test_group_scopes.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import datetime
22

3-
import pytest
4-
5-
from auth_backend.auth_plugins.auth_method import random_string
6-
from auth_backend.models.db import AuthMethod, Group, GroupScope, Scope, User, UserGroup, UserSession, UserSessionScope
3+
from auth_backend.models.db import Group, GroupScope, Scope, UserGroup
74

85

96
def test_scopes_groups(client_auth, dbsession, user_scopes):

tests/test_routes/test_groups.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import datetime
2-
from time import sleep
32

4-
import httpx
53
import pytest
64

75
from auth_backend.exceptions import ObjectNotFound
8-
from auth_backend.models.db import Group, GroupScope, Scope, User, UserGroup
6+
from auth_backend.models.db import Group, UserGroup
97

108

119
def test_create(client, dbsession):

0 commit comments

Comments
 (0)