import logging
import uuid
from collections.abc import Callable
from types import ModuleType
import httpx
import pytest
from flask import Flask
from webmentions_ssg import DATABASE as db
from webmentions_ssg.models import ReceivedWebmention
SOURCE_URL = "https://source.example/article"
TARGET_URL = "https://dennisfink.me/blog/example/"
ReceivedWebmentionFactory = Callable[..., uuid.UUID]
HTTPXMockInstaller = Callable[
[Callable[[httpx.Request], httpx.Response]],
None,
]
def get_webmention_state(
app: Flask,
identifier: uuid.UUID,
) -> tuple[str, str | None]:
with app.app_context():
webmention = db.session.get(
ReceivedWebmention,
identifier,
)
assert webmention is not None
return (
webmention.status,
webmention.failure_reason,
)
@pytest.mark.parametrize(
(
"body",
"source_url",
"target_url",
"expected",
),
[
pytest.param(
f'Reply',
SOURCE_URL,
TARGET_URL,
True,
id="a-href",
),
pytest.param(
f'',
SOURCE_URL,
TARGET_URL,
True,
id="area-href",
),
pytest.param(
f'',
SOURCE_URL,
TARGET_URL,
True,
id="link-href",
),
pytest.param(
f'
',
SOURCE_URL,
TARGET_URL,
True,
id="img-src",
),
pytest.param(
f'',
SOURCE_URL,
TARGET_URL,
True,
id="audio-src",
),
pytest.param(
f'',
SOURCE_URL,
TARGET_URL,
True,
id="video-src",
),
pytest.param(
(f''),
SOURCE_URL,
TARGET_URL,
True,
id="audio-source-src",
),
pytest.param(
(f''),
SOURCE_URL,
TARGET_URL,
True,
id="video-source-src",
),
pytest.param(
f'',
SOURCE_URL,
TARGET_URL,
True,
id="iframe-src",
),
pytest.param(
f'