catastrogps 1.3.2__tar.gz → 2.0.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-1.3.2 → catastrogps-2.0.0}/PKG-INFO +26 -26
- {catastrogps-1.3.2 → catastrogps-2.0.0}/README.md +25 -25
- catastrogps-2.0.0/catastrogps/_version.py +1 -0
- {catastrogps-1.3.2 → catastrogps-2.0.0}/catastrogps/client.py +2 -2
- {catastrogps-1.3.2 → catastrogps-2.0.0}/catastrogps/errors.py +2 -2
- {catastrogps-1.3.2 → catastrogps-2.0.0}/catastrogps/export.py +2 -2
- {catastrogps-1.3.2 → catastrogps-2.0.0}/catastrogps/fincas.py +12 -12
- {catastrogps-1.3.2 → catastrogps-2.0.0}/catastrogps/parcels.py +6 -9
- {catastrogps-1.3.2 → catastrogps-2.0.0}/tests/test_analysis.py +32 -32
- {catastrogps-1.3.2 → catastrogps-2.0.0}/tests/test_client.py +58 -23
- {catastrogps-1.3.2 → catastrogps-2.0.0}/tests/test_fincas.py +30 -30
- catastrogps-1.3.2/catastrogps/_version.py +0 -1
- {catastrogps-1.3.2 → catastrogps-2.0.0}/.gitignore +0 -0
- {catastrogps-1.3.2 → catastrogps-2.0.0}/LICENSE +0 -0
- {catastrogps-1.3.2 → catastrogps-2.0.0}/catastrogps/__init__.py +0 -0
- {catastrogps-1.3.2 → catastrogps-2.0.0}/catastrogps/py.typed +0 -0
- {catastrogps-1.3.2 → catastrogps-2.0.0}/pyproject.toml +0 -0
- {catastrogps-1.3.2 → catastrogps-2.0.0}/tests/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: catastrogps
|
|
3
|
-
Version:
|
|
3
|
+
Version: 2.0.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
|
|
@@ -58,7 +58,7 @@ from catastrogps import CatastroGPS
|
|
|
58
58
|
client = CatastroGPS("pk_live_your_key_here")
|
|
59
59
|
|
|
60
60
|
parcel = client.parcels.get("9872023VH5797S0001WX")
|
|
61
|
-
print(parcel["
|
|
61
|
+
print(parcel["municipality"], parcel.get("parcelArea"), parcel["latitude"], parcel["longitude"])
|
|
62
62
|
```
|
|
63
63
|
|
|
64
64
|
`CatastroGPS()` with no arguments reads `CATASTROGPS_API_KEY` from the environment. Use it as a context manager to close the connection pool:
|
|
@@ -72,20 +72,20 @@ with CatastroGPS() as client:
|
|
|
72
72
|
|
|
73
73
|
| Method | Endpoint | Countries |
|
|
74
74
|
|--------|----------|-----------|
|
|
75
|
-
| `parcels.get(ref, country=)` | `GET /
|
|
76
|
-
| `parcels.at_point(lat, lng, country=)` | `GET /
|
|
77
|
-
| `search_address_candidates(q, street=, number=, municipality=, postcode=, country=, limit=)` | `GET /
|
|
78
|
-
| `parcels.find_by_address(text)` | `POST /
|
|
79
|
-
| `get_units(ref14, country=, previous=)`, `iter_unit_pages` | `GET /
|
|
80
|
-
| `parcels.geometry(ref, country=)` | `GET /
|
|
81
|
-
| `parcels.terrain(ref, country=, lat=, lng=)` | `GET /
|
|
82
|
-
| `parcels.ground_motion(ref, country=, lat=, lng=)` | `GET /
|
|
83
|
-
| `parcels.solar`, `parcels.agriculture`, `parcels.score` | `/solar`, `/
|
|
75
|
+
| `parcels.get(ref, country=)` | `GET /v1/parcels/{ref}` | All references (see coverage) |
|
|
76
|
+
| `parcels.at_point(lat, lng, country=)` | `GET /v1/search/coordinates` | All, including HR, SE and UK (Scotland) |
|
|
77
|
+
| `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 |
|
|
78
|
+
| `parcels.find_by_address(text)` | `POST /v1/search/address/parse` | Spain, central Catastro, live (prefer the candidates search) |
|
|
79
|
+
| `get_units(ref14, country=, previous=)`, `iter_unit_pages` | `GET /v1/parcels/{ref14}/units` | `ES`, `PV`, `NA` |
|
|
80
|
+
| `parcels.geometry(ref, country=)` | `GET /v1/parcels/{ref}/polygon` | All but UK |
|
|
81
|
+
| `parcels.terrain(ref, country=, lat=, lng=)` | `GET /v1/parcels/{ref}/terrain` | All; `lat`/`lng` required outside ES, PV, NA, PT, FR, IT, DE |
|
|
82
|
+
| `parcels.ground_motion(ref, country=, lat=, lng=)` | `GET /v1/parcels/{ref}/ground-motion` | Same as terrain, inside EGMS coverage |
|
|
83
|
+
| `parcels.solar`, `parcels.agriculture`, `parcels.score` | `/solar`, `/agriculture`, `/score` | ES, PV, NA, PT, FR, IT, DE |
|
|
84
84
|
| `parcels.market(ref, country=)` | `/market` | Figures in FR, IT and DE (NRW); a note without figures elsewhere |
|
|
85
85
|
| `parcels.value_history(ref, country=)` | `/value-history` | ES, PV, NA, PT, FR, IT, DE, AT |
|
|
86
|
-
| `parcels.compare([(ref, country), ...])` | `POST /
|
|
87
|
-
| `export.file(ref, "kml" \| "gpx"
|
|
88
|
-
| `resolve(text, hint=)` | `GET /
|
|
86
|
+
| `parcels.compare([(ref, country), ...])` | `POST /v1/parcels/compare` | 2 or 3 parcels in ES, PT, FR, IT, DE |
|
|
87
|
+
| `export.file(ref, "kml" \| "gpx", country=)` | `GET /v1/export/{format}` | Where a geometry exists |
|
|
88
|
+
| `resolve(text, hint=)` | `GET /v1/resolve` | Free, no quota: which country and kind a text is |
|
|
89
89
|
|
|
90
90
|
## Examples
|
|
91
91
|
|
|
@@ -94,15 +94,15 @@ in_warsaw = client.parcels.at_point(52.2297, 21.0122)
|
|
|
94
94
|
in_warsaw["referenciaCatastral"], in_warsaw.get("pais")
|
|
95
95
|
|
|
96
96
|
found = client.search_address_candidates("Damrak 1, 1012 LG Amsterdam", country="NL")
|
|
97
|
-
found["
|
|
97
|
+
found["candidates"][0]["reference"], found["candidates"][0]["confidence"]
|
|
98
98
|
|
|
99
99
|
terrain = client.parcels.terrain("10194A00110004")
|
|
100
|
-
terrain["relief"]["slope"]["class"], terrain["
|
|
100
|
+
terrain["relief"]["slope"]["class"], terrain["protectedAreas"]["natura2000"], terrain.get("climate")
|
|
101
101
|
|
|
102
102
|
brussels = client.parcels.terrain("21004C0123/00", country="BE", lat=50.848139, lng=4.353613)
|
|
103
103
|
|
|
104
104
|
motion = client.parcels.ground_motion("0745901TG4304N0002KH")
|
|
105
|
-
motion["status"], motion.get("
|
|
105
|
+
motion["status"], motion.get("groundMotion", {}).get("vertical", {}).get("meanMmYear")
|
|
106
106
|
|
|
107
107
|
comparison = client.parcels.compare([("9872023VH5797S0001WX", "ES"), ("750560000AB0001", "FR")])
|
|
108
108
|
|
|
@@ -114,7 +114,7 @@ guess["candidates"]
|
|
|
114
114
|
|
|
115
115
|
`terrain` and `ground_motion` carry a `source.attribution` string that must be shown next to the data. A ground motion answer with `status: "no_data"` and `reason: "no_reflectors"` means the satellite had nothing stable to measure (fields, forest, water): there is no figure, not a zero.
|
|
116
116
|
|
|
117
|
-
Responses are the
|
|
117
|
+
Responses are the `data` object of the English v1 API (`https://api.parcelgps.com/v1`) as a `dict`: `reference`, `municipality`, `parcelArea`, `latitude`, `longitude`… Values that come from an official source (land use, addresses) stay in its language. See the [API reference](https://www.parcelgps.com/en/api/docs) and the OpenAPI spec at `https://api.parcelgps.com/v1/openapi.json`. Version 2 of this SDK talks only to `/v1`; 1.x used the deprecated Spanish-named `/api` routes.
|
|
118
118
|
|
|
119
119
|
## Import a building (comunidad de propietarios, Spain)
|
|
120
120
|
|
|
@@ -122,21 +122,21 @@ Address, then finca (14-character reference), then every unit with use, area, pa
|
|
|
122
122
|
|
|
123
123
|
```python
|
|
124
124
|
found = client.search_address_candidates("Avenida José Rodríguez de la Borbolla Camoyán 10, Dos Hermanas")
|
|
125
|
-
finca = found["
|
|
125
|
+
finca = found["candidates"][0]
|
|
126
126
|
|
|
127
|
-
comunidad = client.get_units(finca["
|
|
128
|
-
comunidad["
|
|
129
|
-
for u in comunidad["
|
|
130
|
-
print(u["
|
|
127
|
+
comunidad = client.get_units(finca["reference"], country=finca["country"])
|
|
128
|
+
comunidad["propertyUnitCount"]
|
|
129
|
+
for u in comunidad["units"]:
|
|
130
|
+
print(u["reference"], u["use"], u["area"], u.get("ownershipShare"), u["staircase"], u["floor"], u["door"])
|
|
131
131
|
comunidad["dataSource"], comunidad["attribution"]
|
|
132
132
|
|
|
133
|
-
refreshed = client.get_units(finca["
|
|
133
|
+
refreshed = client.get_units(finca["reference"], previous=comunidad)
|
|
134
134
|
refreshed["changed"]
|
|
135
135
|
```
|
|
136
136
|
|
|
137
137
|
- `get_units` follows `nextCursor` for you (up to 200 units per page). `iter_unit_pages(ref)` yields page by page.
|
|
138
138
|
- **Cost: one quota unit per unit served** in each page, minimum one per page; a page is cut to the quota you have left. Pass the previous result as `previous=` to re-import: unchanged pages come back as `304 Not Modified`, cost nothing and are reused; `changed` tells you if anything moved.
|
|
139
|
-
- Basque Country and Navarre (`country="PV"` or `"NA"`) are served from our copy of each foral cadastre: pass the foral reference of any unit or the finca key
|
|
139
|
+
- Basque Country and Navarre (`country="PV"` or `"NA"`) are served from our copy of each foral cadastre: pass the foral reference of any unit or the finca key as the reference. The foral open data carry no participation coefficient.
|
|
140
140
|
- Organisations with a per-finca cap agreed by contract (Startup and Growth) pay at most that cap per finca and period: see `client.last_quota["finca_cap"]` (`{"cap", "used"}`), also in each page's `quota`.
|
|
141
141
|
|
|
142
142
|
## Quota, prepaid balance and limits
|
|
@@ -199,7 +199,7 @@ Timeouts, network errors, per-minute 429s and 502/503/504 are retried up to `max
|
|
|
199
199
|
| Argument | Default | |
|
|
200
200
|
|----------|---------|---|
|
|
201
201
|
| `api_key` | `CATASTROGPS_API_KEY` env var | Required |
|
|
202
|
-
| `base_url` | `https://api.
|
|
202
|
+
| `base_url` | `https://api.parcelgps.com` | Paths are under `/v1` |
|
|
203
203
|
| `timeout` | `30.0` seconds | Official cadastres can be slow |
|
|
204
204
|
| `max_retries` | `2` | |
|
|
205
205
|
| `http_client` | a new `httpx.Client` | Inject your own for proxies or tests (`httpx.MockTransport`) |
|
|
@@ -27,7 +27,7 @@ from catastrogps import CatastroGPS
|
|
|
27
27
|
client = CatastroGPS("pk_live_your_key_here")
|
|
28
28
|
|
|
29
29
|
parcel = client.parcels.get("9872023VH5797S0001WX")
|
|
30
|
-
print(parcel["
|
|
30
|
+
print(parcel["municipality"], parcel.get("parcelArea"), parcel["latitude"], parcel["longitude"])
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
`CatastroGPS()` with no arguments reads `CATASTROGPS_API_KEY` from the environment. Use it as a context manager to close the connection pool:
|
|
@@ -41,20 +41,20 @@ with CatastroGPS() as client:
|
|
|
41
41
|
|
|
42
42
|
| Method | Endpoint | Countries |
|
|
43
43
|
|--------|----------|-----------|
|
|
44
|
-
| `parcels.get(ref, country=)` | `GET /
|
|
45
|
-
| `parcels.at_point(lat, lng, country=)` | `GET /
|
|
46
|
-
| `search_address_candidates(q, street=, number=, municipality=, postcode=, country=, limit=)` | `GET /
|
|
47
|
-
| `parcels.find_by_address(text)` | `POST /
|
|
48
|
-
| `get_units(ref14, country=, previous=)`, `iter_unit_pages` | `GET /
|
|
49
|
-
| `parcels.geometry(ref, country=)` | `GET /
|
|
50
|
-
| `parcels.terrain(ref, country=, lat=, lng=)` | `GET /
|
|
51
|
-
| `parcels.ground_motion(ref, country=, lat=, lng=)` | `GET /
|
|
52
|
-
| `parcels.solar`, `parcels.agriculture`, `parcels.score` | `/solar`, `/
|
|
44
|
+
| `parcels.get(ref, country=)` | `GET /v1/parcels/{ref}` | All references (see coverage) |
|
|
45
|
+
| `parcels.at_point(lat, lng, country=)` | `GET /v1/search/coordinates` | All, including HR, SE and UK (Scotland) |
|
|
46
|
+
| `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 |
|
|
47
|
+
| `parcels.find_by_address(text)` | `POST /v1/search/address/parse` | Spain, central Catastro, live (prefer the candidates search) |
|
|
48
|
+
| `get_units(ref14, country=, previous=)`, `iter_unit_pages` | `GET /v1/parcels/{ref14}/units` | `ES`, `PV`, `NA` |
|
|
49
|
+
| `parcels.geometry(ref, country=)` | `GET /v1/parcels/{ref}/polygon` | All but UK |
|
|
50
|
+
| `parcels.terrain(ref, country=, lat=, lng=)` | `GET /v1/parcels/{ref}/terrain` | All; `lat`/`lng` required outside ES, PV, NA, PT, FR, IT, DE |
|
|
51
|
+
| `parcels.ground_motion(ref, country=, lat=, lng=)` | `GET /v1/parcels/{ref}/ground-motion` | Same as terrain, inside EGMS coverage |
|
|
52
|
+
| `parcels.solar`, `parcels.agriculture`, `parcels.score` | `/solar`, `/agriculture`, `/score` | ES, PV, NA, PT, FR, IT, DE |
|
|
53
53
|
| `parcels.market(ref, country=)` | `/market` | Figures in FR, IT and DE (NRW); a note without figures elsewhere |
|
|
54
54
|
| `parcels.value_history(ref, country=)` | `/value-history` | ES, PV, NA, PT, FR, IT, DE, AT |
|
|
55
|
-
| `parcels.compare([(ref, country), ...])` | `POST /
|
|
56
|
-
| `export.file(ref, "kml" \| "gpx"
|
|
57
|
-
| `resolve(text, hint=)` | `GET /
|
|
55
|
+
| `parcels.compare([(ref, country), ...])` | `POST /v1/parcels/compare` | 2 or 3 parcels in ES, PT, FR, IT, DE |
|
|
56
|
+
| `export.file(ref, "kml" \| "gpx", country=)` | `GET /v1/export/{format}` | Where a geometry exists |
|
|
57
|
+
| `resolve(text, hint=)` | `GET /v1/resolve` | Free, no quota: which country and kind a text is |
|
|
58
58
|
|
|
59
59
|
## Examples
|
|
60
60
|
|
|
@@ -63,15 +63,15 @@ in_warsaw = client.parcels.at_point(52.2297, 21.0122)
|
|
|
63
63
|
in_warsaw["referenciaCatastral"], in_warsaw.get("pais")
|
|
64
64
|
|
|
65
65
|
found = client.search_address_candidates("Damrak 1, 1012 LG Amsterdam", country="NL")
|
|
66
|
-
found["
|
|
66
|
+
found["candidates"][0]["reference"], found["candidates"][0]["confidence"]
|
|
67
67
|
|
|
68
68
|
terrain = client.parcels.terrain("10194A00110004")
|
|
69
|
-
terrain["relief"]["slope"]["class"], terrain["
|
|
69
|
+
terrain["relief"]["slope"]["class"], terrain["protectedAreas"]["natura2000"], terrain.get("climate")
|
|
70
70
|
|
|
71
71
|
brussels = client.parcels.terrain("21004C0123/00", country="BE", lat=50.848139, lng=4.353613)
|
|
72
72
|
|
|
73
73
|
motion = client.parcels.ground_motion("0745901TG4304N0002KH")
|
|
74
|
-
motion["status"], motion.get("
|
|
74
|
+
motion["status"], motion.get("groundMotion", {}).get("vertical", {}).get("meanMmYear")
|
|
75
75
|
|
|
76
76
|
comparison = client.parcels.compare([("9872023VH5797S0001WX", "ES"), ("750560000AB0001", "FR")])
|
|
77
77
|
|
|
@@ -83,7 +83,7 @@ guess["candidates"]
|
|
|
83
83
|
|
|
84
84
|
`terrain` and `ground_motion` carry a `source.attribution` string that must be shown next to the data. A ground motion answer with `status: "no_data"` and `reason: "no_reflectors"` means the satellite had nothing stable to measure (fields, forest, water): there is no figure, not a zero.
|
|
85
85
|
|
|
86
|
-
Responses are the
|
|
86
|
+
Responses are the `data` object of the English v1 API (`https://api.parcelgps.com/v1`) as a `dict`: `reference`, `municipality`, `parcelArea`, `latitude`, `longitude`… Values that come from an official source (land use, addresses) stay in its language. See the [API reference](https://www.parcelgps.com/en/api/docs) and the OpenAPI spec at `https://api.parcelgps.com/v1/openapi.json`. Version 2 of this SDK talks only to `/v1`; 1.x used the deprecated Spanish-named `/api` routes.
|
|
87
87
|
|
|
88
88
|
## Import a building (comunidad de propietarios, Spain)
|
|
89
89
|
|
|
@@ -91,21 +91,21 @@ Address, then finca (14-character reference), then every unit with use, area, pa
|
|
|
91
91
|
|
|
92
92
|
```python
|
|
93
93
|
found = client.search_address_candidates("Avenida José Rodríguez de la Borbolla Camoyán 10, Dos Hermanas")
|
|
94
|
-
finca = found["
|
|
94
|
+
finca = found["candidates"][0]
|
|
95
95
|
|
|
96
|
-
comunidad = client.get_units(finca["
|
|
97
|
-
comunidad["
|
|
98
|
-
for u in comunidad["
|
|
99
|
-
print(u["
|
|
96
|
+
comunidad = client.get_units(finca["reference"], country=finca["country"])
|
|
97
|
+
comunidad["propertyUnitCount"]
|
|
98
|
+
for u in comunidad["units"]:
|
|
99
|
+
print(u["reference"], u["use"], u["area"], u.get("ownershipShare"), u["staircase"], u["floor"], u["door"])
|
|
100
100
|
comunidad["dataSource"], comunidad["attribution"]
|
|
101
101
|
|
|
102
|
-
refreshed = client.get_units(finca["
|
|
102
|
+
refreshed = client.get_units(finca["reference"], previous=comunidad)
|
|
103
103
|
refreshed["changed"]
|
|
104
104
|
```
|
|
105
105
|
|
|
106
106
|
- `get_units` follows `nextCursor` for you (up to 200 units per page). `iter_unit_pages(ref)` yields page by page.
|
|
107
107
|
- **Cost: one quota unit per unit served** in each page, minimum one per page; a page is cut to the quota you have left. Pass the previous result as `previous=` to re-import: unchanged pages come back as `304 Not Modified`, cost nothing and are reused; `changed` tells you if anything moved.
|
|
108
|
-
- Basque Country and Navarre (`country="PV"` or `"NA"`) are served from our copy of each foral cadastre: pass the foral reference of any unit or the finca key
|
|
108
|
+
- Basque Country and Navarre (`country="PV"` or `"NA"`) are served from our copy of each foral cadastre: pass the foral reference of any unit or the finca key as the reference. The foral open data carry no participation coefficient.
|
|
109
109
|
- Organisations with a per-finca cap agreed by contract (Startup and Growth) pay at most that cap per finca and period: see `client.last_quota["finca_cap"]` (`{"cap", "used"}`), also in each page's `quota`.
|
|
110
110
|
|
|
111
111
|
## Quota, prepaid balance and limits
|
|
@@ -168,7 +168,7 @@ Timeouts, network errors, per-minute 429s and 502/503/504 are retried up to `max
|
|
|
168
168
|
| Argument | Default | |
|
|
169
169
|
|----------|---------|---|
|
|
170
170
|
| `api_key` | `CATASTROGPS_API_KEY` env var | Required |
|
|
171
|
-
| `base_url` | `https://api.
|
|
171
|
+
| `base_url` | `https://api.parcelgps.com` | Paths are under `/v1` |
|
|
172
172
|
| `timeout` | `30.0` seconds | Official cadastres can be slow |
|
|
173
173
|
| `max_retries` | `2` | |
|
|
174
174
|
| `http_client` | a new `httpx.Client` | Inject your own for proxies or tests (`httpx.MockTransport`) |
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "2.0.0"
|
|
@@ -22,7 +22,7 @@ from catastrogps.export import ExportResource
|
|
|
22
22
|
from catastrogps.fincas import FincasResource
|
|
23
23
|
from catastrogps.parcels import ParcelsResource
|
|
24
24
|
|
|
25
|
-
DEFAULT_BASE_URL = "https://api.
|
|
25
|
+
DEFAULT_BASE_URL = "https://api.parcelgps.com"
|
|
26
26
|
DEFAULT_TIMEOUT = 30.0
|
|
27
27
|
DEFAULT_MAX_RETRIES = 2
|
|
28
28
|
BACKOFF_BASE_SECONDS = 0.5
|
|
@@ -94,7 +94,7 @@ class CatastroGPS:
|
|
|
94
94
|
return self.fincas.pages(refcat14, country=country, previous=previous)
|
|
95
95
|
|
|
96
96
|
def resolve(self, text: str, *, hint: str | None = None) -> dict[str, Any]:
|
|
97
|
-
return self.request("GET", "/
|
|
97
|
+
return self.request("GET", "/v1/resolve", query={"q": text, "hint": hint})
|
|
98
98
|
|
|
99
99
|
def request(
|
|
100
100
|
self,
|
|
@@ -113,8 +113,8 @@ def error_from_response(
|
|
|
113
113
|
quota: dict[str, Any] | None = None,
|
|
114
114
|
) -> CatastroGPSError:
|
|
115
115
|
code = body.get("code") if isinstance(body.get("code"), str) else None
|
|
116
|
-
message = body.get("
|
|
117
|
-
details = body.get("
|
|
116
|
+
message = body.get("message") or body.get("error") or f"HTTP {status}"
|
|
117
|
+
details = body.get("details", body.get("data"))
|
|
118
118
|
kwargs: dict[str, Any] = {"status": status, "code": code, "details": details, "body": body}
|
|
119
119
|
|
|
120
120
|
if code == "CNV_AMBIGUOUS" or status == 300:
|
|
@@ -7,7 +7,7 @@ from catastrogps.errors import CatastroGPSError
|
|
|
7
7
|
if TYPE_CHECKING:
|
|
8
8
|
from catastrogps.client import CatastroGPS
|
|
9
9
|
|
|
10
|
-
EXPORT_FORMATS = ("kml", "gpx"
|
|
10
|
+
EXPORT_FORMATS = ("kml", "gpx")
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
class ExportResource:
|
|
@@ -21,5 +21,5 @@ class ExportResource:
|
|
|
21
21
|
if not cleaned:
|
|
22
22
|
raise CatastroGPSError("reference must not be empty")
|
|
23
23
|
return self._client.request(
|
|
24
|
-
"GET", f"/
|
|
24
|
+
"GET", f"/v1/export/{format}", query={"reference": cleaned, "country": country}, raw=True
|
|
25
25
|
)
|
|
@@ -10,7 +10,7 @@ if TYPE_CHECKING:
|
|
|
10
10
|
from catastrogps.client import CatastroGPS
|
|
11
11
|
|
|
12
12
|
MAX_PAGES = 1000
|
|
13
|
-
ADDRESS_CANDIDATES_PATH = "/
|
|
13
|
+
ADDRESS_CANDIDATES_PATH = "/v1/search/address/candidates"
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
class FincasResource:
|
|
@@ -81,7 +81,7 @@ class FincasResource:
|
|
|
81
81
|
pages = list(self.pages(refcat14, country=country, previous=previous))
|
|
82
82
|
first = pages[0]["data"]
|
|
83
83
|
last = pages[-1]["data"]
|
|
84
|
-
units = [unit for page in pages for unit in page["data"].get("
|
|
84
|
+
units = [unit for page in pages for unit in page["data"].get("units") or []]
|
|
85
85
|
previous_pages = (previous or {}).get("pages")
|
|
86
86
|
unchanged = (
|
|
87
87
|
previous_pages is not None
|
|
@@ -89,16 +89,16 @@ class FincasResource:
|
|
|
89
89
|
and all(page["not_modified"] for page in pages)
|
|
90
90
|
)
|
|
91
91
|
return {
|
|
92
|
-
"
|
|
93
|
-
"
|
|
94
|
-
"
|
|
95
|
-
"
|
|
96
|
-
"
|
|
97
|
-
"
|
|
98
|
-
"
|
|
99
|
-
"
|
|
100
|
-
"
|
|
101
|
-
"
|
|
92
|
+
"reference": first.get("reference"),
|
|
93
|
+
"address": first.get("address"),
|
|
94
|
+
"postalCode": first.get("postalCode"),
|
|
95
|
+
"municipality": first.get("municipality"),
|
|
96
|
+
"region": first.get("region"),
|
|
97
|
+
"mainUse": first.get("mainUse"),
|
|
98
|
+
"yearBuilt": first.get("yearBuilt"),
|
|
99
|
+
"propertyUnitCount": last.get("propertyUnitCount", len(units)),
|
|
100
|
+
"units": units,
|
|
101
|
+
"constructions": [c for page in pages for c in page["data"].get("constructions") or []],
|
|
102
102
|
"dataSource": first.get("dataSource"),
|
|
103
103
|
"dataDate": first.get("dataDate"),
|
|
104
104
|
"attribution": first.get("attribution"),
|
|
@@ -85,7 +85,7 @@ def parcel_path(reference: str, suffix: str = "") -> str:
|
|
|
85
85
|
cleaned = (reference or "").strip()
|
|
86
86
|
if not cleaned:
|
|
87
87
|
raise CatastroGPSError("reference must not be empty")
|
|
88
|
-
return f"/
|
|
88
|
+
return f"/v1/parcels/{quote(cleaned, safe='')}{suffix}"
|
|
89
89
|
|
|
90
90
|
|
|
91
91
|
class ParcelsResource:
|
|
@@ -99,13 +99,13 @@ class ParcelsResource:
|
|
|
99
99
|
if not (_finite(lat) and _finite(lng)):
|
|
100
100
|
raise CatastroGPSError("lat and lng must be finite numbers")
|
|
101
101
|
return self._client.request(
|
|
102
|
-
"GET", "/
|
|
102
|
+
"GET", "/v1/search/coordinates", query={"lat": lat, "lng": lng, "country": country}
|
|
103
103
|
)
|
|
104
104
|
|
|
105
105
|
def find_by_address(self, address: str) -> dict[str, Any]:
|
|
106
106
|
if not (address or "").strip():
|
|
107
107
|
raise CatastroGPSError("address must not be empty")
|
|
108
|
-
return self._client.request("POST", "/
|
|
108
|
+
return self._client.request("POST", "/v1/search/address/parse", body={"address": address.strip()})
|
|
109
109
|
|
|
110
110
|
def geometry(self, reference: str, *, country: str | None = None) -> dict[str, Any]:
|
|
111
111
|
return self._client.request("GET", parcel_path(reference, "/polygon"), query={"country": country})
|
|
@@ -114,10 +114,7 @@ class ParcelsResource:
|
|
|
114
114
|
return self._client.request("GET", parcel_path(reference, "/solar"), query={"country": country})
|
|
115
115
|
|
|
116
116
|
def agriculture(self, reference: str, *, country: str | None = None) -> dict[str, Any]:
|
|
117
|
-
|
|
118
|
-
if isinstance(data, dict) and isinstance(data.get("agro"), dict):
|
|
119
|
-
return data["agro"]
|
|
120
|
-
return data
|
|
117
|
+
return self._client.request("GET", parcel_path(reference, "/agriculture"), query={"country": country})
|
|
121
118
|
|
|
122
119
|
def terrain(
|
|
123
120
|
self, reference: str, *, country: str | None = None, lat: float | None = None, lng: float | None = None
|
|
@@ -144,7 +141,7 @@ class ParcelsResource:
|
|
|
144
141
|
items = [_compare_item(parcel) for parcel in parcels]
|
|
145
142
|
if not MIN_COMPARE <= len(items) <= MAX_COMPARE:
|
|
146
143
|
raise CatastroGPSError(f"compare takes {MIN_COMPARE} or {MAX_COMPARE} parcels")
|
|
147
|
-
return self._client.request("POST", "/
|
|
144
|
+
return self._client.request("POST", "/v1/parcels/compare", body={"parcels": items})
|
|
148
145
|
|
|
149
146
|
|
|
150
147
|
def _compare_item(parcel: tuple[str, str] | dict[str, str]) -> dict[str, str]:
|
|
@@ -157,7 +154,7 @@ def _compare_item(parcel: tuple[str, str] | dict[str, str]) -> dict[str, str]:
|
|
|
157
154
|
raise CatastroGPSError("reference must not be empty")
|
|
158
155
|
if country not in ENRICHMENT_COUNTRY_CODES:
|
|
159
156
|
raise CatastroGPSError(f"country must be one of {', '.join(ENRICHMENT_COUNTRY_CODES)}")
|
|
160
|
-
return {"
|
|
157
|
+
return {"reference": cleaned, "country": country}
|
|
161
158
|
|
|
162
159
|
|
|
163
160
|
def _located_query(country: str | None, lat: float | None, lng: float | None) -> dict[str, Any]:
|
|
@@ -49,11 +49,11 @@ def fail(status, body, headers=None):
|
|
|
49
49
|
|
|
50
50
|
|
|
51
51
|
TERRAIN = {
|
|
52
|
-
"
|
|
52
|
+
"reference": "10194A00110004",
|
|
53
53
|
"country": "ES",
|
|
54
|
-
"relief": {"status": "ok", "
|
|
55
|
-
"
|
|
56
|
-
"climate": {"status": "ok", "baseline": {"
|
|
54
|
+
"relief": {"status": "ok", "elevationM": {"mean": 365.8, "min": 212.3, "max": 506.6}},
|
|
55
|
+
"protectedAreas": {"status": "ok", "natura2000": [{"code": "ES0000014", "name": "Monfrague", "type": "SPA"}]},
|
|
56
|
+
"climate": {"status": "ok", "baseline": {"startYear": 1991, "endYear": 2020, "meanTempC": 16.1}},
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
|
|
@@ -61,7 +61,7 @@ def test_terrain_reads_relief_protected_areas_and_climate():
|
|
|
61
61
|
client, recorder = make(ok(TERRAIN))
|
|
62
62
|
terrain = client.parcels.terrain("10194A00110004")
|
|
63
63
|
assert terrain["climate"]["status"] == "ok"
|
|
64
|
-
assert recorder.requests[0].url.path == "/
|
|
64
|
+
assert recorder.requests[0].url.path == "/v1/parcels/10194A00110004/terrain"
|
|
65
65
|
assert recorder.requests[0].url.query == b""
|
|
66
66
|
|
|
67
67
|
|
|
@@ -69,7 +69,7 @@ def test_terrain_sends_the_point_outside_the_seven_countries():
|
|
|
69
69
|
client, recorder = make(ok(TERRAIN))
|
|
70
70
|
client.parcels.terrain("21004C0123/00", country="BE", lat=50.848139, lng=4.353613)
|
|
71
71
|
url = recorder.requests[0].url
|
|
72
|
-
assert url.raw_path.startswith(b"/
|
|
72
|
+
assert url.raw_path.startswith(b"/v1/parcels/21004C0123%2F00/terrain")
|
|
73
73
|
assert url.params["country"] == "BE"
|
|
74
74
|
assert url.params["lat"] == "50.848139"
|
|
75
75
|
assert url.params["lng"] == "4.353613"
|
|
@@ -88,11 +88,11 @@ def test_located_endpoints_validate_the_point(kwargs, message):
|
|
|
88
88
|
|
|
89
89
|
def test_ground_motion_reads_values_and_no_data():
|
|
90
90
|
client, recorder = make(
|
|
91
|
-
ok({"
|
|
92
|
-
ok({"
|
|
91
|
+
ok({"reference": "R", "country": "ES", "status": "ok", "groundMotion": {"vertical": {"meanMmYear": -0.4}}}),
|
|
92
|
+
ok({"reference": "X", "country": "FR", "status": "no_data", "reason": "no_reflectors"}),
|
|
93
93
|
)
|
|
94
|
-
assert client.parcels.ground_motion("R")["
|
|
95
|
-
assert recorder.requests[0].url.path == "/
|
|
94
|
+
assert client.parcels.ground_motion("R")["groundMotion"]["vertical"]["meanMmYear"] == -0.4
|
|
95
|
+
assert recorder.requests[0].url.path == "/v1/parcels/R/ground-motion"
|
|
96
96
|
assert client.parcels.ground_motion("X", country="FR")["reason"] == "no_reflectors"
|
|
97
97
|
assert recorder.requests[1].url.params["country"] == "FR"
|
|
98
98
|
|
|
@@ -103,20 +103,20 @@ def test_ground_motion_reads_values_and_no_data():
|
|
|
103
103
|
def test_analysis_endpoints(method, suffix):
|
|
104
104
|
client, recorder = make(ok({"disponible": True}))
|
|
105
105
|
assert getattr(client.parcels, method)("750560000AB0001", country="FR") == {"disponible": True}
|
|
106
|
-
assert recorder.requests[0].url.path == f"/
|
|
106
|
+
assert recorder.requests[0].url.path == f"/v1/parcels/750560000AB0001{suffix}"
|
|
107
107
|
assert recorder.requests[0].url.params["country"] == "FR"
|
|
108
108
|
|
|
109
109
|
|
|
110
110
|
def test_compare_accepts_tuples_and_dicts():
|
|
111
|
-
client, recorder = make(ok({"
|
|
111
|
+
client, recorder = make(ok({"parcels": []}))
|
|
112
112
|
client.parcels.compare([(" 9872023VH5797S0001WX ", "ES"), {"reference": "750560000AB0001", "country": "FR"}])
|
|
113
113
|
request = recorder.requests[0]
|
|
114
114
|
assert request.method == "POST"
|
|
115
|
-
assert request.url.path == "/
|
|
115
|
+
assert request.url.path == "/v1/parcels/compare"
|
|
116
116
|
assert json.loads(request.content) == {
|
|
117
|
-
"
|
|
118
|
-
{"
|
|
119
|
-
{"
|
|
117
|
+
"parcels": [
|
|
118
|
+
{"reference": "9872023VH5797S0001WX", "country": "ES"},
|
|
119
|
+
{"reference": "750560000AB0001", "country": "FR"},
|
|
120
120
|
]
|
|
121
121
|
}
|
|
122
122
|
|
|
@@ -138,7 +138,7 @@ def test_compare_validates_before_calling(parcels, message):
|
|
|
138
138
|
|
|
139
139
|
|
|
140
140
|
def test_address_candidates_take_a_country():
|
|
141
|
-
client, recorder = make(ok({"
|
|
141
|
+
client, recorder = make(ok({"query": {"text": "x"}, "candidates": [], "attribution": ""}))
|
|
142
142
|
client.search_address_candidates("Damrak 1, 1012 LG Amsterdam", country="NL", limit=3)
|
|
143
143
|
assert recorder.requests[0].url.params["country"] == "NL"
|
|
144
144
|
assert recorder.requests[0].url.params["limit"] == "3"
|
|
@@ -147,10 +147,10 @@ def test_address_candidates_take_a_country():
|
|
|
147
147
|
|
|
148
148
|
def test_units_take_the_foral_country_and_keep_the_finca_cap():
|
|
149
149
|
page = {
|
|
150
|
-
"
|
|
151
|
-
"
|
|
152
|
-
"
|
|
153
|
-
"
|
|
150
|
+
"reference": "020-3-657",
|
|
151
|
+
"unitCount": 1,
|
|
152
|
+
"propertyUnitCount": 1,
|
|
153
|
+
"units": [{"reference": "N0714723L"}],
|
|
154
154
|
"truncated": False,
|
|
155
155
|
"dataSource": "clone",
|
|
156
156
|
"dataDate": "2026-09-01",
|
|
@@ -191,11 +191,11 @@ def test_read_quota_ignores_malformed_numbers_and_overage_off():
|
|
|
191
191
|
def test_quota_exceeded_carries_the_quota_and_tells_an_empty_balance_apart():
|
|
192
192
|
with_overage = fail(
|
|
193
193
|
429,
|
|
194
|
-
{"code": "KEY_AUTH_004", "
|
|
194
|
+
{"code": "KEY_AUTH_004", "message": "Monthly quota used up and prepaid balance empty."},
|
|
195
195
|
headers={"X-Quota-Limit": "250", "X-Quota-Remaining": "0", "X-Quota-Overage": "on", "X-Quota-Balance": "0"},
|
|
196
196
|
)
|
|
197
197
|
without_overage = fail(
|
|
198
|
-
429, {"code": "KEY_AUTH_004", "
|
|
198
|
+
429, {"code": "KEY_AUTH_004", "message": "Monthly quota used up."}, headers={"X-Quota-Limit": "250"}
|
|
199
199
|
)
|
|
200
200
|
client, _ = make(with_overage, without_overage)
|
|
201
201
|
with pytest.raises(QuotaExceededError) as first:
|
|
@@ -208,7 +208,7 @@ def test_quota_exceeded_carries_the_quota_and_tells_an_empty_balance_apart():
|
|
|
208
208
|
|
|
209
209
|
|
|
210
210
|
def test_per_minute_limit_is_a_rate_limit_error_with_retry_after():
|
|
211
|
-
client, _ = make(fail(429, {"code": "KEY_RATE_002", "
|
|
211
|
+
client, _ = make(fail(429, {"code": "KEY_RATE_002", "message": "Too many"}, headers={"Retry-After": "7"}))
|
|
212
212
|
with pytest.raises(RateLimitError) as error:
|
|
213
213
|
client.parcels.get("R")
|
|
214
214
|
assert error.value.retry_after == 7
|
|
@@ -217,14 +217,14 @@ def test_per_minute_limit_is_a_rate_limit_error_with_retry_after():
|
|
|
217
217
|
def test_place_name_error_has_the_geocoded_location():
|
|
218
218
|
body = {
|
|
219
219
|
"code": "CNV_PLACE_NAME",
|
|
220
|
-
"
|
|
221
|
-
"
|
|
220
|
+
"message": "That looks like a place name",
|
|
221
|
+
"details": {"query": "Gemarkung Musterdorf 12", "location": {"latitude": 50.1, "longitude": 8.6}},
|
|
222
222
|
}
|
|
223
|
-
client, _ = make(fail(422, body), fail(422, {"code": "CNV_PLACE_NAME", "
|
|
223
|
+
client, _ = make(fail(422, body), fail(422, {"code": "CNV_PLACE_NAME", "message": "x"}))
|
|
224
224
|
with pytest.raises(PlaceNameError) as error:
|
|
225
225
|
client.parcels.get("Gemarkung Musterdorf 12")
|
|
226
226
|
assert isinstance(error.value, ValidationError)
|
|
227
|
-
assert error.value.location == {"
|
|
227
|
+
assert error.value.location == {"latitude": 50.1, "longitude": 8.6}
|
|
228
228
|
with pytest.raises(PlaceNameError) as bare:
|
|
229
229
|
client.parcels.get("x")
|
|
230
230
|
assert bare.value.location is None
|
|
@@ -233,10 +233,10 @@ def test_place_name_error_has_the_geocoded_location():
|
|
|
233
233
|
def test_coverage_error_exposes_country_feature_and_supported_countries():
|
|
234
234
|
body = {
|
|
235
235
|
"code": "CNV_COVERAGE",
|
|
236
|
-
"
|
|
237
|
-
"
|
|
236
|
+
"message": "Not available",
|
|
237
|
+
"details": {"country": "PL", "feature": "solar", "supportedCountries": ["ES", "DE"]},
|
|
238
238
|
}
|
|
239
|
-
client, _ = make(fail(422, body), fail(422, {"code": "CNV_COVERAGE", "
|
|
239
|
+
client, _ = make(fail(422, body), fail(422, {"code": "CNV_COVERAGE", "message": "x"}))
|
|
240
240
|
with pytest.raises(CoverageError) as error:
|
|
241
241
|
client.parcels.solar("R")
|
|
242
242
|
assert (error.value.country, error.value.feature, error.value.supported_countries) == ("PL", "solar", ["ES", "DE"])
|
|
@@ -247,7 +247,7 @@ def test_coverage_error_exposes_country_feature_and_supported_countries():
|
|
|
247
247
|
|
|
248
248
|
def test_not_modified_keeps_the_quota_of_that_response():
|
|
249
249
|
client, _ = make(httpx.Response(304, headers={"ETag": '"a"', "X-Quota-Remaining": "9"}))
|
|
250
|
-
result = client.conditional_request("GET", "/
|
|
250
|
+
result = client.conditional_request("GET", "/v1/search/address/candidates", if_none_match='"a"')
|
|
251
251
|
assert result["not_modified"] is True
|
|
252
252
|
assert result["quota"] == {"remaining": 9}
|
|
253
253
|
|
|
@@ -44,7 +44,7 @@ def ok(data, headers=None):
|
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
def fail(status, code=None, error="boom", **extra):
|
|
47
|
-
body = {"success": False, "
|
|
47
|
+
body = {"success": False, "message": error, **extra}
|
|
48
48
|
if code:
|
|
49
49
|
body["code"] = code
|
|
50
50
|
return httpx.Response(status, json=body)
|
|
@@ -89,10 +89,10 @@ def test_knows_31_country_and_region_codes():
|
|
|
89
89
|
|
|
90
90
|
|
|
91
91
|
def test_get_parcel_unwraps_data_and_sends_headers():
|
|
92
|
-
client, rec = make(ok({"
|
|
92
|
+
client, rec = make(ok({"reference": "9872023VH5797S0001WX", "latitude": 40.4}))
|
|
93
93
|
parcel = client.parcels.get("9872023VH5797S0001WX")
|
|
94
|
-
assert parcel["
|
|
95
|
-
assert rec.last.url.path == "/
|
|
94
|
+
assert parcel["reference"] == "9872023VH5797S0001WX"
|
|
95
|
+
assert rec.last.url.path == "/v1/parcels/9872023VH5797S0001WX"
|
|
96
96
|
assert "country" not in rec.last.url.params
|
|
97
97
|
assert rec.last.headers["X-API-Key"] == "pk_test_000000000000"
|
|
98
98
|
assert rec.last.headers["User-Agent"] == f"catastrogps-python/{__version__}"
|
|
@@ -101,15 +101,15 @@ def test_get_parcel_unwraps_data_and_sends_headers():
|
|
|
101
101
|
def test_get_parcel_passes_country_and_encodes_slashes():
|
|
102
102
|
client, rec = make(ok({}))
|
|
103
103
|
client.parcels.get("146510_8.0502.1/3", country="PL")
|
|
104
|
-
assert rec.last.url.raw_path.decode().startswith("/
|
|
104
|
+
assert rec.last.url.raw_path.decode().startswith("/v1/parcels/146510_8.0502.1%2F3")
|
|
105
105
|
assert rec.last.url.params["country"] == "PL"
|
|
106
106
|
|
|
107
107
|
|
|
108
108
|
def test_at_point_uses_the_get_endpoint():
|
|
109
|
-
client, rec = make(ok({"
|
|
110
|
-
assert client.parcels.at_point(52.2297, 21.0122)["
|
|
109
|
+
client, rec = make(ok({"reference": "R"}))
|
|
110
|
+
assert client.parcels.at_point(52.2297, 21.0122)["reference"] == "R"
|
|
111
111
|
assert rec.last.method == "GET"
|
|
112
|
-
assert rec.last.url.path == "/
|
|
112
|
+
assert rec.last.url.path == "/v1/search/coordinates"
|
|
113
113
|
assert rec.last.url.params["lat"] == "52.2297"
|
|
114
114
|
|
|
115
115
|
|
|
@@ -121,24 +121,25 @@ def test_at_point_rejects_bad_numbers_locally():
|
|
|
121
121
|
|
|
122
122
|
|
|
123
123
|
def test_find_by_address_posts_free_text():
|
|
124
|
-
client, rec = make(ok({"
|
|
124
|
+
client, rec = make(ok({"reference": "0485206DF3808E0016EZ"}))
|
|
125
125
|
match = client.parcels.find_by_address("Calle Mallorca 213, Barcelona")
|
|
126
|
-
assert match["
|
|
126
|
+
assert match["reference"] == "0485206DF3808E0016EZ"
|
|
127
127
|
assert rec.last.method == "POST"
|
|
128
|
-
assert rec.last.url.path == "/
|
|
129
|
-
assert json.loads(rec.last.content) == {"
|
|
128
|
+
assert rec.last.url.path == "/v1/search/address/parse"
|
|
129
|
+
assert json.loads(rec.last.content) == {"address": "Calle Mallorca 213, Barcelona"}
|
|
130
130
|
|
|
131
131
|
|
|
132
132
|
@pytest.mark.parametrize("method,suffix", [("geometry", "/polygon"), ("solar", "/solar")])
|
|
133
133
|
def test_enrichment_paths(method, suffix):
|
|
134
134
|
client, rec = make(ok({}))
|
|
135
135
|
getattr(client.parcels, method)("R", country="ES")
|
|
136
|
-
assert rec.last.url.path == f"/
|
|
136
|
+
assert rec.last.url.path == f"/v1/parcels/R{suffix}"
|
|
137
137
|
|
|
138
138
|
|
|
139
139
|
def test_agriculture_unwraps_agro():
|
|
140
|
-
client,
|
|
141
|
-
assert client.parcels.agriculture("R") == {"
|
|
140
|
+
client, rec = make(ok({"landUse": "TA", "mainCrop": "Cebada"}))
|
|
141
|
+
assert client.parcels.agriculture("R") == {"landUse": "TA", "mainCrop": "Cebada"}
|
|
142
|
+
assert rec.last.url.path == "/v1/parcels/R/agriculture"
|
|
142
143
|
|
|
143
144
|
|
|
144
145
|
def test_empty_reference_is_rejected():
|
|
@@ -160,8 +161,8 @@ def test_export_returns_bytes():
|
|
|
160
161
|
httpx.Response(200, content=b"<kml/>", headers={"Content-Type": "application/vnd.google-earth.kml+xml"})
|
|
161
162
|
)
|
|
162
163
|
assert client.export.file("R", "kml", country="FR") == b"<kml/>"
|
|
163
|
-
assert rec.last.url.path == "/
|
|
164
|
-
assert rec.last.url.params["
|
|
164
|
+
assert rec.last.url.path == "/v1/export/kml"
|
|
165
|
+
assert rec.last.url.params["reference"] == "R"
|
|
165
166
|
|
|
166
167
|
|
|
167
168
|
def test_export_rejects_unknown_formats():
|
|
@@ -191,11 +192,45 @@ def test_not_found_keeps_status_code_and_message():
|
|
|
191
192
|
assert (info.value.status, info.value.code, info.value.message) == (404, "NOT_FOUND", "Parcel not found.")
|
|
192
193
|
|
|
193
194
|
|
|
194
|
-
def
|
|
195
|
-
client,
|
|
195
|
+
def test_address_miss_reads_the_v1_error_body():
|
|
196
|
+
client, rec = make(fail(404, code="NOT_FOUND", error="No parcel was found for this reference or location."))
|
|
196
197
|
with pytest.raises(NotFoundError) as info:
|
|
197
198
|
client.parcels.find_by_address("Calle Mayor 1")
|
|
198
|
-
assert info.value.
|
|
199
|
+
assert info.value.message == "No parcel was found for this reference or location."
|
|
200
|
+
assert json.loads(rec.last.content) == {"address": "Calle Mayor 1"}
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def test_legacy_error_body_is_still_understood():
|
|
204
|
+
client, _ = make(httpx.Response(422, json={"success": False, "code": "CNV_COVERAGE", "error": "legacy", "data": {"country": "RO"}}))
|
|
205
|
+
with pytest.raises(CatastroGPSError) as info:
|
|
206
|
+
client.parcels.get("R")
|
|
207
|
+
assert info.value.message == "legacy"
|
|
208
|
+
assert info.value.details == {"country": "RO"}
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def test_every_call_uses_the_v1_api():
|
|
212
|
+
seen = []
|
|
213
|
+
|
|
214
|
+
def handler(request):
|
|
215
|
+
seen.append(request.url)
|
|
216
|
+
return httpx.Response(200, json={"success": True, "data": {}})
|
|
217
|
+
|
|
218
|
+
client = CatastroGPS("pk_test_000000000000", http_client=httpx.Client(transport=httpx.MockTransport(handler)), max_retries=0)
|
|
219
|
+
client.parcels.get("R")
|
|
220
|
+
client.parcels.at_point(1, 2)
|
|
221
|
+
client.parcels.find_by_address("Gran Via 1, Madrid")
|
|
222
|
+
client.parcels.geometry("R")
|
|
223
|
+
client.parcels.solar("R")
|
|
224
|
+
client.parcels.agriculture("R")
|
|
225
|
+
client.parcels.terrain("R")
|
|
226
|
+
client.parcels.ground_motion("R")
|
|
227
|
+
client.parcels.market("R")
|
|
228
|
+
client.parcels.score("R")
|
|
229
|
+
client.parcels.value_history("R")
|
|
230
|
+
client.parcels.compare([("A", "ES"), ("B", "ES")])
|
|
231
|
+
client.resolve("R")
|
|
232
|
+
assert all(url.host == "api.parcelgps.com" for url in seen)
|
|
233
|
+
assert all(url.path.startswith("/v1/") for url in seen)
|
|
199
234
|
|
|
200
235
|
|
|
201
236
|
def test_ambiguous_reference_lists_candidates():
|
|
@@ -220,8 +255,8 @@ def test_retries_a_cadastre_that_is_down_then_gives_up():
|
|
|
220
255
|
|
|
221
256
|
|
|
222
257
|
def test_recovers_after_a_network_error():
|
|
223
|
-
client, rec = make(httpx.ConnectError("refused"), ok({"
|
|
224
|
-
assert client.parcels.get("R")["
|
|
258
|
+
client, rec = make(httpx.ConnectError("refused"), ok({"reference": "R"}))
|
|
259
|
+
assert client.parcels.get("R")["reference"] == "R"
|
|
225
260
|
assert len(rec.requests) == 2
|
|
226
261
|
|
|
227
262
|
|
|
@@ -262,7 +297,7 @@ def test_records_the_monthly_quota_from_x_quota_headers_not_the_per_minute_limit
|
|
|
262
297
|
def test_records_the_exhausted_quota_of_a_429():
|
|
263
298
|
exhausted = httpx.Response(
|
|
264
299
|
429,
|
|
265
|
-
json={"success": False, "code": "KEY_AUTH_004", "
|
|
300
|
+
json={"success": False, "code": "KEY_AUTH_004", "message": "Cuota mensual agotada"},
|
|
266
301
|
headers={
|
|
267
302
|
"X-Quota-Limit": "250",
|
|
268
303
|
"X-Quota-Remaining": "0",
|
|
@@ -19,25 +19,25 @@ class Recorder:
|
|
|
19
19
|
|
|
20
20
|
def unit(n):
|
|
21
21
|
return {
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
22
|
+
"reference": f"{FINCA}{n:04d}KH",
|
|
23
|
+
"staircase": "",
|
|
24
|
+
"floor": "01",
|
|
25
|
+
"door": "B",
|
|
26
|
+
"use": "Residencial",
|
|
27
|
+
"area": 155,
|
|
28
|
+
"description": "x",
|
|
29
|
+
"ownershipShare": 0.279543,
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
|
|
33
33
|
def page(start, end, truncated, total=365, etag=None, **extra):
|
|
34
34
|
units = [unit(n) for n in range(start, end + 1)]
|
|
35
35
|
data = {
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
36
|
+
"reference": FINCA,
|
|
37
|
+
"municipality": "DOS HERMANAS",
|
|
38
|
+
"unitCount": len(units),
|
|
39
|
+
"propertyUnitCount": total,
|
|
40
|
+
"units": units,
|
|
41
41
|
"truncated": truncated,
|
|
42
42
|
"dataSource": "clone",
|
|
43
43
|
"dataDate": "2026-08-19",
|
|
@@ -45,7 +45,7 @@ def page(start, end, truncated, total=365, etag=None, **extra):
|
|
|
45
45
|
**extra,
|
|
46
46
|
}
|
|
47
47
|
if truncated:
|
|
48
|
-
data["nextCursor"] = units[-1]["
|
|
48
|
+
data["nextCursor"] = units[-1]["reference"]
|
|
49
49
|
headers = {"ETag": etag} if etag else None
|
|
50
50
|
return httpx.Response(200, json={"success": True, "data": data}, headers=headers)
|
|
51
51
|
|
|
@@ -55,7 +55,7 @@ def not_modified(etag):
|
|
|
55
55
|
|
|
56
56
|
|
|
57
57
|
def fail(status, code, headers=None):
|
|
58
|
-
return httpx.Response(status, json={"success": False, "code": code, "
|
|
58
|
+
return httpx.Response(status, json={"success": False, "code": code, "message": "boom"}, headers=headers)
|
|
59
59
|
|
|
60
60
|
|
|
61
61
|
@pytest.fixture(autouse=True)
|
|
@@ -80,11 +80,11 @@ def test_get_units_follows_the_cursor_and_returns_every_unit():
|
|
|
80
80
|
result = client.get_units(FINCA)
|
|
81
81
|
|
|
82
82
|
assert len(rec.requests) == 2
|
|
83
|
-
assert rec.requests[0].url.path == f"/
|
|
83
|
+
assert rec.requests[0].url.path == f"/v1/parcels/{FINCA}/units"
|
|
84
84
|
assert "cursor" not in rec.requests[0].url.params
|
|
85
85
|
assert rec.requests[1].url.params["cursor"] == f"{FINCA}0200KH"
|
|
86
|
-
assert len(result["
|
|
87
|
-
assert result["
|
|
86
|
+
assert len(result["units"]) == 365
|
|
87
|
+
assert result["propertyUnitCount"] == 365
|
|
88
88
|
assert result["dataSource"] == "clone"
|
|
89
89
|
assert result["attribution"] == "Dirección General del Catastro"
|
|
90
90
|
assert [p["etag"] for p in result["pages"]] == ['"p1"', '"p2"']
|
|
@@ -92,13 +92,13 @@ def test_get_units_follows_the_cursor_and_returns_every_unit():
|
|
|
92
92
|
|
|
93
93
|
|
|
94
94
|
def test_a_single_page_finca_keeps_its_constructions():
|
|
95
|
-
client, rec = make(page(1, 1, False, total=1,
|
|
95
|
+
client, rec = make(page(1, 1, False, total=1, constructions=[{"use": "Hotelero", "area": 458}]))
|
|
96
96
|
|
|
97
97
|
result = client.get_units(FINCA)
|
|
98
98
|
|
|
99
99
|
assert len(rec.requests) == 1
|
|
100
|
-
assert len(result["
|
|
101
|
-
assert result["
|
|
100
|
+
assert len(result["units"]) == 1
|
|
101
|
+
assert result["constructions"][0]["use"] == "Hotelero"
|
|
102
102
|
|
|
103
103
|
|
|
104
104
|
def test_a_reimport_sends_the_etags_and_reuses_unchanged_pages():
|
|
@@ -112,7 +112,7 @@ def test_a_reimport_sends_the_etags_and_reuses_unchanged_pages():
|
|
|
112
112
|
assert rec.requests[1].headers["If-None-Match"] == '"p2"'
|
|
113
113
|
assert rec.requests[1].url.params["cursor"] == f"{FINCA}0200KH"
|
|
114
114
|
assert again["changed"] is False
|
|
115
|
-
assert len(again["
|
|
115
|
+
assert len(again["units"]) == 365
|
|
116
116
|
|
|
117
117
|
|
|
118
118
|
def test_one_changed_page_marks_the_import_as_changed():
|
|
@@ -123,8 +123,8 @@ def test_one_changed_page_marks_the_import_as_changed():
|
|
|
123
123
|
again = client.get_units(FINCA, previous=previous)
|
|
124
124
|
|
|
125
125
|
assert again["changed"] is True
|
|
126
|
-
assert len(again["
|
|
127
|
-
assert again["
|
|
126
|
+
assert len(again["units"]) == 366
|
|
127
|
+
assert again["propertyUnitCount"] == 366
|
|
128
128
|
|
|
129
129
|
|
|
130
130
|
def test_a_304_for_an_unknown_page_is_an_error():
|
|
@@ -135,7 +135,7 @@ def test_a_304_for_an_unknown_page_is_an_error():
|
|
|
135
135
|
|
|
136
136
|
def test_iter_unit_pages_yields_page_by_page():
|
|
137
137
|
client, _ = make(page(1, 200, True), page(201, 365, False))
|
|
138
|
-
assert [len(p["data"]["
|
|
138
|
+
assert [len(p["data"]["units"]) for p in client.iter_unit_pages(FINCA)] == [200, 165]
|
|
139
139
|
|
|
140
140
|
|
|
141
141
|
def test_a_foral_finca_raises_coverage_error():
|
|
@@ -156,7 +156,7 @@ def test_an_outage_is_retried_after_retry_after(no_sleep):
|
|
|
156
156
|
|
|
157
157
|
result = client.get_units(FINCA)
|
|
158
158
|
|
|
159
|
-
assert len(result["
|
|
159
|
+
assert len(result["units"]) == 3
|
|
160
160
|
assert no_sleep == [2.0]
|
|
161
161
|
|
|
162
162
|
|
|
@@ -186,8 +186,8 @@ def test_the_quota_comes_from_the_page_headers():
|
|
|
186
186
|
ANSWER = {
|
|
187
187
|
"success": True,
|
|
188
188
|
"data": {
|
|
189
|
-
"
|
|
190
|
-
"
|
|
189
|
+
"query": {"text": "Calle Gran Via 31, Madrid"},
|
|
190
|
+
"candidates": [{"reference": "0347501VK4704G", "country": "ES", "confidence": 1.0}],
|
|
191
191
|
"attribution": "CartoCiudad",
|
|
192
192
|
},
|
|
193
193
|
}
|
|
@@ -198,9 +198,9 @@ def test_search_address_candidates_sends_free_text():
|
|
|
198
198
|
|
|
199
199
|
result = client.search_address_candidates(" Calle Gran Via 31, Madrid ")
|
|
200
200
|
|
|
201
|
-
assert rec.requests[0].url.path == "/
|
|
201
|
+
assert rec.requests[0].url.path == "/v1/search/address/candidates"
|
|
202
202
|
assert rec.requests[0].url.params["q"] == "Calle Gran Via 31, Madrid"
|
|
203
|
-
assert result["
|
|
203
|
+
assert result["candidates"][0]["reference"] == "0347501VK4704G"
|
|
204
204
|
|
|
205
205
|
|
|
206
206
|
def test_search_address_candidates_sends_a_structured_address():
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "1.3.2"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|