Tweak test suite

main
Thomas Sileo 2022-07-24 20:27:58 +02:00
parent 55cbd8b617
commit 4d0f439c8c
2 changed files with 6 additions and 23 deletions

View File

@ -4,11 +4,11 @@ import pytest
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from app.database import Base from app.database import Base
from app.database import SessionLocal
from app.database import async_engine from app.database import async_engine
from app.database import async_session from app.database import async_session
from app.database import engine from app.database import engine
from app.main import app from app.main import app
from tests.factories import _Session
@pytest.fixture @pytest.fixture
@ -25,28 +25,12 @@ async def async_db_session():
def db() -> Generator: def db() -> Generator:
Base.metadata.create_all(bind=engine) Base.metadata.create_all(bind=engine)
try: try:
yield SessionLocal() yield _Session
finally: finally:
try:
Base.metadata.drop_all(bind=engine) Base.metadata.drop_all(bind=engine)
except Exception:
# XXX: for some reason, the teardown occasionally fails because of this
pass
@pytest.fixture @pytest.fixture
def exclude_fastapi_middleware(): def client(db) -> Generator:
"""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
with TestClient(app) as c: with TestClient(app) as c:
yield c yield c

View File

@ -56,6 +56,7 @@ async def test_new_outgoing_activity(
outgoing_activity = await new_outgoing_activity( outgoing_activity = await new_outgoing_activity(
async_db_session, inbox_url, outbox_object.id async_db_session, inbox_url, outbox_object.id
) )
await async_db_session.commit()
assert ( assert (
await async_db_session.execute(select(models.OutgoingActivity)) await async_db_session.execute(select(models.OutgoingActivity))
@ -105,8 +106,6 @@ def test_process_next_outgoing_activity__webmention(
db: Session, db: Session,
respx_mock: respx.MockRouter, respx_mock: respx.MockRouter,
) -> None: ) -> None:
# FIXME(ts): fix not passing in CI (but passing in local)
return
# And an outgoing activity # And an outgoing activity
outbox_object = _setup_outbox_object() outbox_object = _setup_outbox_object()
@ -176,7 +175,7 @@ def test_process_next_outgoing_activity__errored(
) )
# And an outgoing activity # And an outgoing activity
outgoing_activity = factories.OutgoingActivityFactory( outgoing_activity = factories.OutgoingActivityFactory.create(
recipient=recipient_inbox_url, recipient=recipient_inbox_url,
outbox_object_id=outbox_object.id, outbox_object_id=outbox_object.id,
inbox_object_id=None, inbox_object_id=None,