Skip to content

Commit

Permalink
feat: Add test for the landing page
Browse files Browse the repository at this point in the history
  • Loading branch information
kovalch committed Oct 21, 2024
1 parent 5be4a53 commit 5c11f1b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
26 changes: 26 additions & 0 deletions ckanext/geocat/tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,32 @@ def test_check_package_change_new_resource_modified_time(self):
"resource modified date changed: 2020-01-02T12:00:00"
)

def test_check_package_change_new_url(self):
existing_package = {
"url": "http://example.org/landing",
}
dataset_dict = {
"url": "http://example.org/new/landing",
}

assert check_package_change(existing_package, dataset_dict) == (
True,
"dataset url value changed from 'http://example.org/landing' to 'http://example.org/new/landing'"
)

def test_check_package_change_empty_new_url(self):
existing_package = {
"url": "http://example.org/landing",
}
dataset_dict = {
"url": "",
}

assert check_package_change(existing_package, dataset_dict) == (
True,
"dataset url value changed from 'http://example.org/landing' to 'None'"
)

def test_check_package_change_new_resource_url(self):
existing_package = {
"resources": [
Expand Down
16 changes: 11 additions & 5 deletions ckanext/geocat/utils/harvest_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,22 @@ def create_activity(package_id, message):


def check_package_change(existing_pkg, dataset_dict):
# Ensure to clear the key values if they are not
# in the new dataset_dict
for key in existing_pkg.keys():
if key not in dataset_dict or not dataset_dict[key]:
existing_pkg[key] = ''
# Check if the URL has changed
existing_pkg_url = existing_pkg.get('url')
dataset_dict_url = dataset_dict.get('url')
if existing_pkg_url != dataset_dict_url:
msg = "dataset url value changed from '{}' to '{}'".format(
existing_pkg_url or "None", dataset_dict_url or "None")
return True, msg

# Check if the modified date has changed
if _changes_in_date(
existing_pkg.get('modified'), dataset_dict.get('modified')):
msg = "dataset modified date changed: {}" \
.format(dataset_dict.get('modified'))
return True, msg

# Check for changes in resources
resources = dataset_dict.get('resources', [])
existing_resources = existing_pkg.get('resources', [])
resource_count_changed = len(existing_resources) != len(resources)
Expand Down

0 comments on commit 5c11f1b

Please sign in to comment.