|
1 | 1 | from pathlib import Path |
| 2 | +from typing import List |
| 3 | + |
| 4 | +import pytest |
2 | 5 |
|
3 | 6 | from scripts.validate_storefront_claims import ( |
4 | 7 | discover_installed_surfaces, |
|
10 | 13 | ROOT = Path(__file__).resolve().parents[1] |
11 | 14 |
|
12 | 15 |
|
| 16 | +def _installed_text_failures(tmp_path: Path, text: str) -> List[str]: |
| 17 | + package = tmp_path / "oilpriceapi" |
| 18 | + dist_info = tmp_path / "oilpriceapi-9.9.9.dist-info" |
| 19 | + package.mkdir() |
| 20 | + dist_info.mkdir() |
| 21 | + (package / "version.py").write_text('__version__ = "9.9.9"\n') |
| 22 | + (package / "future.txt").write_text(text) |
| 23 | + (dist_info / "METADATA").write_text( |
| 24 | + "Metadata-Version: 2.1\n" |
| 25 | + "Name: oilpriceapi\n" |
| 26 | + "Version: 9.9.9\n\n" |
| 27 | + "https://api.oilpriceapi.com/product-facts.json\n" |
| 28 | + ) |
| 29 | + (dist_info / "RECORD").write_text( |
| 30 | + "oilpriceapi/version.py,,\n" |
| 31 | + "oilpriceapi/future.txt,,\n" |
| 32 | + "oilpriceapi-9.9.9.dist-info/METADATA,,\n" |
| 33 | + "oilpriceapi-9.9.9.dist-info/RECORD,,\n" |
| 34 | + ) |
| 35 | + return validate_package(tmp_path) |
| 36 | + |
| 37 | + |
13 | 38 | def test_storefront_claims_match_reviewed_contract() -> None: |
14 | 39 | assert validate() == [] |
15 | 40 |
|
@@ -115,3 +140,41 @@ def test_rejects_claim_in_future_installed_package_data(tmp_path: Path) -> None: |
115 | 140 | and "matched '50 requests/day'" in failure |
116 | 141 | for failure in failures |
117 | 142 | ) |
| 143 | + |
| 144 | + |
| 145 | +@pytest.mark.parametrize( |
| 146 | + "claim", |
| 147 | + [ |
| 148 | + "50 API calls/day", |
| 149 | + "50 calls per day", |
| 150 | + "50 requests daily", |
| 151 | + "daily limit of 50 requests", |
| 152 | + "50-request daily allowance", |
| 153 | + "100 API calls hourly", |
| 154 | + "hourly request quota: 100 calls", |
| 155 | + "3 reqs/minute", |
| 156 | + "50 calls each day", |
| 157 | + "100 API requests every hour", |
| 158 | + "daily cap is 50 calls", |
| 159 | + "50-call-per-day allowance", |
| 160 | + ], |
| 161 | +) |
| 162 | +def test_rejects_fixed_rate_aliases_in_installed_text(tmp_path: Path, claim: str) -> None: |
| 163 | + failures = _installed_text_failures(tmp_path, claim) |
| 164 | + |
| 165 | + assert any("fixed demo rate" in failure for failure in failures), failures |
| 166 | + |
| 167 | + |
| 168 | +@pytest.mark.parametrize( |
| 169 | + "text", |
| 170 | + [ |
| 171 | + "SDK version 1.12.4 supports Python 3.8.", |
| 172 | + "Run 50 tests daily.", |
| 173 | + "The response contains 50 records per page.", |
| 174 | + "Retry attempt 50 failed.", |
| 175 | + ], |
| 176 | +) |
| 177 | +def test_fixed_rate_aliases_do_not_match_versions_or_test_counts( |
| 178 | + tmp_path: Path, text: str |
| 179 | +) -> None: |
| 180 | + assert _installed_text_failures(tmp_path, text) == [] |
0 commit comments