Skip to content

Commit

Permalink
Merge pull request #44 from OCHA-DAP/add_tests
Browse files Browse the repository at this point in the history
HAPI-154 Add functional tests
  • Loading branch information
mcarans authored Oct 11, 2023
2 parents ea7231d + 9595ee3 commit c7152ee
Show file tree
Hide file tree
Showing 27 changed files with 10,888 additions and 23 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/run-python-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# This workflow will install Python dependencies, lint and run tests
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Run tests

on:
workflow_dispatch: # add run button in github
push:
branches-ignore:
- gh-pages
- 'dependabot/**'
pull_request:
branches-ignore:
- gh-pages

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade hatch
- name: Test with hatch/pytest
run: |
hatch run test:test
- name: Check styling
if: always()
run: |
hatch run lint:style
- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
junit_files: test-results.xml
- name: Publish in Coveralls
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
flag-name: tests
format: lcov
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ filelock==3.12.4
# via virtualenv
frictionless==5.16.0
# via hdx-python-utilities
google-auth==2.23.2
google-auth==2.23.3
# via
# google-auth-oauthlib
# gspread
Expand All @@ -69,7 +69,7 @@ greenlet==3.0.0
# via sqlalchemy
gspread==5.11.3
# via hdx-python-scraper
hapi-schema==0.0.5
hapi-schema==0.0.6
# via hapi-pipelines (pyproject.toml)
hdx-python-api==6.1.3
# via
Expand Down
15 changes: 15 additions & 0 deletions src/hapi/pipelines/app/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from os.path import join
from typing import Dict

from hdx.utilities.loader import load_and_merge_yaml
from hdx.utilities.path import script_dir_plus_file
from hdx.utilities.typehint import ListTuple


def load_yamls(config_files: ListTuple[str]) -> Dict:
input_files = [
script_dir_plus_file(join("..", "configs", file), load_yamls)
for file in config_files
]
project_config = load_and_merge_yaml(input_files)
return project_config
24 changes: 4 additions & 20 deletions src/hapi/pipelines/app/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from os import getenv
from typing import List, Optional

import yaml
from hdx.api.configuration import Configuration
from hdx.database import Database
from hdx.database.dburi import get_params_from_connection_uri
Expand All @@ -15,9 +14,10 @@
from hdx.utilities.dictandlist import args_to_dict
from hdx.utilities.easy_logging import setup_logging
from hdx.utilities.errors_onexit import ErrorsOnExit
from hdx.utilities.path import script_dir_plus_file, temp_dir
from hdx.utilities.path import temp_dir

from hapi.pipelines._version import __version__
from hapi.pipelines.app import load_yamls
from hapi.pipelines.app.pipelines import Pipelines

setup_logging()
Expand Down Expand Up @@ -64,19 +64,6 @@ def parse_args():
return parser.parse_args()


def compile_YAMLs(config_files):
project_config = {}
for config_file in config_files:
file_address = script_dir_plus_file(f"../configs/{config_file}", main)
with open(file_address) as file:
config = yaml.safe_load(file)
project_config = project_config | config

output_address = script_dir_plus_file("project_configuration.yaml", main)
with open(output_address, "w") as file:
yaml.dump(project_config, file)


