Skip to content

Commit

Permalink
add more load tests and fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
rshewitt committed Jan 4, 2024
1 parent c66c4c2 commit c31a32e
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 66 deletions.
4 changes: 3 additions & 1 deletion harvester/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ def dcatus_to_ckan(dcatus_dataset, harvest_source_name):

resources = create_ckan_resources(dcatus_dataset)
tags = create_ckan_tags(dcatus_dataset["keyword"])
pubisher_hierarchy = create_ckan_publisher_hierarchy(dcatus_dataset["publisher"])
pubisher_hierarchy = create_ckan_publisher_hierarchy(
dcatus_dataset["publisher"], []
)

extras_base = create_ckan_extra_base(
pubisher_hierarchy, "Dataset", dcatus_dataset["publisher"]["name"]
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/load/ckan/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,21 @@ def test_ckan_patch_package(test_ckan_package_id):
@pytest.fixture
def test_ckan_purge_package(test_ckan_package_id):
return {"id": test_ckan_package_id}


@pytest.fixture
def test_ckan_transform_catalog():
return {
"identifier": "test identifier",
"contactPoint": {"fn": "Bob Smith", "hasEmail": "bob.smith@example.com"},
"description": "test description",
"title": "test title",
}


@pytest.fixture
def test_ckan_publisher():
return {
"name": "U.S. Test Organization of the Tests",
"subOrganizationOf": {"name": "Test Incorporated"},
}
65 changes: 0 additions & 65 deletions tests/unit/load/ckan/test_ckan_cud.py
Original file line number Diff line number Diff line change
@@ -1,73 +1,8 @@
from unittest.mock import patch

from deepdiff import DeepDiff

import harvester


def test_dcatus_to_ckan_transform(test_dcatus_catalog):
# ruff: noqa: E501
expected_result = {
"name": "fdic-failed-bank-list",
"owner_org": "test",
"identifier": "https://www.fdic.gov/bank/individual/failed/",
"maintainer": "FDIC Public Data Feedback",
"maintainer_email": "FDICPublicDataFeedback@fdic.gov",
"notes": "The FDIC is often appointed as receiver for failed banks. This list includes banks which have failed since October 1, 2000.",
"title": "FDIC Failed Bank List",
"resources": [
{"url": "https://www.fdic.gov/bank/individual/failed/banklist.csv"},
{"url": "https://www.fdic.gov/bank/individual/failed/index.html"},
],
"tags": [
{"name": "financial-institution"},
{"name": "banks"},
{"name": "failures"},
{"name": "assistance-transactions"},
],
"extras": [
{
"key": "publisher_hierarchy",
"value": "U.S. Government > Federal Deposit Insurance Corporation > Division of Insurance and Research",
},
{"key": "resource-type", "value": "Dataset"},
{"key": "publisher", "value": "Division of Insurance and Research"},
{"key": "accessLevel", "value": "public"},
{"key": "bureauCode", "value": "357:20"},
{
"key": "identifier",
"value": "https://www.fdic.gov/bank/individual/failed/",
},
{"key": "modified", "value": "R/P1W"},
{"key": "programCode", "value": "000:000"},
{"key": "publisher", "value": "Division of Insurance and Research"},
{
"key": "publisher_hierarchy",
"value": "U.S. Government > Federal Deposit Insurance Corporation > Division of Insurance and Research",
},
{"key": "resource-type", "value": "Dataset"},
{"key": "publisher", "value": "Division of Insurance and Research"},
{
"key": "dcat_metadata",
"value": "{'accessLevel': 'public', 'bureauCode': ['357:20'], 'contactPoint': {'fn': 'FDIC Public Data Feedback', 'hasEmail': 'mailto:FDICPublicDataFeedback@fdic.gov'}, 'description': 'The FDIC is often appointed as receiver for failed banks. This list includes banks which have failed since October 1, 2000.', 'distribution': [{'accessURL': 'https://www.fdic.gov/bank/individual/failed/index.html', 'mediaType': 'text/html'}, {'downloadURL': 'https://www.fdic.gov/bank/individual/failed/banklist.csv', 'mediaType': 'text/csv'}], 'identifier': 'https://www.fdic.gov/bank/individual/failed/', 'keyword': ['assistance transactions', 'banks', 'failures', 'financial institution'], 'modified': 'R/P1W', 'programCode': ['000:000'], 'publisher': {'name': 'Division of Insurance and Research', 'subOrganizationOf': {'name': 'Federal Deposit Insurance Corporation', 'subOrganizationOf': {'name': 'U.S. Government'}}}, 'title': 'FDIC Failed Bank List'}",
},
{"key": "harvest_source_name", "value": "example_harvest_source_name"},
],
"author": None,
"author_email": None,
}

assert (
DeepDiff(
harvester.dcatus_to_ckan(
test_dcatus_catalog, "example_harvest_source_name"
),
expected_result,
)
== {}
)


@patch("harvester.create_ckan_package")
def test_create_package(mock_create_ckan_package, ckan_entrypoint, test_ckan_package):
mock_create_ckan_package.return_value = test_ckan_package.copy()
Expand Down
89 changes: 89 additions & 0 deletions tests/unit/load/ckan/test_ckan_transform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
from harvester.load import (
simple_transform,
create_ckan_publisher_hierarchy,
dcatus_to_ckan,
)
from deepdiff import DeepDiff


def test_simple_transform(test_ckan_transform_catalog):
expected_result = {
"name": "test-title",
"owner_org": "test",
"identifier": "test identifier",
"maintainer": "Bob Smith",
"maintainer_email": "bob.smith@example.com",
"notes": "test description",
"title": "test title",
}

res = simple_transform(test_ckan_transform_catalog)
assert res == expected_result


def test_publisher_name(test_ckan_publisher):
res = create_ckan_publisher_hierarchy(test_ckan_publisher, [])
assert res == "Test Incorporated > U.S. Test Organization of the Tests"


def test_dcatus_to_ckan_transform(test_dcatus_catalog):
# ruff: noqa: E501
expected_result = {
"name": "fdic-failed-bank-list",
"owner_org": "test",
"identifier": "https://www.fdic.gov/bank/individual/failed/",
"maintainer": "FDIC Public Data Feedback",
"maintainer_email": "FDICPublicDataFeedback@fdic.gov",
"notes": "The FDIC is often appointed as receiver for failed banks. This list includes banks which have failed since October 1, 2000.",
"title": "FDIC Failed Bank List",
"resources": [
{"url": "https://www.fdic.gov/bank/individual/failed/banklist.csv"},
{"url": "https://www.fdic.gov/bank/individual/failed/index.html"},
],
"tags": [
{"name": "financial-institution"},
{"name": "banks"},
{"name": "failures"},
{"name": "assistance-transactions"},
],
"extras": [
{
"key": "publisher_hierarchy",
"value": "U.S. Government > Federal Deposit Insurance Corporation > Division of Insurance and Research",
},
{"key": "resource-type", "value": "Dataset"},
{"key": "publisher", "value": "Division of Insurance and Research"},
{"key": "accessLevel", "value": "public"},
{"key": "bureauCode", "value": "357:20"},
{
"key": "identifier",
"value": "https://www.fdic.gov/bank/individual/failed/",
},
{"key": "modified", "value": "R/P1W"},
{"key": "programCode", "value": "000:000"},
{"key": "publisher", "value": "Division of Insurance and Research"},
{
"key": "publisher_hierarchy",
"value": "U.S. Government > Federal Deposit Insurance Corporation > Division of Insurance and Research",
},
{"key": "resource-type", "value": "Dataset"},
{"key": "publisher", "value": "Division of Insurance and Research"},
{
"key": "dcat_metadata",
"value": "{'accessLevel': 'public', 'bureauCode': ['357:20'], 'contactPoint': {'fn': 'FDIC Public Data Feedback', 'hasEmail': 'mailto:FDICPublicDataFeedback@fdic.gov'}, 'description': 'The FDIC is often appointed as receiver for failed banks. This list includes banks which have failed since October 1, 2000.', 'distribution': [{'accessURL': 'https://www.fdic.gov/bank/individual/failed/index.html', 'mediaType': 'text/html'}, {'downloadURL': 'https://www.fdic.gov/bank/individual/failed/banklist.csv', 'mediaType': 'text/csv'}], 'identifier': 'https://www.fdic.gov/bank/individual/failed/', 'keyword': ['assistance transactions', 'banks', 'failures', 'financial institution'], 'modified': 'R/P1W', 'programCode': ['000:000'], 'publisher': {'name': 'Division of Insurance and Research', 'subOrganizationOf': {'name': 'Federal Deposit Insurance Corporation', 'subOrganizationOf': {'name': 'U.S. Government'}}}, 'title': 'FDIC Failed Bank List'}",
},
{"key": "harvest_source_name", "value": "example_harvest_source_name"},
],
"author": None,
"author_email": None,
}

# res = dcatus_to_ckan(test_dcatus_catalog, "example_harvest_source_name")

assert (
DeepDiff(
dcatus_to_ckan(test_dcatus_catalog, "example_harvest_source_name"),
expected_result,
)
== {}
)

1 comment on commit c31a32e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
harvester
   __init__.py120100% 
   compare.py120100% 
   extract.py4877 85%
   load.py1001010 90%
   transform.py1377 46%
harvester/utils
   __init__.py20100% 
   json.py40100% 
   util.py70100% 
harvester/validate
   __init__.py20100% 
   dcat_us.py2433 88%
TOTAL2242788% 

Tests Skipped Failures Errors Time
28 0 💤 0 ❌ 0 🔥 24.193s ⏱️

Please sign in to comment.