-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds expectation for deleted entities #317
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,10 @@ | |
import pytest | ||
import pandas as pd | ||
|
||
from digital_land.expectations.operation import count_lpa_boundary | ||
from digital_land.expectations.operation import ( | ||
count_lpa_boundary, | ||
count_deleted_entities, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
|
@@ -109,3 +112,64 @@ def test_count_lpa_boundary_passes( | |
detail_keys = ["actual", "expected"] | ||
for key in detail_keys: | ||
assert key in details, f"{key} missing from details" | ||
|
||
|
||
def test_count_deleted_entities(dataset_path, mocker): | ||
# define constant parameters | ||
organisation_entity = 109 | ||
expected = 0 | ||
|
||
# load data into sqlite for entity, fact_resource and fact table | ||
test_entity_data = pd.DataFrame.from_dict( | ||
{ | ||
"entity": ["1001"], | ||
"name": ["test1"], | ||
"organisation_entity": [109], | ||
"reference": ["ref1"], | ||
} | ||
) | ||
|
||
test_fact_resource_data = pd.DataFrame.from_dict( | ||
{ | ||
"fact": ["036d2b946bd41", "16bf38800aafd"], | ||
"resource": ["2f7d900dd48fd02", "2f7d900dd48fd02"], | ||
"entry_number": ["1", "1"], | ||
}, | ||
) | ||
|
||
test_fact_data = pd.DataFrame.from_dict( | ||
{ | ||
"fact": ["036d2b946bd41", "16bf38800aafd"], | ||
"entity": ["1001", "1001"], | ||
"field": ["name", "reference"], | ||
"value": ["abc", "ref1"], | ||
} | ||
) | ||
|
||
# mock `pandas.read_csv` to return the mock DataFrame | ||
mock_df = pd.DataFrame({"resource": ["2f7d900dd48fd02"]}) | ||
mocker.patch("pandas.read_csv", return_value=mock_df) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these lines necessary? I can't see where 'mock_df' is required. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The setup mocks the |
||
|
||
with spatialite.connect(dataset_path) as conn: | ||
# load data into required tables | ||
test_entity_data.to_sql("entity", conn, if_exists="append", index=False) | ||
test_fact_resource_data.to_sql( | ||
"fact_resource", conn, if_exists="append", index=False | ||
) | ||
test_fact_data.to_sql("fact", conn, if_exists="append", index=False) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would we want the |
||
|
||
# run expectation | ||
passed, message, details = count_deleted_entities( | ||
conn, | ||
expected=expected, | ||
organisation_entity=organisation_entity, | ||
) | ||
|
||
assert ( | ||
passed | ||
), f"test failed : expected {details['expected']} but got {details['actual']} entities" | ||
assert message, "test requires a message" | ||
|
||
detail_keys = ["actual", "expected"] | ||
for key in detail_keys: | ||
assert key in details, f"{key} missing from details" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For 'select *,o.entity ...' should there be an alias in front of the star or is 'o.entity' not required as the star will bring all of the columns in?