def main(
db_uri: Optional[str] = None,
db_params: Optional[str] = None,
Expand Down Expand Up @@ -170,17 +157,14 @@ def main(
"population.yaml",
"operational_presence.yaml",
]
compile_YAMLs(project_configs)
project_config_yaml = script_dir_plus_file(
"project_configuration.yaml", main
)
project_config_dict = load_yamls(project_configs)
facade(
main,
hdx_key=hdx_key,
user_agent=user_agent,
preprefix=preprefix,
hdx_site=hdx_site,
project_config_yaml=project_config_yaml,
project_config_dict=project_config_dict,
db_uri=db_uri,
db_params=args.db_params,
scrapers_to_run=scrapers_to_run,
Expand Down
2 changes: 1 addition & 1 deletion src/hapi/pipelines/database/population.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def _validate_hxl_tag(hxl_tag: str) -> bool:
#population+f+age_5_12
#population+f+age_80_plus
"""
# TODO: add tests for this (HAPI-154)
# TODO: add tests for this (HAPI-159)
return bool(_HXL_PATTERN.match(hxl_tag))


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"archived": false, "creator_user_id": "391f0864-b6e4-425f-9d46-df87aa456c2b", "data_update_frequency": "180", "dataseries_name": "OCHA Afghanistan - Who does What Where", "dataset_date": "[2023-01-01T00:00:00 TO 2023-03-31T23:59:59]", "dataset_preview": "resource_id", "dataset_source": "Humanitarian partners", "due_date": "2023-11-05T07:35:47", "has_geodata": false, "has_quickcharts": true, "has_showcases": true, "id": "f50bc211-d42f-4fcd-8291-3e4a57a0dfcf", "is_requestdata_type": false, "isopen": true, "last_modified": "2023-05-09T07:35:47.682796", "license_id": "cc-by", "license_title": "Creative Commons Attribution International", "license_url": "http://www.opendefinition.org/licenses/cc-by", "maintainer": "391f0864-b6e4-425f-9d46-df87aa456c2b", "maintainer_email": "[email protected]", "metadata_created": "2023-05-04T06:04:43.041555", "metadata_modified": "2023-09-07T08:36:12.493166", "methodology": "Direct Observational Data/Anecdotal Data", "name": "afghanistan-who-does-what-where-january-to-march-2023", "notes": "The Who does What Where (3W) is a core humanitarian coordination dataset. It is critical to know where humanitarian organizations are working, what they are doing and their capability in order to identify gaps, avoid duplication of efforts, and plan for future humanitarian response (if needed). The data includes a list of humanitarian organizations by district and cluster, as well as a unique count of organizations. An interactive map of the 3W data can be accessed [here](https://www.humanitarianresponse.info/en/operations/afghanistan/3w). ", "num_resources": 3, "num_tags": 4, "organization": {"id": "10e168ce-5b51-49ac-8616-a142d48618e5", "name": "ocha-afghanistan", "title": "OCHA Afghanistan", "type": "organization", "description": "OCHA resumed its operation in Afghanistan in 2009, providing humanitarian assistance in a complex environment where separate \u2013 and not always complementary \u2013 military, political and security objectives pose challenges to the implementation of humanitarian principles, the ability of responders to reach people in need and the safety and security of aid workers", "image_url": "", "created": "2014-08-06T14:26:07.642577", "is_organization": true, "approval_status": "approved", "state": "active"}, "overdue_date": "2023-12-05T07:35:47", "owner_org": "10e168ce-5b51-49ac-8616-a142d48618e5", "package_creator": "murtaza", "pageviews_last_14_days": 1, "private": false, "qa_completed": false, "solr_additions": "{\"countries\": [\"Afghanistan\"]}", "state": "active", "subnational": "1", "title": "Afghanistan - Who does What Where (January to March 2023)", "total_res_downloads": 129, "type": "dataset", "url": null, "version": null, "groups": [{"description": "", "display_name": "Afghanistan", "id": "afg", "image_display_url": "", "name": "afg", "title": "Afghanistan"}], "tags": [{"display_name": "hxl", "id": "a0fbb23a-6aad-4ccc-8062-e9ef9f20e5d2", "name": "hxl", "state": "active", "vocabulary_id": "b891512e-9516-4bf5-962a-7a289772a2a1"}, {"display_name": "operational capacity", "id": "d8a59526-9f9a-4c71-b38f-5d9f2eb1615a", "name": "operational capacity", "state": "active", "vocabulary_id": "b891512e-9516-4bf5-962a-7a289772a2a1"}, {"display_name": "operational presence", "id": "a25059f9-7e1f-49be-b629-ccccd97a95f8", "name": "operational presence", "state": "active", "vocabulary_id": "b891512e-9516-4bf5-962a-7a289772a2a1"}, {"display_name": "who is doing what and where-3w-4w-5w", "id": "ec53893c-6dba-4656-978b-4a32289ea2eb", "name": "who is doing what and where-3w-4w-5w", "state": "active", "vocabulary_id": "b891512e-9516-4bf5-962a-7a289772a2a1"}], "relationships_as_subject": [], "relationships_as_object": [], "is_fresh": true, "update_status": "fresh", "x_resource_grouping": [], "resources": [{"alt_url": "https://data.humdata.org/dataset/f50bc211-d42f-4fcd-8291-3e4a57a0dfcf/resource/129a828a-9735-418e-ad41-691a6dac4144/download/", "cache_last_updated": null, "cache_url": null, "created": "2023-05-09T07:35:36.019511", "dataset_preview_enabled": false, "datastore_active": false, "description": "", "download_url": "https://data.humdata.org/dataset/f50bc211-d42f-4fcd-8291-3e4a57a0dfcf/resource/129a828a-9735-418e-ad41-691a6dac4144/download/afghanistan-3w-january-march-2023.xlsx", "format": "XLSX", "fs_check_info": "[{\"state\": \"processing\", \"message\": \"The processing of the file structure check has started\", \"timestamp\": \"2023-05-09T07:35:35.550193\"}, {\"state\": \"success\", \"message\": \"Hxl Proxy data received successfully\", \"timestamp\": \"2023-05-09T07:35:37.820231\", \"hxl_proxy_response\": {\"url_or_filename\": null, \"format\": \"XLSX\", \"sheets\": [{\"name\": \"MetaData\", \"is_hidden\": false, \"nrows\": 11, \"ncols\": 1, \"has_merged_cells\": false, \"is_hxlated\": false, \"header_hash\": \"8a9c0818e0622aadfcb2e59cfe5299b4\", \"hxl_header_hash\": null}, {\"name\": \"List_District\", \"is_hidden\": false, \"nrows\": 403, \"ncols\": 21, \"has_merged_cells\": false, \"is_hxlated\": true, \"header_hash\": \"30d419bf10484e12f5a01f983141414f\", \"hxl_header_hash\": \"13a225f52ee1aef7a638c73adb893a32\"}, {\"name\": \"Count_District\", \"is_hidden\": false, \"nrows\": 403, \"ncols\": 21, \"has_merged_cells\": false, \"is_hxlated\": true, \"header_hash\": \"30d419bf10484e12f5a01f983141414f\", \"hxl_header_hash\": \"13a225f52ee1aef7a638c73adb893a32\"}]}}]", "hash": "", "hdx_rel_url": "/dataset/f50bc211-d42f-4fcd-8291-3e4a57a0dfcf/resource/129a828a-9735-418e-ad41-691a6dac4144/download/afghanistan-3w-january-march-2023.xlsx", "id": "129a828a-9735-418e-ad41-691a6dac4144", "last_modified": "2023-05-09T07:35:35.641553", "metadata_modified": "2023-05-09T14:11:46.390076", "microdata": false, "mimetype": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "mimetype_inner": null, "name": "afghanistan-3w-january-march-2023.xlsx", "originalHash": "-988266717", "package_id": "f50bc211-d42f-4fcd-8291-3e4a57a0dfcf", "pii": "false", "pii_predict_score": 0.8562966605953982, "pii_report_flag": "FINDINGS", "pii_report_id": "/resources/129a828a-9735-418e-ad41-691a6dac4144/pii.2023-05-09T07-35-40.main.json", "pii_timestamp": "2023-05-09T07:36:15.845000", "position": 0, "resource_type": "file.upload", "size": 142558, "state": "active", "url": "https://data.humdata.org/dataset/f50bc211-d42f-4fcd-8291-3e4a57a0dfcf/resource/129a828a-9735-418e-ad41-691a6dac4144/download/afghanistan-3w-january-march-2023.xlsx", "url_type": "upload"}, {"alt_url": "https://data.humdata.org/dataset/f50bc211-d42f-4fcd-8291-3e4a57a0dfcf/resource/1d28eb8a-5585-4694-ba2f-766212a2f5ae/download/", "cache_last_updated": null, "cache_url": null, "created": "2023-05-04T06:04:44.805532", "dataset_preview_enabled": true, "datastore_active": false, "description": "", "download_url": "https://data.humdata.org/dataset/f50bc211-d42f-4fcd-8291-3e4a57a0dfcf/resource/1d28eb8a-5585-4694-ba2f-766212a2f5ae/download/afghanistan-3w-operational-presence-january-march-2023.csv", "format": "CSV", "hash": "", "hdx_rel_url": "/dataset/f50bc211-d42f-4fcd-8291-3e4a57a0dfcf/resource/1d28eb8a-5585-4694-ba2f-766212a2f5ae/download/afghanistan-3w-operational-presence-january-march-2023.csv", "id": "1d28eb8a-5585-4694-ba2f-766212a2f5ae", "last_modified": "2023-05-09T07:35:47.682796", "metadata_modified": "2023-06-05T10:39:33.579461", "microdata": false, "mimetype": "text/csv", "mimetype_inner": null, "name": "afghanistan-3w-operational-presence-january-march-2023.csv", "originalHash": -1590159593, "package_id": "f50bc211-d42f-4fcd-8291-3e4a57a0dfcf", "pii": "false", "pii_predict_score": 0.7961682088135019, "pii_report_flag": "FINDINGS", "pii_report_id": "/resources/1d28eb8a-5585-4694-ba2f-766212a2f5ae/pii.2023-05-09T07-35-51.main.json", "pii_timestamp": "2023-05-09T07:36:40.941000", "position": 1, "resource_type": "file.upload", "size": 1477495, "state": "active", "url": "https://data.humdata.org/dataset/f50bc211-d42f-4fcd-8291-3e4a57a0dfcf/resource/1d28eb8a-5585-4694-ba2f-766212a2f5ae/download/afghanistan-3w-operational-presence-january-march-2023.csv", "url_type": "upload"}, {"alt_url": "https://data.humdata.org/dataset/f50bc211-d42f-4fcd-8291-3e4a57a0dfcf/resource/f4b8a3d4-b952-4375-b9b8-926c78047c59/download/", "cache_last_updated": null, "cache_url": null, "created": "2023-05-04T06:04:54.297605", "dataset_preview_enabled": false, "datastore_active": false, "description": "", "download_url": "https://data.humdata.org/dataset/f50bc211-d42f-4fcd-8291-3e4a57a0dfcf/resource/f4b8a3d4-b952-4375-b9b8-926c78047c59/download/afghanistan-3w-operational-capacity-january-march-2023.csv", "format": "CSV", "hash": "", "hdx_rel_url": "/dataset/f50bc211-d42f-4fcd-8291-3e4a57a0dfcf/resource/f4b8a3d4-b952-4375-b9b8-926c78047c59/download/afghanistan-3w-operational-capacity-january-march-2023.csv", "id": "f4b8a3d4-b952-4375-b9b8-926c78047c59", "last_modified": "2023-05-04T06:04:54.071665", "metadata_modified": "2023-05-04T06:05:52.859718", "microdata": false, "mimetype": "text/csv", "mimetype_inner": null, "name": "afghanistan-3w-operational-capacity-january-march-2023.csv", "originalHash": "-988266717", "package_id": "f50bc211-d42f-4fcd-8291-3e4a57a0dfcf", "pii": "false", "pii_predict_score": 0.7829160250103557, "pii_report_flag": "FINDINGS", "pii_report_id": "/resources/f4b8a3d4-b952-4375-b9b8-926c78047c59/pii.2023-05-04T06-04-57.main.json", "pii_timestamp": "2023-05-04T06:05:52.383000", "position": 2, "resource_type": "file.upload", "size": 1302201, "state": "active", "url": "https://data.humdata.org/dataset/f50bc211-d42f-4fcd-8291-3e4a57a0dfcf/resource/f4b8a3d4-b952-4375-b9b8-926c78047c59/download/afghanistan-3w-operational-capacity-january-march-2023.csv", "url_type": "upload"}]}
Loading

0 comments on commit c7152ee

Please sign in to comment.