Skip to content

Commit

Permalink
feat: support both urgUnits and orgunits from IASO
Browse files Browse the repository at this point in the history
  • Loading branch information
nazarfil committed Oct 10, 2024
1 parent 042ffdf commit a319874
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
7 changes: 6 additions & 1 deletion openhexa/toolbox/iaso/iaso.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ def get_org_units(self, page: int = 1, limit: int = 10, **kwargs) -> dict:
params = kwargs
params.update({"page": page, "limit": limit})
response = self.api_client.get("/api/orgunits", params=params)
return response.json().get("orgunits")
json_response = response.json()
if "orgunits" in json_response:
return json_response.get("orgunits")
elif "orgUnits" in json_response:
return json_response.get("orgUnits")
return []

def get_form_instances(
self,
Expand Down
16 changes: 16 additions & 0 deletions tests/iaso/fixtures/iaso_api_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@
}

iaso_mocked_orgunits = {
"orgUnits": [
{
"name": "ACEH",
"id": 1978297,
"parent_id": 1978331,
"org_unit_type_id": 781,
"org_unit_type_name": "Province",
"validation_status": "VALID",
"created_at": 1712825023.085615,
"updated_at": 1712828860.665764,
}
]
}


iaso_mocked_orgunits_with_params = {
"orgunits": [
{
"name": "ACEH",
Expand Down
13 changes: 11 additions & 2 deletions tests/iaso/test_iaso.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
iaso_mocked_orgunits,
iaso_mocked_refreshed_auth_token,
iaso_mocked_projects,
iaso_mocked_instances,
iaso_mocked_instances, iaso_mocked_orgunits_with_params,
)


Expand Down Expand Up @@ -50,7 +50,16 @@ def test_get_org_units(self, mock_responses):
iaso = IASO("https://iaso-staging.bluesquare.org", "username", "password")
r = iaso.get_org_units()
assert len(r) > 0

def test_get_org_units_with_params(self, mock_responses):
mock_responses.add(
responses.POST, "https://iaso-staging.bluesquare.org/api/token/", json=iaso_mocked_auth_token, status=200
)
mock_responses.add(
responses.GET, "https://iaso-staging.bluesquare.org/api/orgunits/", json=iaso_mocked_orgunits_with_params, status=200
)
iaso = IASO("https://iaso-staging.bluesquare.org", "username", "password")
r = iaso.get_org_units()
assert len(r) > 0
def test_get_forms(self, mock_responses):
mock_responses.add(
responses.POST, "https://iaso-staging.bluesquare.org/api/token/", json=iaso_mocked_auth_token, status=200
Expand Down

0 comments on commit a319874

Please sign in to comment.