Skip to content

Commit f736c15

Browse files
committed
Add tests/test_cdaweb_contract.py: drift probes for CDAWeb
Four daily-cron probes covering the live CDA paths whose cassettes were dropped from the unit tier for size reasons (full inventory fetch and the FEEPS electron-intensity request) plus two cheap smoke checks (short THA fetch, inventory dataset presence).
1 parent 6a7ea07 commit f736c15

1 file changed

Lines changed: 87 additions & 0 deletions

File tree

tests/test_cdaweb_contract.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
"""Daily real-server probes for CDAWeb upstream-drift detection.
2+
3+
These tests run on the contract tier (daily cron) and hit the live
4+
NASA CDAWeb service. Failures here mean CDA changed something we
5+
depend on - the relevant cassettes need re-recording.
6+
7+
Most of CDA's coverage runs on the unit tier via cassettes. This file
8+
keeps the cassette-tier in budget by hosting the few probes whose
9+
recorded payloads would be too large to ship as cassettes:
10+
11+
- A full-inventory fetch (multi-hundred-MB response).
12+
- A FEEPS electron-intensity request known to recover a large CDF.
13+
14+
It also adds two short smoke probes against well-known datasets so a
15+
failure here actually says "CDA changed", not "this one large dataset
16+
moved".
17+
"""
18+
19+
from __future__ import annotations
20+
21+
import os
22+
import unittest
23+
from datetime import datetime, timezone
24+
25+
import pytest
26+
27+
import speasy as spz
28+
from speasy.products import SpeasyVariable
29+
30+
pytestmark = pytest.mark.contract
31+
32+
33+
def _reset_cda_inventory_cache_flags() -> None:
34+
spz.core.index.index.set("cdaweb-inventory", "masters-last-modified", "")
35+
spz.core.index.index.set("cdaweb-inventory", "xml_catalog-last-modified", "")
36+
if spz.core.index.index.contains("cdaweb-inventory", "tree"):
37+
spz.core.index.index.pop("cdaweb-inventory", "tree")
38+
39+
40+
class CdaWebContractProbes(unittest.TestCase):
41+
42+
def test_short_request_returns_speasy_variable(self) -> None:
43+
result = spz.cda.get_variable(
44+
dataset="THA_L2_FGM",
45+
variable="tha_fgl_gsm",
46+
start_time=datetime(2014, 6, 1, tzinfo=timezone.utc),
47+
stop_time=datetime(2014, 6, 1, 0, 5, tzinfo=timezone.utc),
48+
disable_proxy=True,
49+
disable_cache=True,
50+
method="API",
51+
)
52+
self.assertIsInstance(result, SpeasyVariable)
53+
self.assertGreater(len(result), 0)
54+
55+
def test_inventory_has_known_dataset(self) -> None:
56+
from speasy.inventories import flat_inventories
57+
# Loaded at import time; just probe a well-known node.
58+
self.assertIn("THA_L2_FGM", flat_inventories.cda.datasets)
59+
60+
def test_full_inventory_fetch_finds_at_least_47000_parameters(self) -> None:
61+
# Full inventory pull is a multi-hundred-MB response - too large for
62+
# a cassette but cheap-enough to run daily as a drift probe.
63+
os.environ[spz.config.proxy.enabled.env_var_name] = "False"
64+
_reset_cda_inventory_cache_flags()
65+
try:
66+
spz.cda.update_inventory()
67+
self.assertGreaterEqual(
68+
len(spz.inventories.flat_inventories.cda.parameters), 47000
69+
)
70+
finally:
71+
os.environ.pop(spz.config.proxy.enabled.env_var_name, None)
72+
73+
def test_feeps_electron_intensity_returns_data(self) -> None:
74+
# MMS FEEPS payloads are large CDFs; not cassette-friendly.
75+
result = spz.get_data(
76+
"cda/MMS1_FEEPS_SRVY_L2_ELECTRON/"
77+
"mms1_epd_feeps_srvy_l2_electron_bottom_intensity_sensorid_2",
78+
datetime(2018, 5, 26, 1, 0, 0),
79+
datetime(2018, 5, 26, 1, 10, 1),
80+
disable_proxy=True,
81+
disable_cache=True,
82+
)
83+
self.assertIsNotNone(result)
84+
85+
86+
if __name__ == "__main__":
87+
unittest.main()

0 commit comments

Comments
 (0)