Skip to content

Commit 92f5464

Browse files
committed
use cassettes
1 parent 18c0da2 commit 92f5464

6 files changed

+51051
-3
lines changed

tests/cassettes/test_extract_preserves_article_metadata[doi].yaml

Lines changed: 11573 additions & 0 deletions
Large diffs are not rendered by default.

tests/cassettes/test_extract_preserves_article_metadata[pmid].yaml

Lines changed: 13935 additions & 0 deletions
Large diffs are not rendered by default.

tests/cassettes/test_extract_returns_coordinates_for_real_articles[doi].yaml

Lines changed: 11573 additions & 0 deletions
Large diffs are not rendered by default.

tests/cassettes/test_extract_returns_coordinates_for_real_articles[pmid].yaml

Lines changed: 13935 additions & 0 deletions
Large diffs are not rendered by default.

tests/conftest.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111
pytest_plugins = ("pytest_asyncio",)
1212

1313

14+
def _strip_cookies(response: dict[str, Any]) -> dict[str, Any]:
15+
"""Remove volatile cookie headers before storing responses."""
16+
response.get("headers", {}).pop("Set-Cookie", None)
17+
response.get("headers", {}).pop("set-cookie", None)
18+
return response
19+
20+
1421
@pytest.fixture(scope="session")
1522
def vcr_config() -> dict[str, Any]:
1623
"""Configure pytest-recording for cassette storage and header scrubbing."""
@@ -19,11 +26,36 @@ def vcr_config() -> dict[str, Any]:
1926
return {
2027
"cassette_library_dir": str(cassette_dir),
2128
"record_mode": os.getenv("PYTEST_RECORDING_MODE", "once"),
22-
"filter_headers": ["X-Elsevier-Apikey", "Authorization"],
23-
"filter_query_parameters": [("apiKey", "DUMMY")],
29+
"filter_headers": [
30+
"authorization",
31+
"x-api-key",
32+
"x-els-apikey",
33+
"cookie",
34+
"set-cookie",
35+
"user-agent",
36+
],
37+
"filter_query_parameters": [
38+
"apiKey",
39+
"apikey",
40+
"api_key",
41+
"access_token",
42+
],
43+
"decode_compressed_response": True,
44+
"allow_playback_repeats": True,
45+
"before_record_response": _strip_cookies,
2446
}
2547

2648

49+
@pytest.fixture
50+
def vcr_cassette(vcr: Any, request: pytest.FixtureRequest):
51+
"""Automatically open a cassette per-test (module/testname)."""
52+
53+
module = request.node.module.__name__.replace(".", "_")
54+
path = Path("auto") / module / f"{request.node.name}.yaml"
55+
with vcr.use_cassette(str(path)):
56+
yield
57+
58+
2759
@pytest.fixture(scope="session")
2860
def test_dois() -> list[str]:
2961
"""Provide a set of DOIs for use in tests."""

tests/extract/test_coordinates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from elsevier_coordinate_extraction.types import ArticleContent, build_article_content
1616

1717

18-
@pytest.fixture(scope="module", params=("doi", "pmid"), ids=("doi", "pmid"))
18+
@pytest.fixture(scope="function", params=("doi", "pmid"), ids=("doi", "pmid"))
1919
def downloaded_articles(
2020
request: pytest.FixtureRequest,
2121
test_dois: list[str],

0 commit comments

Comments
 (0)