Skip to content

Commit

Permalink
Merge pull request #80 from rafsaf/dependabot/pip/all-dependencies-27…
Browse files Browse the repository at this point in the history
…b3656dda

Bump the all-dependencies group across 1 directory with 25 updates
  • Loading branch information
rafsaf authored Aug 28, 2024
2 parents fb0284c + 7dba35d commit 1d24352
Show file tree
Hide file tree
Showing 11 changed files with 787 additions and 956 deletions.
2 changes: 1 addition & 1 deletion app/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Settings(BaseSettings):
security: Security
database: Database

@computed_field # type: ignore[misc]
@computed_field # type: ignore[prop-decorator]
@property
def sqlalchemy_database_uri(self) -> URL:
return URL.create(
Expand Down
30 changes: 19 additions & 11 deletions app/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio
import logging
import os
from collections.abc import AsyncGenerator, Generator
from collections.abc import AsyncGenerator

import pytest
import pytest_asyncio
Expand All @@ -24,12 +24,17 @@
default_user_access_token = create_jwt_token(default_user_id).access_token


@pytest.fixture(scope="session")
def event_loop() -> Generator[asyncio.AbstractEventLoop, None, None]:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
yield loop
loop.close()
# @pytest.fixture(scope="session")
# def event_loop_policy():
# return uvloop.EventLoopPolicy()


# @pytest.fixture(scope="session")
# def event_loop() -> Generator[asyncio.AbstractEventLoop, None, None]:
# loop = asyncio.new_event_loop()
# asyncio.set_event_loop(loop)
# yield loop
# loop.close()


@pytest_asyncio.fixture(scope="session", autouse=True)
Expand Down Expand Up @@ -102,6 +107,7 @@ async def fixture_session_with_rollback(

yield session

logging.critical("Rolling back transaction")
await session.close()
await transaction.rollback()
await connection.close()
Expand All @@ -118,18 +124,20 @@ async def fixture_client(session: AsyncSession) -> AsyncGenerator[AsyncClient, N
@pytest_asyncio.fixture(name="default_user", scope="function")
async def fixture_default_user(
session: AsyncSession, default_hashed_password: str
) -> User:
) -> AsyncGenerator[User, None]:
default_user = User(
user_id=default_user_id,
email=default_user_email,
hashed_password=default_hashed_password,
)
session.add(default_user)

await session.commit()
await session.refresh(default_user)
return default_user

yield default_user


@pytest.fixture(name="default_user_headers", scope="function")
@pytest_asyncio.fixture(name="default_user_headers", scope="function")
def fixture_default_user_headers(default_user: User) -> dict[str, str]:
return {"Authorization": f"Bearer {default_user_access_token}"}
3 changes: 3 additions & 0 deletions app/tests/test_api_router_jwt_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from app.models import User


@pytest.mark.asyncio(loop_scope="session")
@pytest.mark.parametrize("api_route", api_router.routes)
async def test_api_routes_raise_401_on_jwt_decode_errors(
client: AsyncClient,
Expand All @@ -26,6 +27,7 @@ async def test_api_routes_raise_401_on_jwt_decode_errors(
assert response.json() == {"detail": "Token invalid: Not enough segments"}


@pytest.mark.asyncio(loop_scope="session")
@pytest.mark.parametrize("api_route", api_router.routes)
async def test_api_routes_raise_401_on_jwt_expired_token(
client: AsyncClient,
Expand All @@ -45,6 +47,7 @@ async def test_api_routes_raise_401_on_jwt_expired_token(
assert response.json() == {"detail": "Token invalid: Signature has expired"}


@pytest.mark.asyncio(loop_scope="session")
@pytest.mark.parametrize("api_route", api_router.routes)
async def test_api_routes_raise_401_on_jwt_user_deleted(
client: AsyncClient,
Expand Down
10 changes: 10 additions & 0 deletions app/tests/test_auth/test_access_token.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import time

import pytest
from fastapi import status
from freezegun import freeze_time
from httpx import AsyncClient
Expand All @@ -14,6 +15,7 @@
from app.tests.conftest import default_user_password


@pytest.mark.asyncio(loop_scope="session")
async def test_login_access_token_has_response_status_code(
client: AsyncClient,
default_user: User,
Expand All @@ -30,6 +32,7 @@ async def test_login_access_token_has_response_status_code(
assert response.status_code == status.HTTP_200_OK


@pytest.mark.asyncio(loop_scope="session")
async def test_login_access_token_jwt_has_valid_token_type(
client: AsyncClient,
default_user: User,
Expand All @@ -47,6 +50,7 @@ async def test_login_access_token_jwt_has_valid_token_type(
assert token["token_type"] == "Bearer"


@pytest.mark.asyncio(loop_scope="session")
@freeze_time("2023-01-01")
async def test_login_access_token_jwt_has_valid_expire_time(
client: AsyncClient,
Expand All @@ -69,6 +73,7 @@ async def test_login_access_token_jwt_has_valid_expire_time(
)


@pytest.mark.asyncio(loop_scope="session")
@freeze_time("2023-01-01")
async def test_login_access_token_returns_valid_jwt_access_token(
client: AsyncClient,
Expand All @@ -92,6 +97,7 @@ async def test_login_access_token_returns_valid_jwt_access_token(
assert token_payload.exp == token["expires_at"]


@pytest.mark.asyncio(loop_scope="session")
async def test_login_access_token_refresh_token_has_valid_expire_time(
client: AsyncClient,
default_user: User,
Expand All @@ -113,6 +119,7 @@ async def test_login_access_token_refresh_token_has_valid_expire_time(
)


@pytest.mark.asyncio(loop_scope="session")
async def test_login_access_token_refresh_token_exists_in_db(
client: AsyncClient,
default_user: User,
Expand All @@ -135,6 +142,7 @@ async def test_login_access_token_refresh_token_exists_in_db(
assert token_db_count == 1


@pytest.mark.asyncio(loop_scope="session")
async def test_login_access_token_refresh_token_in_db_has_valid_fields(
client: AsyncClient,
default_user: User,
Expand All @@ -160,6 +168,7 @@ async def test_login_access_token_refresh_token_in_db_has_valid_fields(
assert not refresh_token.used


@pytest.mark.asyncio(loop_scope="session")
async def test_auth_access_token_fail_for_not_existing_user_with_message(
client: AsyncClient,
) -> None:
Expand All @@ -176,6 +185,7 @@ async def test_auth_access_token_fail_for_not_existing_user_with_message(
assert response.json() == {"detail": api_messages.PASSWORD_INVALID}


@pytest.mark.asyncio(loop_scope="session")
async def test_auth_access_token_fail_for_invalid_password_with_message(
client: AsyncClient,
default_user: User,
Expand Down
11 changes: 11 additions & 0 deletions app/tests/test_auth/test_auth_refresh_token.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import time

import pytest
from fastapi import status
from freezegun import freeze_time
from httpx import AsyncClient
Expand All @@ -13,6 +14,7 @@
from app.models import RefreshToken, User


@pytest.mark.asyncio(loop_scope="session")
async def test_refresh_token_fails_with_message_when_token_does_not_exist(
client: AsyncClient,
) -> None:
Expand All @@ -27,6 +29,7 @@ async def test_refresh_token_fails_with_message_when_token_does_not_exist(
assert response.json() == {"detail": api_messages.REFRESH_TOKEN_NOT_FOUND}


@pytest.mark.asyncio(loop_scope="session")
async def test_refresh_token_fails_with_message_when_token_is_expired(
client: AsyncClient,
default_user: User,
Expand All @@ -51,6 +54,7 @@ async def test_refresh_token_fails_with_message_when_token_is_expired(
assert response.json() == {"detail": api_messages.REFRESH_TOKEN_EXPIRED}


@pytest.mark.asyncio(loop_scope="session")
async def test_refresh_token_fails_with_message_when_token_is_used(
client: AsyncClient,
default_user: User,
Expand All @@ -76,6 +80,7 @@ async def test_refresh_token_fails_with_message_when_token_is_used(
assert response.json() == {"detail": api_messages.REFRESH_TOKEN_ALREADY_USED}


@pytest.mark.asyncio(loop_scope="session")
async def test_refresh_token_success_response_status_code(
client: AsyncClient,
default_user: User,
Expand All @@ -100,6 +105,7 @@ async def test_refresh_token_success_response_status_code(
assert response.status_code == status.HTTP_200_OK


@pytest.mark.asyncio(loop_scope="session")
async def test_refresh_token_success_old_token_is_used(
client: AsyncClient,
default_user: User,
Expand Down Expand Up @@ -128,6 +134,7 @@ async def test_refresh_token_success_old_token_is_used(
assert used_test_refresh_token.used


@pytest.mark.asyncio(loop_scope="session")
async def test_refresh_token_success_jwt_has_valid_token_type(
client: AsyncClient,
default_user: User,
Expand All @@ -153,6 +160,7 @@ async def test_refresh_token_success_jwt_has_valid_token_type(
assert token["token_type"] == "Bearer"


@pytest.mark.asyncio(loop_scope="session")
@freeze_time("2023-01-01")
async def test_refresh_token_success_jwt_has_valid_expire_time(
client: AsyncClient,
Expand Down Expand Up @@ -183,6 +191,7 @@ async def test_refresh_token_success_jwt_has_valid_expire_time(
)


@pytest.mark.asyncio(loop_scope="session")
@freeze_time("2023-01-01")
async def test_refresh_token_success_jwt_has_valid_access_token(
client: AsyncClient,
Expand Down Expand Up @@ -214,6 +223,7 @@ async def test_refresh_token_success_jwt_has_valid_access_token(
assert token_payload.exp == token["expires_at"]


@pytest.mark.asyncio(loop_scope="session")
@freeze_time("2023-01-01")
async def test_refresh_token_success_refresh_token_has_valid_expire_time(
client: AsyncClient,
Expand Down Expand Up @@ -244,6 +254,7 @@ async def test_refresh_token_success_refresh_token_has_valid_expire_time(
)


@pytest.mark.asyncio(loop_scope="session")
async def test_refresh_token_success_new_refresh_token_is_in_db(
client: AsyncClient,
default_user: User,
Expand Down
4 changes: 4 additions & 0 deletions app/tests/test_auth/test_register_new_user.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
from fastapi import status
from httpx import AsyncClient
from sqlalchemy import func, select
Expand All @@ -8,6 +9,7 @@
from app.models import User


@pytest.mark.asyncio(loop_scope="session")
async def test_register_new_user_status_code(
client: AsyncClient,
) -> None:
Expand All @@ -22,6 +24,7 @@ async def test_register_new_user_status_code(
assert response.status_code == status.HTTP_201_CREATED


@pytest.mark.asyncio(loop_scope="session")
async def test_register_new_user_creates_record_in_db(
client: AsyncClient,
session: AsyncSession,
Expand All @@ -40,6 +43,7 @@ async def test_register_new_user_creates_record_in_db(
assert user_count == 1


@pytest.mark.asyncio(loop_scope="session")
async def test_register_new_user_cannot_create_already_created_user(
client: AsyncClient,
session: AsyncSession,
Expand Down
3 changes: 3 additions & 0 deletions app/tests/test_users/test_delete_current_user.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
from fastapi import status
from httpx import AsyncClient
from sqlalchemy import select
Expand All @@ -7,6 +8,7 @@
from app.models import User


@pytest.mark.asyncio(loop_scope="session")
async def test_delete_current_user_status_code(
client: AsyncClient,
default_user_headers: dict[str, str],
Expand All @@ -19,6 +21,7 @@ async def test_delete_current_user_status_code(
assert response.status_code == status.HTTP_204_NO_CONTENT


@pytest.mark.asyncio(loop_scope="session")
async def test_delete_current_user_is_deleted_in_db(
client: AsyncClient,
default_user_headers: dict[str, str],
Expand Down
3 changes: 3 additions & 0 deletions app/tests/test_users/test_read_current_user.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
from fastapi import status
from httpx import AsyncClient

Expand All @@ -8,6 +9,7 @@
)


@pytest.mark.asyncio(loop_scope="session")
async def test_read_current_user_status_code(
client: AsyncClient, default_user_headers: dict[str, str]
) -> None:
Expand All @@ -19,6 +21,7 @@ async def test_read_current_user_status_code(
assert response.status_code == status.HTTP_200_OK


@pytest.mark.asyncio(loop_scope="session")
async def test_read_current_user_response(
client: AsyncClient, default_user_headers: dict[str, str]
) -> None:
Expand Down
3 changes: 3 additions & 0 deletions app/tests/test_users/test_reset_password.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
from fastapi import status
from httpx import AsyncClient
from sqlalchemy import select
Expand All @@ -8,6 +9,7 @@
from app.models import User


@pytest.mark.asyncio(loop_scope="session")
async def test_reset_current_user_password_status_code(
client: AsyncClient,
default_user_headers: dict[str, str],
Expand All @@ -21,6 +23,7 @@ async def test_reset_current_user_password_status_code(
assert response.status_code == status.HTTP_204_NO_CONTENT


@pytest.mark.asyncio(loop_scope="session")
async def test_reset_current_user_password_is_changed_in_db(
client: AsyncClient,
default_user_headers: dict[str, str],
Expand Down
Loading

0 comments on commit 1d24352

Please sign in to comment.