"""Shared test fixtures.""" from typing import Any import pytest _SAMPLE_RSS = b""" Sample Feed First Article https://example.test/article/1 <p>A short summary.</p> Mon, 19 May 2026 13:00:00 GMT Jane Doe Second Article Plain text summary without HTML. Mon, 19 May 2026 12:00:00 GMT """ _SAMPLE_ARTICLE_HTML = b"""

First paragraph of the article.

Second paragraph with more detail.

Third paragraph closing the story.

""" _SAMPLE_JSONLD_HTML = b""" """ # Mirrors the real drugs.com article DOM: no
, sidebar inside
, # and trailing furniture after the disclaimer. _SAMPLE_DRUGS_COM_HTML = b"""
Home News Consumer News Print page

FDA Clears First Cholesterol Pill

THURSDAY, July 16, 2026 — A new daily pill will lower cholesterol.

The FDA acted today to approve the drug for adults.

  • Sources

Disclaimer: Statistical data in medical articles provide general trends.

© 2026 HealthDay. All rights reserved.

Read this next

Related teaser one.

Related teaser two.

More news resources

  • FDA Medwatch Drug Alerts

Subscribe to our newsletter

Whatever your topic of interest, subscribe to our newsletters.

Podcast pitch paragraph.

Sidebar drug teaser one.

Sidebar drug teaser two.

""" @pytest.fixture def sample_drugs_com_html() -> bytes: return _SAMPLE_DRUGS_COM_HTML @pytest.fixture def sample_rss() -> bytes: return _SAMPLE_RSS @pytest.fixture def sample_article_html() -> bytes: return _SAMPLE_ARTICLE_HTML @pytest.fixture def sample_jsonld_html() -> bytes: return _SAMPLE_JSONLD_HTML class _FakeResponse: def __init__(self, content: bytes = b"", status: int = 200) -> None: self._content = content self.status = status async def read(self) -> bytes: return self._content def raise_for_status(self) -> None: if self.status >= 400: import aiohttp raise aiohttp.ClientResponseError( request_info=None, # type: ignore[arg-type] history=(), status=self.status, ) async def __aenter__(self) -> "_FakeResponse": return self async def __aexit__(self, *_args: Any) -> None: return None class _FakeSession: def __init__(self, response_map: dict) -> None: self.response_map = response_map self.calls: list[str] = [] self.headers_sent: list[dict | None] = [] self.closed = False async def get(self, url: str, **kwargs: Any) -> _FakeResponse: self.calls.append(url) self.headers_sent.append(kwargs.get("headers")) result = self.response_map.get(url) if result is None: raise KeyError(f"unmocked URL: {url}") if isinstance(result, BaseException): raise result return result async def __aenter__(self) -> "_FakeSession": return self async def __aexit__(self, *_args: Any) -> None: self.closed = True async def close(self) -> None: self.closed = True @pytest.fixture def stub_session_factory(monkeypatch): def factory(response_map: dict) -> _FakeSession: normalized: dict = {} for url, value in response_map.items(): if isinstance(value, (bytes, bytearray)): normalized[url] = _FakeResponse(bytes(value)) elif ( isinstance(value, tuple) and len(value) == 2 and isinstance(value[0], (bytes, bytearray)) ): content, status = value normalized[url] = _FakeResponse(bytes(content), status=int(status)) else: normalized[url] = value session = _FakeSession(normalized) async def _factory(*_a: Any, **_kw: Any) -> _FakeSession: return session monkeypatch.setattr( "openbb_core.provider.utils.helpers.get_async_requests_session", _factory, ) return session return factory