diff --git a/ckanext/mapactiongeorss/plugin.py b/ckanext/mapactiongeorss/plugin.py index ad1e0a2..9f4994e 100644 --- a/ckanext/mapactiongeorss/plugin.py +++ b/ckanext/mapactiongeorss/plugin.py @@ -24,11 +24,16 @@ def get_item_additional_fields(self, package): """ Get the geometry from either extras (for legacy datasets) or dataset fields """ geometry_fields = ('ymin', 'xmin', 'ymax', 'xmax') + geometry_source = {} + if all(o in package for o in geometry_fields): geometry_source = package else: - # look for geometry in extras - geometry_source = {e['key']: e['value'] for e in package['extras']} + try: + # look for geometry in extras + geometry_source = {e['key']: e['value'] for e in package['extras']} + except KeyError: + pass box = tuple( float(geometry_source.get(n, '0')) diff --git a/ckanext/mapactiongeorss/tests/controllers/test_feed.py b/ckanext/mapactiongeorss/tests/controllers/test_feed.py index 50fb88e..3041f36 100644 --- a/ckanext/mapactiongeorss/tests/controllers/test_feed.py +++ b/ckanext/mapactiongeorss/tests/controllers/test_feed.py @@ -9,6 +9,8 @@ import ckanext.mapactiongeorss.tests.helpers as helpers import ckanext.mapactiongeorss.tests.factories as custom_factories +from ckanext.mapactionimporter.plugin import create_product_themes + assert_equals = nose.tools.assert_equals assert_true = nose.tools.assert_true assert_regexp_matches = nose.tools.assert_regexp_matches @@ -117,6 +119,14 @@ def test_feed_contains_published(self): expected_published = self.convert_date(dataset['metadata_created']) assert_equals(published, expected_published) + def test_feed_handles_default_schema_without_extras(self): + create_product_themes() + dataset = custom_factories.DefaultDataset(product_themes=['Agriculture']) + + published = self.find_in_rss('xmlns:entry/xmlns:published').text + expected_published = self.convert_date(dataset['metadata_created']) + assert_equals(published, expected_published) + def test_main_feed_title_is_mapaction_georss(self): title = self.find_in_rss('xmlns:title').text diff --git a/ckanext/mapactiongeorss/tests/default.json b/ckanext/mapactiongeorss/tests/default.json new file mode 100644 index 0000000..cfc6c16 --- /dev/null +++ b/ckanext/mapactiongeorss/tests/default.json @@ -0,0 +1,81 @@ +{ + "scheming_version": 1, + "dataset_type": "default", + "about": "MapAction Default", + "about_url": "", + "dataset_fields": [ + { + "field_name": "title", + "label": "Title", + "preset": "title", + "form_placeholder": "eg. A descriptive title" + }, + { + "field_name": "name", + "label": "URL", + "preset": "dataset_slug", + "form_placeholder": "eg. my-dataset" + }, + { + "field_name": "notes", + "label": "Description", + "form_snippet": "markdown.html", + "form_placeholder": "eg. Some useful notes about the data" + }, + { + "field_name": "license_id", + "label": "License", + "form_snippet": "license.html", + "help_text": "License definitions and additional information can be found at http://opendefinition.org/" + }, + { + "field_name": "owner_org", + "label": "Organization", + "preset": "dataset_organization" + }, + { + "field_name": "url", + "label": "Source", + "form_placeholder": "http://example.com/dataset.json", + "display_property": "foaf:homepage", + "display_snippet": "link.html" + }, + { + "field_name": "version", + "label": "Version", + "validators": "ignore_missing unicode package_version_validator", + "form_placeholder": "1.0" + }, + { + "field_name": "product_themes", + "label": "Themes", + "preset": "product_themes", + "form_placeholder": "eg. economy, mental health, government", + "vocabulary": "product_themes", + "choices_helper": "mapactionschemas_vocabulary_choices" + } + ], + "resource_fields": [ + { + "field_name": "url", + "label": "URL", + "preset": "resource_url_upload" + }, + { + "field_name": "name", + "label": "Name", + "form_placeholder": "eg. January 2011 Gold Prices" + }, + { + "field_name": "description", + "label": "Description", + "form_snippet": "markdown.html", + "form_placeholder": "Some useful notes about the data" + }, + { + "field_name": "format", + "label": "Format", + "preset": "resource_format_autocomplete" + } + ] +} diff --git a/ckanext/mapactiongeorss/tests/factories.py b/ckanext/mapactiongeorss/tests/factories.py new file mode 100644 index 0000000..7d6fa76 --- /dev/null +++ b/ckanext/mapactiongeorss/tests/factories.py @@ -0,0 +1,8 @@ +import ckan.tests.factories as factories + + +class Dataset(factories.Dataset): + type = 'test_schema' + +class DefaultDataset(factories.Dataset): + type = 'default' diff --git a/ckanext/mapactiongeorss/tests/test_schema.json b/ckanext/mapactiongeorss/tests/test_schema.json new file mode 100644 index 0000000..a8c41ad --- /dev/null +++ b/ckanext/mapactiongeorss/tests/test_schema.json @@ -0,0 +1,130 @@ +{ + "scheming_version": 1, + "dataset_type": "test-schema", + "about_url": "http://github.com/ckan/ckanext-scheming", + "dataset_fields": [ + { + "field_name": "title", + "label": "Title", + "preset": "title", + "form_placeholder": "eg. Larry, Peter, Susan" + }, + { + "field_name": "name", + "label": "URL", + "preset": "dataset_slug", + "form_placeholder": "eg. camel-no-5" + }, + { + "field_name": "humps", + "label": "Humps", + "validators": "ignore_missing int_validator", + "form_placeholder": "eg. 2" + }, + { + "field_name": "category", + "label": "Category", + "help_text": "Make and model", + "help_inline": true, + "preset": "select", + "choices": [ + { + "value": "bactrian", + "label": "Bactrian Camel" + }, + { + "value": "hybrid", + "label": "Hybrid Camel" + }, + { + "value": "f2hybrid", + "label": "F2 Hybrid Camel" + }, + { + "value": "snowwhite", + "label": "Snow-white Dromedary" + }, + { + "value": "black", + "label": "Black Camel" + } + ] + }, + { + "field_name": "personality", + "label": "Personality", + "preset": "multiple_checkbox", + "choices_helper": "scheming_test_schema_choices" + }, + { + "field_name": "a_relevant_date", + "label": "A relevant date", + "preset": "date" + }, + { + "field_name": "a_relevant_datetime", + "label": "Date+Time", + "label_time": "Time (combined with above)", + "preset": "datetime" + }, + { + "field_name": "a_relevant_datetime_tz", + "label": "Date+Time+Tz", + "label_time": "Time (for above)", + "label_tz": "Timezone (for above)", + "preset": "datetime_tz" + }, + { + "field_name": "other", + "label": {"en": "Other information"}, + "output_validators": "ignore_missing" + }, + { + "label": "Example JSON", + "field_name": "a_json_field", + "preset": "json_object" + } + ], + "resource_fields": [ + { + "field_name": "url", + "label": "Photo", + "preset": "resource_url_upload", + "form_placeholder": "http://example.com/my-camel-photo.jpg", + "upload_label": "Photo" + }, + { + "field_name": "camels_in_photo", + "label": "Camels in Photo", + "validators": "ignore_missing int_validator", + "form_placeholder": "eg. 2" + }, + { + "field_name": "others_in_photo", + "label": "Other Thing in Photo", + "output_validators": "ignore_missing" + }, + { + "field_name": "date", + "label": "Date", + "preset": "date" + }, + { + "field_name": "datetime", + "label": "Date Taken", + "label_time": "Time Taken", + "preset": "datetime" + }, + { + "field_name": "datetime_tz", + "label": "Date Taken", + "label_time": "Time Taken", + "preset": "datetime_tz" + }, + { + "label": "Example JSON Resource", + "field_name": "a_resource_json_field", + "preset": "json_object" + } + ] +} diff --git a/test.ini b/test.ini index de519f3..3d1e3dc 100644 --- a/test.ini +++ b/test.ini @@ -15,7 +15,7 @@ use = config:../ckan/test-core.ini # tests here. ckan.plugins = scheming_datasets mapactionschemas -scheming.dataset_schemas = ckanext.mapactionschemas:dataset.json ckanext.mapactiongeorss.tests:test_schema.json +scheming.dataset_schemas = ckanext.mapactionschemas:dataset.json ckanext.mapactiongeorss.tests:test_schema.json ckanext.mapactiongeorss.tests:default.json scheming.presets = ckanext.scheming:presets.json ckanext.mapactionschemas:presets.json scheming.dataset_fallback = false