From 5c11f1b5279535a25e258f6f0de90b0ce8266552 Mon Sep 17 00:00:00 2001 From: kovalch Date: Mon, 21 Oct 2024 13:51:52 +0200 Subject: [PATCH] feat: Add test for the landing page --- ckanext/geocat/tests/test_helpers.py | 26 ++++++++++++++++++++++++++ ckanext/geocat/utils/harvest_helper.py | 16 +++++++++++----- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/ckanext/geocat/tests/test_helpers.py b/ckanext/geocat/tests/test_helpers.py index ea949c10..94785192 100644 --- a/ckanext/geocat/tests/test_helpers.py +++ b/ckanext/geocat/tests/test_helpers.py @@ -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": [ diff --git a/ckanext/geocat/utils/harvest_helper.py b/ckanext/geocat/utils/harvest_helper.py index 45197157..11c4ad6e 100644 --- a/ckanext/geocat/utils/harvest_helper.py +++ b/ckanext/geocat/utils/harvest_helper.py @@ -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)