Skip to content

Commit

Permalink
fix: Fixed anotate query bug that returned empty json and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JCruiz15 committed Oct 30, 2024
1 parent e037243 commit 07145bc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 24 deletions.
21 changes: 7 additions & 14 deletions sigpac_tools/anotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,22 @@ def __query(
KeyError
If the layer is not supported
"""
id = ""
match layer.lower():
case "parcela":
logger.info("Searching for the parcel specified")
url = f"{BASE_URL}/fega/ServiciosVisorSigpac/LayerInfo"
params = {
"layer": layer,
"id": f"{province},{municipality},{aggregate},{zone},{polygon},{parcel}",
}
response = requests.get(url, params=params)
return response.json()
id = f"{province},{municipality},{aggregate},{zone},{polygon},{parcel}"
case "recinto":
logger.info("Searching for the enclosure specified")
url = f"{BASE_URL}/fega/ServiciosVisorSigpac/LayerInfo"
params = {
"layer": layer,
"id": f"{province},{municipality},{aggregate},{zone},{polygon},{parcel},{enclosure}",
}
response = requests.get(url, params=params)
return response.json()
id = f"{province},{municipality},{aggregate},{zone},{polygon},{parcel},{enclosure}"
case _:
raise KeyError(
"Layer not supported. Supported layers: ['parcela', 'recinto']"
)

url = f"{BASE_URL}/fega/serviciosvisorsigpac/layerinfo/{layer}/{id}"
response = requests.get(url)
return response.json()


def get_metadata(layer: str, data: dict):
Expand Down
10 changes: 5 additions & 5 deletions sigpac_tools/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ def search(data: dict) -> dict:
if parc:
logger.info("Searching for the parcel specified")
response = requests.get(
f"{BASE_URL}/fega/ServiciosVisorSigpac/query/recintos/{prov}/{muni}/0/0/{polg}/{parc}"
f"{BASE_URL}/fega/serviciosvisorsigpac/query/recintos/{prov}/{muni}/0/0/{polg}/{parc}"
)
geojson = response.json()
return geojson
else:
logger.info(f"Searching for the parcels of the polygon {polg}")
response = requests.get(
f"{BASE_URL}/fega/ServiciosVisorSigpac/query/parcelas/{prov}/{muni}/0/0/{polg}"
f"{BASE_URL}/fega/serviciosvisorsigpac/query/parcelas/{prov}/{muni}/0/0/{polg}"
)
geojson = response.json()
return geojson
Expand All @@ -64,21 +64,21 @@ def search(data: dict) -> dict:
f"Searching for the polygons of the municipality {muni}"
)
response = requests.get(
f"{BASE_URL}/fega/ServiciosVisorSigpac/query/poligonos/{prov}/{muni}/0/0"
f"{BASE_URL}/fega/serviciosvisorsigpac/query/poligonos/{prov}/{muni}/0/0"
)
geojson = response.json()
return geojson
else:
logger.info(f"Searching for the municipalities of the province {prov}")
response = requests.get(
f"{BASE_URL}/fega/ServiciosVisorSigpac/query/municipios/{prov}"
f"{BASE_URL}/fega/serviciosvisorsigpac/query/municipios/{prov}"
)
geojson = response.json()
return geojson
else:
logger.info(f"Searching for the provinces of the community {comm}")
response = requests.get(
f"{BASE_URL}/fega/ServiciosVisorSigpac/query/provincias/{comm}"
f"{BASE_URL}/fega/serviciosvisorsigpac/query/provincias/{comm}"
)
geojson = response.json()
return geojson
Expand Down
10 changes: 5 additions & 5 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_search_provinces(self, mock_get):
search(data)

mock_get.assert_called_once_with(
f"{BASE_URL}/fega/ServiciosVisorSigpac/query/provincias/1.geojson"
f"{BASE_URL}/fega/serviciosvisorsigpac/query/provincias/1"
)

@patch("sigpac_tools.search.requests.get")
Expand All @@ -35,7 +35,7 @@ def test_search_municipalities(self, mock_get):
search(data)

mock_get.assert_called_once_with(
f"{BASE_URL}/fega/ServiciosVisorSigpac/query/municipios/1.geojson"
f"{BASE_URL}/fega/serviciosvisorsigpac/query/municipios/1"
)

@patch("sigpac_tools.search.requests.get")
Expand All @@ -48,7 +48,7 @@ def test_search_polygons(self, mock_get):
search(data)

mock_get.assert_called_once_with(
f"{BASE_URL}/fega/ServiciosVisorSigpac/query/poligonos/1/1/0/0.geojson"
f"{BASE_URL}/fega/serviciosvisorsigpac/query/poligonos/1/1/0/0"
)

@patch("sigpac_tools.search.requests.get")
Expand All @@ -61,7 +61,7 @@ def test_search_parcels(self, mock_get):
search(data)

mock_get.assert_called_once_with(
f"{BASE_URL}/fega/ServiciosVisorSigpac/query/parcelas/1/1/0/0/1.geojson"
f"{BASE_URL}/fega/serviciosvisorsigpac/query/parcelas/1/1/0/0/1"
)

@patch("sigpac_tools.search.requests.get")
Expand All @@ -74,7 +74,7 @@ def test_search_specific_parcel(self, mock_get):
search(data)

mock_get.assert_called_once_with(
f"{BASE_URL}/fega/ServiciosVisorSigpac/query/recintos/1/1/0/0/1/1.geojson"
f"{BASE_URL}/fega/serviciosvisorsigpac/query/recintos/1/1/0/0/1/1"
)

def test_missing_community_and_province(self):
Expand Down

0 comments on commit 07145bc

Please sign in to comment.