catastrogps 2.1.0__tar.gz → 2.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {catastrogps-2.1.0 → catastrogps-2.2.0}/CHANGELOG.md +6 -0
- {catastrogps-2.1.0 → catastrogps-2.2.0}/PKG-INFO +10 -3
- {catastrogps-2.1.0 → catastrogps-2.2.0}/README.md +9 -2
- catastrogps-2.2.0/catastrogps/_version.py +1 -0
- {catastrogps-2.1.0 → catastrogps-2.2.0}/catastrogps/parcels.py +18 -0
- catastrogps-2.2.0/tests/test_sigpac.py +221 -0
- catastrogps-2.1.0/catastrogps/_version.py +0 -1
- {catastrogps-2.1.0 → catastrogps-2.2.0}/.gitignore +0 -0
- {catastrogps-2.1.0 → catastrogps-2.2.0}/LICENSE +0 -0
- {catastrogps-2.1.0 → catastrogps-2.2.0}/catastrogps/__init__.py +0 -0
- {catastrogps-2.1.0 → catastrogps-2.2.0}/catastrogps/client.py +0 -0
- {catastrogps-2.1.0 → catastrogps-2.2.0}/catastrogps/errors.py +0 -0
- {catastrogps-2.1.0 → catastrogps-2.2.0}/catastrogps/export.py +0 -0
- {catastrogps-2.1.0 → catastrogps-2.2.0}/catastrogps/fincas.py +0 -0
- {catastrogps-2.1.0 → catastrogps-2.2.0}/catastrogps/locations.py +0 -0
- {catastrogps-2.1.0 → catastrogps-2.2.0}/catastrogps/py.typed +0 -0
- {catastrogps-2.1.0 → catastrogps-2.2.0}/pyproject.toml +0 -0
- {catastrogps-2.1.0 → catastrogps-2.2.0}/tests/__init__.py +0 -0
- {catastrogps-2.1.0 → catastrogps-2.2.0}/tests/test_analysis.py +0 -0
- {catastrogps-2.1.0 → catastrogps-2.2.0}/tests/test_client.py +0 -0
- {catastrogps-2.1.0 → catastrogps-2.2.0}/tests/test_fincas.py +0 -0
- {catastrogps-2.1.0 → catastrogps-2.2.0}/tests/test_subparcels_and_locations.py +0 -0
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.2.0 (2026-10-23)
|
|
4
|
+
|
|
5
|
+
- `parcels.sigpac(ref, country=, lang=)`: `GET /v1/parcels/{ref}/sigpac`, every SIGPAC enclosure of a Spanish parcel (ES, PV, NA) with land use, irrigation, slope, altitude, CAP eligibility and region, incidents and outline. 1 unit, 0 when empty; `SIG_001` raises `ServiceUnavailableError`, retried and not charged.
|
|
6
|
+
- `parcels.sigpac_geojson(ref, country=, lang=)`: the same with `format=geojson`, parsed into a GeoJSON FeatureCollection dict.
|
|
7
|
+
- README: subparcels coverage lists every country the API answers (adds DE, CZ, NL, FR, PT, SE, CH, FI, BE, IE, SI).
|
|
8
|
+
|
|
3
9
|
## 2.1.0 (2026-10-21)
|
|
4
10
|
|
|
5
11
|
- `parcels.subparcels(ref, country=, lang=)`: `GET /v1/parcels/{ref}/subparcels`, crops and land use of each part of the parcel (`cropCode`, `crop`, `cropOriginal`, `intensity`, `area`, `landType`, `landClass`, `kind`, `useClass`, `useClassName`, `source`, `geometry`). Paid (1 unit, 0 when empty); a source failure raises `ServiceUnavailableError` with code `SUB_001` and is not charged.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: catastrogps
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.2.0
|
|
4
4
|
Summary: Official Python client for the Catastro GPS API: parcels from 29 European countries (including the Basque Country and Navarre foral cadastres) by reference, coordinates or address; building units, terrain, ground motion, solar and more
|
|
5
5
|
Project-URL: Homepage, https://www.parcelgps.com/developers
|
|
6
6
|
Project-URL: Documentation, https://www.parcelgps.com/developers
|
|
@@ -75,7 +75,9 @@ with CatastroGPS() as client:
|
|
|
75
75
|
| Method | Endpoint | Countries |
|
|
76
76
|
|--------|----------|-----------|
|
|
77
77
|
| `parcels.get(ref, country=, lang=)` | `GET /v1/parcels/{ref}` | All references (see coverage). Carries `subparcelCount` and `cropSummary` |
|
|
78
|
-
| `parcels.subparcels(ref, country=, lang=)` | `GET /v1/parcels/{ref}/subparcels` | ES (with PV/NA), AT, EE, GR. 1 unit; 0 when the parcel has none |
|
|
78
|
+
| `parcels.subparcels(ref, country=, lang=)` | `GET /v1/parcels/{ref}/subparcels` | ES (with PV/NA), AT, DE, CZ, NL, FR, PT, SE, CH, FI, BE, IE, SI, EE, GR. 1 unit; 0 when the parcel has none |
|
|
79
|
+
| `parcels.sigpac(ref, country=, lang=)` | `GET /v1/parcels/{ref}/sigpac` | ES, PV, NA. SIGPAC enclosures with land use, irrigation, slope, CAP eligibility, incidents and outline. 1 unit; 0 when there are none; `SIG_001` is not charged |
|
|
80
|
+
| `parcels.sigpac_geojson(ref, country=, lang=)` | `GET /v1/parcels/{ref}/sigpac?format=geojson` | The same as a GeoJSON FeatureCollection (dict) |
|
|
79
81
|
| `parcels.neighbors(ref, country=)` | `GET /v1/parcels/{ref}/neighbors` | Spain, and countries where we hold a copy; `supported: false` (free) elsewhere |
|
|
80
82
|
| `parcels.at_point(lat, lng, country=)` | `GET /v1/search/coordinates` | All, including HR, SE and UK (Scotland) |
|
|
81
83
|
| `search_address_candidates(q, street=, number=, municipality=, postcode=, country=, limit=)` | `GET /v1/search/address/candidates` | Spain (with Basque Country and Navarre) and 26 more; not SE or HR |
|
|
@@ -121,6 +123,11 @@ crops = client.parcels.subparcels("46063A00100121", lang="en")
|
|
|
121
123
|
for row in crops["subparcels"]:
|
|
122
124
|
print(row["cropCode"], row.get("crop"), row.get("cropOriginal"), row["area"], row.get("useClass"))
|
|
123
125
|
|
|
126
|
+
sigpac = client.parcels.sigpac("46063A00100121", lang="en")
|
|
127
|
+
for enclosure in sigpac["enclosures"]:
|
|
128
|
+
print(enclosure["id"], enclosure["landUseCode"], enclosure.get("landUse"), enclosure["areaHa"], enclosure["irrigationPct"])
|
|
129
|
+
collection = client.parcels.sigpac_geojson("46063A00100121")
|
|
130
|
+
|
|
124
131
|
catalog = client.crop_catalog(lang="en")
|
|
125
132
|
names = {crop["code"]: crop["name"] for crop in catalog["crops"]}
|
|
126
133
|
|
|
@@ -210,7 +217,7 @@ except QuotaExceededError as error:
|
|
|
210
217
|
| `NotFoundError` | `404 NOT_FOUND` |
|
|
211
218
|
| `QuotaExceededError` | `429 KEY_AUTH_004` |
|
|
212
219
|
| `RateLimitError` | `429 KEY_RATE_002`, `RATE_LIMIT_EXCEEDED`; `retry_after` |
|
|
213
|
-
| `ServiceUnavailableError` | `503 SERVICE_UNAVAILABLE`, `SUB_001` (subparcels source down, not charged); `retry_after` |
|
|
220
|
+
| `ServiceUnavailableError` | `503 SERVICE_UNAVAILABLE`, `SUB_001` / `SIG_001` (subparcels or SIGPAC source down, not charged); `retry_after` |
|
|
214
221
|
| `ServerError`, `TimeoutError`, `NetworkError` | `5xx`, client timeout, network failure |
|
|
215
222
|
|
|
216
223
|
Timeouts, network errors, per-minute 429s and 502/503/504 are retried up to `max_retries` times (default 2) with exponential backoff, waiting `Retry-After` when the API sends it (up to 60 s). An exhausted monthly quota is never retried.
|
|
@@ -44,7 +44,9 @@ with CatastroGPS() as client:
|
|
|
44
44
|
| Method | Endpoint | Countries |
|
|
45
45
|
|--------|----------|-----------|
|
|
46
46
|
| `parcels.get(ref, country=, lang=)` | `GET /v1/parcels/{ref}` | All references (see coverage). Carries `subparcelCount` and `cropSummary` |
|
|
47
|
-
| `parcels.subparcels(ref, country=, lang=)` | `GET /v1/parcels/{ref}/subparcels` | ES (with PV/NA), AT, EE, GR. 1 unit; 0 when the parcel has none |
|
|
47
|
+
| `parcels.subparcels(ref, country=, lang=)` | `GET /v1/parcels/{ref}/subparcels` | ES (with PV/NA), AT, DE, CZ, NL, FR, PT, SE, CH, FI, BE, IE, SI, EE, GR. 1 unit; 0 when the parcel has none |
|
|
48
|
+
| `parcels.sigpac(ref, country=, lang=)` | `GET /v1/parcels/{ref}/sigpac` | ES, PV, NA. SIGPAC enclosures with land use, irrigation, slope, CAP eligibility, incidents and outline. 1 unit; 0 when there are none; `SIG_001` is not charged |
|
|
49
|
+
| `parcels.sigpac_geojson(ref, country=, lang=)` | `GET /v1/parcels/{ref}/sigpac?format=geojson` | The same as a GeoJSON FeatureCollection (dict) |
|
|
48
50
|
| `parcels.neighbors(ref, country=)` | `GET /v1/parcels/{ref}/neighbors` | Spain, and countries where we hold a copy; `supported: false` (free) elsewhere |
|
|
49
51
|
| `parcels.at_point(lat, lng, country=)` | `GET /v1/search/coordinates` | All, including HR, SE and UK (Scotland) |
|
|
50
52
|
| `search_address_candidates(q, street=, number=, municipality=, postcode=, country=, limit=)` | `GET /v1/search/address/candidates` | Spain (with Basque Country and Navarre) and 26 more; not SE or HR |
|
|
@@ -90,6 +92,11 @@ crops = client.parcels.subparcels("46063A00100121", lang="en")
|
|
|
90
92
|
for row in crops["subparcels"]:
|
|
91
93
|
print(row["cropCode"], row.get("crop"), row.get("cropOriginal"), row["area"], row.get("useClass"))
|
|
92
94
|
|
|
95
|
+
sigpac = client.parcels.sigpac("46063A00100121", lang="en")
|
|
96
|
+
for enclosure in sigpac["enclosures"]:
|
|
97
|
+
print(enclosure["id"], enclosure["landUseCode"], enclosure.get("landUse"), enclosure["areaHa"], enclosure["irrigationPct"])
|
|
98
|
+
collection = client.parcels.sigpac_geojson("46063A00100121")
|
|
99
|
+
|
|
93
100
|
catalog = client.crop_catalog(lang="en")
|
|
94
101
|
names = {crop["code"]: crop["name"] for crop in catalog["crops"]}
|
|
95
102
|
|
|
@@ -179,7 +186,7 @@ except QuotaExceededError as error:
|
|
|
179
186
|
| `NotFoundError` | `404 NOT_FOUND` |
|
|
180
187
|
| `QuotaExceededError` | `429 KEY_AUTH_004` |
|
|
181
188
|
| `RateLimitError` | `429 KEY_RATE_002`, `RATE_LIMIT_EXCEEDED`; `retry_after` |
|
|
182
|
-
| `ServiceUnavailableError` | `503 SERVICE_UNAVAILABLE`, `SUB_001` (subparcels source down, not charged); `retry_after` |
|
|
189
|
+
| `ServiceUnavailableError` | `503 SERVICE_UNAVAILABLE`, `SUB_001` / `SIG_001` (subparcels or SIGPAC source down, not charged); `retry_after` |
|
|
183
190
|
| `ServerError`, `TimeoutError`, `NetworkError` | `5xx`, client timeout, network failure |
|
|
184
191
|
|
|
185
192
|
Timeouts, network errors, per-minute 429s and 502/503/504 are retried up to `max_retries` times (default 2) with exponential backoff, waiting `Retry-After` when the API sends it (up to 60 s). An exhausted monthly quota is never retried.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "2.2.0"
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
import json
|
|
3
4
|
import math
|
|
4
5
|
from typing import TYPE_CHECKING, Any
|
|
5
6
|
from urllib.parse import quote
|
|
@@ -104,6 +105,23 @@ class ParcelsResource:
|
|
|
104
105
|
"GET", parcel_path(reference, "/subparcels"), query={"country": country, "lang": crop_language(lang)}
|
|
105
106
|
)
|
|
106
107
|
|
|
108
|
+
def sigpac(self, reference: str, *, country: str | None = None, lang: str | None = None) -> dict[str, Any]:
|
|
109
|
+
return self._client.request(
|
|
110
|
+
"GET", parcel_path(reference, "/sigpac"), query={"country": country, "lang": crop_language(lang)}
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
def sigpac_geojson(self, reference: str, *, country: str | None = None, lang: str | None = None) -> dict[str, Any]:
|
|
114
|
+
content = self._client.request(
|
|
115
|
+
"GET",
|
|
116
|
+
parcel_path(reference, "/sigpac"),
|
|
117
|
+
query={"country": country, "lang": crop_language(lang), "format": "geojson"},
|
|
118
|
+
raw=True,
|
|
119
|
+
)
|
|
120
|
+
try:
|
|
121
|
+
return json.loads(content)
|
|
122
|
+
except ValueError as error:
|
|
123
|
+
raise CatastroGPSError("SIGPAC GeoJSON response is not valid JSON") from error
|
|
124
|
+
|
|
107
125
|
def neighbors(self, reference: str, *, country: str | None = None) -> dict[str, Any]:
|
|
108
126
|
return self._client.request("GET", parcel_path(reference, "/neighbors"), query={"country": country})
|
|
109
127
|
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import json
|
|
2
|
+
|
|
3
|
+
import httpx
|
|
4
|
+
import pytest
|
|
5
|
+
|
|
6
|
+
import catastrogps.client as client_module
|
|
7
|
+
from catastrogps import (
|
|
8
|
+
AuthenticationError,
|
|
9
|
+
CatastroGPS,
|
|
10
|
+
CatastroGPSError,
|
|
11
|
+
CoverageError,
|
|
12
|
+
NotFoundError,
|
|
13
|
+
QuotaExceededError,
|
|
14
|
+
RateLimitError,
|
|
15
|
+
ServerError,
|
|
16
|
+
ServiceUnavailableError,
|
|
17
|
+
TimeoutError,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class Recorder:
|
|
22
|
+
def __init__(self, *responses):
|
|
23
|
+
self.responses = list(responses)
|
|
24
|
+
self.requests = []
|
|
25
|
+
|
|
26
|
+
def __call__(self, request: httpx.Request) -> httpx.Response:
|
|
27
|
+
self.requests.append(request)
|
|
28
|
+
response = self.responses.pop(0)
|
|
29
|
+
if isinstance(response, Exception):
|
|
30
|
+
raise response
|
|
31
|
+
return response
|
|
32
|
+
|
|
33
|
+
@property
|
|
34
|
+
def last(self) -> httpx.Request:
|
|
35
|
+
return self.requests[-1]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@pytest.fixture(autouse=True)
|
|
39
|
+
def no_sleep(monkeypatch):
|
|
40
|
+
monkeypatch.setattr(client_module.time, "sleep", lambda _seconds: None)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def make(*responses, max_retries=0):
|
|
44
|
+
recorder = Recorder(*responses)
|
|
45
|
+
http = httpx.Client(transport=httpx.MockTransport(recorder))
|
|
46
|
+
client = CatastroGPS(
|
|
47
|
+
"pk_test_000000000000", base_url="https://api.example.test", http_client=http, max_retries=max_retries
|
|
48
|
+
)
|
|
49
|
+
return client, recorder
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def ok(data, headers=None):
|
|
53
|
+
return httpx.Response(200, json={"success": True, "data": data}, headers=headers)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def fail(status, code, message="error", headers=None, details=None):
|
|
57
|
+
body = {"success": False, "code": code, "message": message}
|
|
58
|
+
if details is not None:
|
|
59
|
+
body["details"] = details
|
|
60
|
+
return httpx.Response(status, json=body, headers=headers)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
SIGPAC = {
|
|
64
|
+
"reference": "46063A00100121",
|
|
65
|
+
"country": "ES",
|
|
66
|
+
"sigpacParcel": {"province": 46, "municipality": 63, "aggregate": 0, "zone": 0, "polygon": 1, "parcel": 121},
|
|
67
|
+
"match": "reference",
|
|
68
|
+
"count": 2,
|
|
69
|
+
"totalAreaHa": 0.8815,
|
|
70
|
+
"crs": "EPSG:4258 (ETRS89, lon/lat; equal to WGS84 within about 1 m)",
|
|
71
|
+
"retrievedAt": "2026-10-22T13:47:26Z",
|
|
72
|
+
"source": {"name": "SIGPAC", "provider": "FEGA", "license": "Ley 37/2007", "attribution": "Fuente: FEGA — SIGPAC"},
|
|
73
|
+
"enclosures": [
|
|
74
|
+
{
|
|
75
|
+
"id": "46:63:0:0:1:121:2",
|
|
76
|
+
"enclosure": 2,
|
|
77
|
+
"landUseCode": "FY",
|
|
78
|
+
"landUse": "Fruit trees",
|
|
79
|
+
"cropCode": "SIGPAC:FY",
|
|
80
|
+
"useClass": "orchard",
|
|
81
|
+
"areaHa": 0.0513,
|
|
82
|
+
"irrigationPct": 0,
|
|
83
|
+
"meanSlopePct": 7.6,
|
|
84
|
+
"altitudeM": 117,
|
|
85
|
+
"pastureEligibilityPct": None,
|
|
86
|
+
"capRegion": 12,
|
|
87
|
+
"incidents": [{"code": 199, "description": "Recinto inactivo"}],
|
|
88
|
+
"geometry": {"type": "Polygon", "coordinates": []},
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"id": "46:63:0:0:1:121:9",
|
|
92
|
+
"enclosure": 9,
|
|
93
|
+
"landUseCode": "ZZ",
|
|
94
|
+
"areaHa": 0.0039,
|
|
95
|
+
"irrigationPct": None,
|
|
96
|
+
"meanSlopePct": None,
|
|
97
|
+
"altitudeM": None,
|
|
98
|
+
"pastureEligibilityPct": None,
|
|
99
|
+
"capRegion": None,
|
|
100
|
+
"incidents": [],
|
|
101
|
+
"geometry": None,
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
GEOJSON = {
|
|
107
|
+
"type": "FeatureCollection",
|
|
108
|
+
"reference": "46063A00100121",
|
|
109
|
+
"count": 1,
|
|
110
|
+
"features": [{"type": "Feature", "properties": {"landUseCode": "FY"}, "geometry": None}],
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def test_sigpac_sends_country_and_lang_and_returns_data():
|
|
115
|
+
client, rec = make(ok(SIGPAC, headers={"X-Quota-Remaining": "41"}))
|
|
116
|
+
out = client.parcels.sigpac(" 46063A00100121 ", country="ES", lang="EN")
|
|
117
|
+
assert rec.last.method == "GET"
|
|
118
|
+
assert rec.last.url.path == "/v1/parcels/46063A00100121/sigpac"
|
|
119
|
+
assert dict(rec.last.url.params) == {"country": "ES", "lang": "en"}
|
|
120
|
+
assert rec.last.headers["Accept"] == "application/json"
|
|
121
|
+
assert out["count"] == 2
|
|
122
|
+
assert out["sigpacParcel"]["parcel"] == 121
|
|
123
|
+
assert out["enclosures"][0]["incidents"][0]["code"] == 199
|
|
124
|
+
assert out["enclosures"][1]["irrigationPct"] is None
|
|
125
|
+
assert out["enclosures"][1]["geometry"] is None
|
|
126
|
+
assert client.last_quota["remaining"] == 41
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def test_sigpac_without_options_sends_no_query():
|
|
130
|
+
client, rec = make(ok(SIGPAC))
|
|
131
|
+
client.parcels.sigpac("46063A00100121")
|
|
132
|
+
assert dict(rec.last.url.params) == {}
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def test_sigpac_no_enclosures():
|
|
136
|
+
empty = {**SIGPAC, "sigpacParcel": None, "match": "point", "count": 0, "totalAreaHa": 0, "enclosures": []}
|
|
137
|
+
client, _ = make(ok(empty))
|
|
138
|
+
out = client.parcels.sigpac("9872023VH5797S0001WX")
|
|
139
|
+
assert out["sigpacParcel"] is None
|
|
140
|
+
assert out["enclosures"] == []
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
@pytest.mark.parametrize("call", ["sigpac", "sigpac_geojson"])
|
|
144
|
+
def test_sigpac_validates_before_request(call):
|
|
145
|
+
client, rec = make()
|
|
146
|
+
with pytest.raises(CatastroGPSError):
|
|
147
|
+
getattr(client.parcels, call)(" ")
|
|
148
|
+
with pytest.raises(CatastroGPSError):
|
|
149
|
+
getattr(client.parcels, call)("46063A00100121", lang="ja")
|
|
150
|
+
assert rec.requests == []
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def test_sigpac_geojson_parses_feature_collection():
|
|
154
|
+
response = httpx.Response(
|
|
155
|
+
200,
|
|
156
|
+
content=json.dumps(GEOJSON).encode(),
|
|
157
|
+
headers={
|
|
158
|
+
"Content-Type": "application/geo+json",
|
|
159
|
+
"Content-Disposition": 'attachment; filename="sigpac.geojson"',
|
|
160
|
+
"X-Quota-Remaining": "40",
|
|
161
|
+
},
|
|
162
|
+
)
|
|
163
|
+
client, rec = make(response)
|
|
164
|
+
out = client.parcels.sigpac_geojson("46063A00100121", country="NA", lang="de")
|
|
165
|
+
assert dict(rec.last.url.params) == {"country": "NA", "lang": "de", "format": "geojson"}
|
|
166
|
+
assert rec.last.headers["Accept"] == "*/*"
|
|
167
|
+
assert out == GEOJSON
|
|
168
|
+
assert client.last_quota["remaining"] == 40
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def test_sigpac_geojson_invalid_body():
|
|
172
|
+
client, _ = make(httpx.Response(200, content=b"<html>", headers={"Content-Type": "text/html"}))
|
|
173
|
+
with pytest.raises(CatastroGPSError, match="not valid JSON"):
|
|
174
|
+
client.parcels.sigpac_geojson("46063A00100121")
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
@pytest.mark.parametrize(
|
|
178
|
+
"status,code,error",
|
|
179
|
+
[
|
|
180
|
+
(401, "KEY_AUTH_002", AuthenticationError),
|
|
181
|
+
(404, "NOT_FOUND", NotFoundError),
|
|
182
|
+
(422, "CNV_COVERAGE", CoverageError),
|
|
183
|
+
(429, "KEY_AUTH_004", QuotaExceededError),
|
|
184
|
+
(429, "KEY_RATE_002", RateLimitError),
|
|
185
|
+
(500, "INTERNAL", ServerError),
|
|
186
|
+
(503, "SIG_001", ServiceUnavailableError),
|
|
187
|
+
],
|
|
188
|
+
)
|
|
189
|
+
@pytest.mark.parametrize("call", ["sigpac", "sigpac_geojson"])
|
|
190
|
+
def test_sigpac_errors(call, status, code, error):
|
|
191
|
+
details = {"feature": "sigpac", "supportedCountries": ["ES", "PV", "NA"]}
|
|
192
|
+
client, rec = make(fail(status, code, details=details, headers={"Retry-After": "3"}))
|
|
193
|
+
with pytest.raises(error) as caught:
|
|
194
|
+
getattr(client.parcels, call)("CH119192997709")
|
|
195
|
+
assert caught.value.code == code
|
|
196
|
+
assert caught.value.status == status
|
|
197
|
+
assert len(rec.requests) == 1
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def test_sigpac_down_is_retried_then_succeeds():
|
|
201
|
+
client, rec = make(
|
|
202
|
+
fail(503, "SIG_001", "The SIGPAC enclosures could not be read right now.", headers={"Retry-After": "2"}),
|
|
203
|
+
ok(SIGPAC),
|
|
204
|
+
max_retries=1,
|
|
205
|
+
)
|
|
206
|
+
assert client.parcels.sigpac("46063A00100121")["count"] == 2
|
|
207
|
+
assert len(rec.requests) == 2
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def test_sigpac_quota_exceeded_not_retried():
|
|
211
|
+
client, rec = make(fail(429, "KEY_AUTH_004"), max_retries=3)
|
|
212
|
+
with pytest.raises(QuotaExceededError):
|
|
213
|
+
client.parcels.sigpac("46063A00100121")
|
|
214
|
+
assert len(rec.requests) == 1
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def test_sigpac_timeout():
|
|
218
|
+
client, rec = make(httpx.ReadTimeout("slow"), httpx.ReadTimeout("slow"), max_retries=1)
|
|
219
|
+
with pytest.raises(TimeoutError):
|
|
220
|
+
client.parcels.sigpac("46063A00100121")
|
|
221
|
+
assert len(rec.requests) == 2
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "2.1.0"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|