Skip to content

Commit

Permalink
Merge pull request #16 from CIAT-DAPA/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Minotriz02 authored May 30, 2024
2 parents 7f25e5e + d6a3054 commit 3f89acb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 21 deletions.
8 changes: 0 additions & 8 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ on:
permissions:
contents: read

env:
GEOSERVER_USER: ${{secrets.GEOSERVER_USER}}
GEOSERVER_PASSWORD: ${{secrets.GEOSERVER_PASSWORD}}

jobs:

# ------- START TEST PROCCESS -------- #
Expand All @@ -40,10 +36,6 @@ jobs:
- name: Install dependencies
run: |
pip install -r ./requirements.txt
- name: Create environment variables
run: |
export GEOSERVER_USER=${{env.GEOSERVER_USER}}
export GEOSERVER_PASSWORD=${{env.GEOSERVER_PASSWORD}}
- name: Run Tests
run: |
python -m unittest discover -s ./src/test/ -p 'test_*.py'
Expand Down
Binary file modified README.md
Binary file not shown.
21 changes: 11 additions & 10 deletions src/aclimate_api/geoserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@
import re
import tempfile
import geopandas as gpd
import os

class Geoserver:

def __init__(self, url_root):
self.url_root = url_root

def get_geo_workspaces(self):
def get_geo_workspaces(self, user, password):
"""
Retrieves the list of GeoServer workspaces.
Args:
user (str): The username for the GeoServer instance.
password (str): The password for the GeoServer instance.
Returns:
pandas.DataFrame: A DataFrame containing the workspace names and their corresponding hrefs.
"""
user = os.getenv("GEOSERVER_USER")
password = os.getenv("GEOSERVER_PASSWORD")

if not user or not password:
print("Error: Missing GeoServer credentials")
Expand Down Expand Up @@ -57,18 +58,18 @@ def get_geo_workspaces(self):

# print(get_geo_workspaces("https://geo.aclimate.org/geoserver/"))

def get_geo_mosaic_name(self, workspace):
def get_geo_mosaic_name(self, workspace, user, password):
"""
Retrieves the names and hrefs of the mosaics in the specified GeoServer workspace.
Args:
workspace (str): The name of the GeoServer workspace.
user (str): The username for the GeoServer instance.
password (str): The password for the GeoServer instance.
Returns:
pandas.DataFrame: A DataFrame containing the mosaic names and hrefs, or an empty DataFrame if there was an error.
"""
user = os.getenv("GEOSERVER_USER")
password = os.getenv("GEOSERVER_PASSWORD")

if not user or not password:
print("Error: Missing GeoServer credentials")
Expand Down Expand Up @@ -155,19 +156,19 @@ def get_geo_mosaics(self, workspace, mosaic_name, year, month=1, day=1):

# print(get_geo_mosaics("https://geo.aclimate.org/geoserver/", "waterpoints_et", "biomass", 2024, 4, 22))

def get_geo_polygon_name(self, workspace):
def get_geo_polygon_name(self, workspace, user, password):
"""
Retrieves the names and hrefs of polygons from the specified workspace in GeoServer.
Args:
workspace (str): The name of the workspace in GeoServer.
user (str): The username for the GeoServer instance.
password (str): The password for the GeoServer instance.
Returns:
pandas.DataFrame: A DataFrame containing the names and hrefs of the polygons, with columns 'polygon_name' and 'polygon_href'.
If no polygons are found or an error occurs, an empty DataFrame is returned.
"""
user = os.getenv("GEOSERVER_USER")
password = os.getenv("GEOSERVER_PASSWORD")

if not user or not password:
print("Error: Missing GeoServer credentials")
Expand Down
6 changes: 3 additions & 3 deletions src/test/test_geoserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_get_geo_workspaces(self, mock_get):
mock_get.return_value.status_code = 200
mock_get.return_value.text = geo_workspace_mock_data

result = self.geoserver.get_geo_workspaces()
result = self.geoserver.get_geo_workspaces("test","pass")

self.assertIsInstance(result, pd.DataFrame)
self.assertIn("workspace_name", result.columns)
Expand All @@ -39,7 +39,7 @@ def test_get_geo_mosaic_name(self, mock_get):
mock_get.return_value.status_code = 200
mock_get.return_value.text = geo_mosaic_name_mock_data

result = self.geoserver.get_geo_mosaic_name(workspace)
result = self.geoserver.get_geo_mosaic_name(workspace,"test","pass")

self.assertIsInstance(result, pd.DataFrame)
self.assertIn("mosaic_name", result.columns)
Expand Down Expand Up @@ -74,7 +74,7 @@ def test_get_geo_polygon_name(self, mock_get):
mock_get.return_value.status_code = 200
mock_get.return_value.text = geo_polygon_name_mock_data

result = self.geoserver.get_geo_polygon_name(workspace)
result = self.geoserver.get_geo_polygon_name(workspace,"test","pass")

self.assertIsInstance(result, pd.DataFrame)
self.assertIn("polygon_name", result.columns)
Expand Down

0 comments on commit 3f89acb

Please sign in to comment.