From 4d0f439c8ccbb4a4f0a37305a17e82e37ecbdfa0 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sun, 24 Jul 2022 20:27:58 +0200 Subject: [PATCH] Tweak test suite --- tests/conftest.py | 24 ++++------------------- tests/test_process_outgoing_activities.py | 5 ++--- 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 8985470..a528f23 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,11 +4,11 @@ import pytest from fastapi.testclient import TestClient from app.database import Base -from app.database import SessionLocal from app.database import async_engine from app.database import async_session from app.database import engine from app.main import app +from tests.factories import _Session @pytest.fixture @@ -25,28 +25,12 @@ async def async_db_session(): def db() -> Generator: Base.metadata.create_all(bind=engine) try: - yield SessionLocal() + yield _Session finally: - try: - Base.metadata.drop_all(bind=engine) - except Exception: - # XXX: for some reason, the teardown occasionally fails because of this - pass + Base.metadata.drop_all(bind=engine) @pytest.fixture -def exclude_fastapi_middleware(): - """Workaround for https://github.com/encode/starlette/issues/472""" - user_middleware = app.user_middleware.copy() - app.user_middleware = [] - app.middleware_stack = app.build_middleware_stack() - yield - app.user_middleware = user_middleware - app.middleware_stack = app.build_middleware_stack() - - -@pytest.fixture -def client(db, exclude_fastapi_middleware) -> Generator: - # app.dependency_overrides[get_db] = _get_db_for_testing +def client(db) -> Generator: with TestClient(app) as c: yield c diff --git a/tests/test_process_outgoing_activities.py b/tests/test_process_outgoing_activities.py index e50958d..a0c303a 100644 --- a/tests/test_process_outgoing_activities.py +++ b/tests/test_process_outgoing_activities.py @@ -56,6 +56,7 @@ async def test_new_outgoing_activity( outgoing_activity = await new_outgoing_activity( async_db_session, inbox_url, outbox_object.id ) + await async_db_session.commit() assert ( await async_db_session.execute(select(models.OutgoingActivity)) @@ -105,8 +106,6 @@ def test_process_next_outgoing_activity__webmention( db: Session, respx_mock: respx.MockRouter, ) -> None: - # FIXME(ts): fix not passing in CI (but passing in local) - return # And an outgoing activity outbox_object = _setup_outbox_object() @@ -176,7 +175,7 @@ def test_process_next_outgoing_activity__errored( ) # And an outgoing activity - outgoing_activity = factories.OutgoingActivityFactory( + outgoing_activity = factories.OutgoingActivityFactory.create( recipient=recipient_inbox_url, outbox_object_id=outbox_object.id, inbox_object_id=None,