From 1c9b73b17012316cfbcf818035a3c3b8b8dbabdd Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Fri, 29 Jul 2022 09:24:51 +0200 Subject: [PATCH] Fix LD sig tests --- pyproject.toml | 3 +++ tests/conftest.py | 3 ++- tests/test_ldsig.py | 14 ++++++++++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 4f2fc3c..d2a1a2c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -83,3 +83,6 @@ extend-exclude = ''' | alembic/versions )/ ''' + +[tool.pytest.ini_options] +asyncio_mode = "auto" diff --git a/tests/conftest.py b/tests/conftest.py index e2eaa2f..b78cb2c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,7 @@ from typing import Generator import pytest +import pytest_asyncio from fastapi.testclient import TestClient from app.database import Base @@ -11,7 +12,7 @@ from app.main import app from tests.factories import _Session -@pytest.fixture +@pytest_asyncio.fixture async def async_db_session(): async with async_session() as session: async with async_engine.begin() as conn: diff --git a/tests/test_ldsig.py b/tests/test_ldsig.py index d371994..62ea525 100644 --- a/tests/test_ldsig.py +++ b/tests/test_ldsig.py @@ -1,7 +1,12 @@ from copy import deepcopy +import httpx +import pytest +from respx import MockRouter + from app import activitypub as ap from app import ldsig +from app.database import AsyncSession from app.key import Key from tests import factories @@ -28,7 +33,11 @@ _SAMPLE_CREATE = { } -def test_linked_data_sig(): +@pytest.mark.asyncio +async def test_linked_data_sig( + async_db_session: AsyncSession, + respx_mock: MockRouter, +) -> None: privkey, pubkey = factories.generate_key() ra = factories.RemoteActorFactory( base_url="https://microblog.pub", @@ -37,8 +46,9 @@ def test_linked_data_sig(): ) k = Key(ra.ap_id, f"{ra.ap_id}#main-key") k.load(privkey) + respx_mock.get(ra.ap_id).mock(return_value=httpx.Response(200, json=ra.ap_actor)) doc = deepcopy(_SAMPLE_CREATE) ldsig.generate_signature(doc, k) - assert ldsig.verify_signature(doc, k) + assert (await ldsig.verify_signature(async_db_session, doc)) is True