From 43fdb6fc78a4232a62c41c4d482b9e07fd64ee1d Mon Sep 17 00:00:00 2001 From: Luccas Mateus Date: Tue, 10 Dec 2024 08:42:09 -0300 Subject: [PATCH] Tests --- ckan-backend-dev/docker-compose.dev.yml | 4 +- ckan-backend-dev/docker-compose.test.yml | 4 +- ckan-backend-dev/solr/Dockerfile | 57 +++ .../src/ckanext-wri/ckanext/wri/plugin.py | 4 +- .../ckanext/wri/tests/test_location_search.py | 476 ++++++++++++------ .../datasets/admin/EditDatasetForm.tsx | 26 +- .../datasets/admin/metadata/LocationForm.tsx | 4 +- deployment/frontend/src/schema/ckan.schema.ts | 1 + .../frontend/src/schema/dataset.schema.ts | 2 +- deployment/frontend/src/utils/apiUtils.ts | 2 +- 10 files changed, 410 insertions(+), 170 deletions(-) create mode 100644 ckan-backend-dev/solr/Dockerfile diff --git a/ckan-backend-dev/docker-compose.dev.yml b/ckan-backend-dev/docker-compose.dev.yml index b7cb72587..6cd6dd080 100755 --- a/ckan-backend-dev/docker-compose.dev.yml +++ b/ckan-backend-dev/docker-compose.dev.yml @@ -136,7 +136,9 @@ services: solr: container_name: ${SOLR_CONTAINER_NAME} - image: ckan/ckan-solr:${SOLR_IMAGE_VERSION} + #image: ckan/ckan-solr:${SOLR_IMAGE_VERSION} + build: + context: solr/ volumes: - solr_data:/var/solr - ./ckan/setup/schema.xml:/opt/solr/server/solr/configsets/ckan/conf/managed-schema diff --git a/ckan-backend-dev/docker-compose.test.yml b/ckan-backend-dev/docker-compose.test.yml index b31c4e6a7..9f453b3bd 100755 --- a/ckan-backend-dev/docker-compose.test.yml +++ b/ckan-backend-dev/docker-compose.test.yml @@ -146,7 +146,9 @@ services: solr: container_name: ${SOLR_CONTAINER_NAME} - image: ckan/ckan-solr:${SOLR_IMAGE_VERSION} + #image: ckan/ckan-solr:${SOLR_IMAGE_VERSION} + build: + context: solr/ volumes: - solr_data:/var/solr - ./ckan/setup/schema.xml:/opt/solr/server/solr/configsets/ckan/conf/managed-schema diff --git a/ckan-backend-dev/solr/Dockerfile b/ckan-backend-dev/solr/Dockerfile new file mode 100644 index 000000000..c333eb1bb --- /dev/null +++ b/ckan-backend-dev/solr/Dockerfile @@ -0,0 +1,57 @@ +FROM solr:8 + +EXPOSE 8983 + +ARG CKAN_BRANCH="dev-v2.10" + +ENV SOLR_INSTALL="/opt/solr" +ENV SOLR_CONFIG_DIR="$SOLR_INSTALL/server/solr/configsets" +ENV SOLR_SCHEMA_FILE="$SOLR_CONFIG_DIR/ckan/conf/managed-schema" + +ARG JTS_VERSION="1.16.0" +ARG JTS_JAR_FILE="$SOLR_INSTALL/server/solr-webapp/webapp/WEB-INF/lib/jts-core-$JTS_VERSION.jar" + +USER root + +# Create a CKAN configset by copying the default one +RUN cp -R $SOLR_CONFIG_DIR/_default $SOLR_CONFIG_DIR/ckan + +# Update the schema +ADD https://raw.githubusercontent.com/ckan/ckan/$CKAN_BRANCH/ckan/config/solr/schema.xml $SOLR_SCHEMA_FILE + +# Install JTS JAR file +ADD https://repo1.maven.org/maven2/org/locationtech/jts/jts-core/$JTS_VERSION/jts-core-$JTS_VERSION.jar \ + $JTS_JAR_FILE +RUN chmod 644 $JTS_JAR_FILE + +# Add the spatial field type definitions and fields + +## RPT +ENV SOLR_RPT_FIELD_DEFINITION '' + +ENV SOLR_RPT_FIELD '' + +RUN sed -i "//a $SOLR_RPT_FIELD_DEFINITION" $SOLR_SCHEMA_FILE +RUN sed -i "//a $SOLR_RPT_FIELD" $SOLR_SCHEMA_FILE + +## BBox +ENV SOLR_BBOX_FIELDS ' \ + \ + \ + \ + ' + +RUN sed -i "//a $SOLR_BBOX_FIELDS" $SOLR_SCHEMA_FILE + + +RUN chmod 644 $SOLR_SCHEMA_FILE + +USER solr + +CMD ["sh", "-c", "solr-precreate ckan $SOLR_CONFIG_DIR/ckan"] diff --git a/ckan-backend-dev/src/ckanext-wri/ckanext/wri/plugin.py b/ckan-backend-dev/src/ckanext-wri/ckanext/wri/plugin.py index 5ba29784b..5fc9941db 100644 --- a/ckan-backend-dev/src/ckanext-wri/ckanext/wri/plugin.py +++ b/ckan-backend-dev/src/ckanext-wri/ckanext/wri/plugin.py @@ -427,7 +427,7 @@ def before_dataset_index(self, pkg_dict): if len(geometries) == 0: return pkg_dict merged_geom = shapely.ops.unary_union(geometries) - pkg_dict["spatial_geom"] = merged_geom + pkg_dict["spatial_geom"] = merged_geom.wkt else: pkg_dict = SolrSpatialFieldSearchBackend().index_dataset(pkg_dict) @@ -440,6 +440,8 @@ def before_dataset_index(self, pkg_dict): pkg_dict.pop("extras_spatial", None) pkg_dict.pop("spatial", None) + print("PACKAGE DICT", flush=True) + print(pkg_dict, flush=True) return pkg_dict def before_dataset_search(self, search_params): diff --git a/ckan-backend-dev/src/ckanext-wri/ckanext/wri/tests/test_location_search.py b/ckan-backend-dev/src/ckanext-wri/ckanext/wri/tests/test_location_search.py index 3623dd0fc..714437874 100644 --- a/ckan-backend-dev/src/ckanext-wri/ckanext/wri/tests/test_location_search.py +++ b/ckan-backend-dev/src/ckanext-wri/ckanext/wri/tests/test_location_search.py @@ -10,251 +10,423 @@ @mock.patch("ckan.plugins.toolkit.mail_user") -@pytest.mark.usefixtures(u'with_plugins', u'test_request_context') +@pytest.mark.usefixtures("with_plugins", "test_request_context") def test_location_search_1(mail_user): userobj = factories.Sysadmin() session = model.Session context = { - 'model': model, 'session': session, - 'user': userobj['name'], 'ignore_auth': True, - 'user_obj': userobj + "model": model, + "session": session, + "user": userobj["name"], + "ignore_auth": True, + "user_obj": userobj, } - context['auth_user_obj'] = model.User.get(context['user']) + context["auth_user_obj"] = model.User.get(context["user"]) organization_dict = factories.Organization() group_dict = factories.Group() dataset = { - 'type': 'dataset', - 'title': 'Test Dataset Schema', - 'name': 'test-dataset-schema', - 'url': 'http://example.com/dataset.json', - 'language': 'en', - 'owner_org': organization_dict['id'], - 'project': 'American Cities Climate Challenge: Renewables Accelerator (U.S. Energy)', - 'application': 'rw app', - 'groups': [{'id': group_dict['id']}], - 'technical_notes': 'http://example.com/technical_notes.pdf', - 'tag_string': 'economy,mental health,government', + "type": "dataset", + "title": "Test Dataset Schema", + "name": "test-dataset-schema", + "url": "http://example.com/dataset.json", + "language": "en", + "owner_org": organization_dict["id"], + "project": "American Cities Climate Challenge: Renewables Accelerator (U.S. Energy)", + "application": "rw app", + "groups": [{"id": group_dict["id"]}], + "technical_notes": "http://example.com/technical_notes.pdf", + "tag_string": "economy,mental health,government", # 'temporal_coverage_start': '2007', # 'temporal_coverage_end': '2011', - 'update_frequency': 'annually', - 'citation': 'Citation information', - 'visibility_type': 'private', - 'license_id': 'cc-by-4.0', - 'featured_dataset': True, - 'short_description': 'A short description of the dataset', - 'notes': 'Some useful notes about the data', - 'author': 'Joe Bloggs', - 'author_email': 'joe@example.com', - 'maintainer': 'Joe Bloggs', - 'maintainer_email': 'joe@example.com', - 'function': 'This data is used to...', - 'restrictions': 'This data is restricted to...', - 'reason_for_adding': 'This data is being added because...', - 'learn_more': 'https://example.com/learn_more.pdf', - 'cautions': 'This data should be used with caution because...', - 'methodology': 'A short methodology of the dataset' + "update_frequency": "annually", + "citation": "Citation information", + "visibility_type": "private", + "license_id": "cc-by-4.0", + "featured_dataset": True, + "short_description": "A short description of the dataset", + "notes": "Some useful notes about the data", + "author": "Joe Bloggs", + "author_email": "joe@example.com", + "maintainer": "Joe Bloggs", + "maintainer_email": "joe@example.com", + "function": "This data is used to...", + "restrictions": "This data is restricted to...", + "reason_for_adding": "This data is being added because...", + "learn_more": "https://example.com/learn_more.pdf", + "cautions": "This data should be used with caution because...", + "methodology": "A short methodology of the dataset", } try: - get_action('dataset_purge')( - context={'ignore_auth': True}, - data_dict={'id': dataset['name']} + get_action("dataset_purge")( + context={"ignore_auth": True}, data_dict={"id": dataset["name"]} ) except NotFound: pass - result_1 = get_action('package_create')( - context=context, - data_dict=dataset - ) + result_1 = get_action("package_create")(context=context, data_dict=dataset) - search_1 = get_action('package_search')( - context=context, - data_dict={'ext_location_q': '10,10', 'ext_address_q': "test"} - )['results'] + search_1 = get_action("package_search")( + context=context, data_dict={"ext_location_q": "10,10", "ext_address_q": "test"} + )["results"] assert len(search_1) == 0 try: - get_action('package_delete')( - context={'ignore_auth': True}, - data_dict={'id': dataset['name']} - ) + get_action("package_delete")( + context={"ignore_auth": True}, data_dict={"id": dataset["name"]} + ) except NotFound: - pass + pass + @mock.patch("ckan.plugins.toolkit.mail_user") -@pytest.mark.usefixtures(u'with_plugins', u'test_request_context') +@pytest.mark.usefixtures("with_plugins", "test_request_context") def test_location_search_2(mail_user): userobj = factories.Sysadmin() session = model.Session context = { - 'model': model, 'session': session, - 'user': userobj['name'], 'ignore_auth': True, - 'user_obj': userobj + "model": model, + "session": session, + "user": userobj["name"], + "ignore_auth": True, + "user_obj": userobj, } - context['auth_user_obj'] = model.User.get(context['user']) + context["auth_user_obj"] = model.User.get(context["user"]) organization_dict = factories.Organization() group_dict = factories.Group() dataset = { - 'type': 'dataset', - 'title': 'Test Dataset Schema', - 'name': 'test-dataset-schema', - 'url': 'http://example.com/dataset.json', - 'language': 'en', - 'owner_org': organization_dict['id'], - 'project': 'American Cities Climate Challenge: Renewables Accelerator (U.S. Energy)', - 'application': 'rw app', - 'groups': [{'id': group_dict['id']}], - 'technical_notes': 'http://example.com/technical_notes.pdf', - 'tag_string': 'economy,mental health,government', + "type": "dataset", + "title": "Test Dataset Schema", + "name": "test-dataset-schema", + "url": "http://example.com/dataset.json", + "language": "en", + "owner_org": organization_dict["id"], + "project": "American Cities Climate Challenge: Renewables Accelerator (U.S. Energy)", + "application": "rw app", + "groups": [{"id": group_dict["id"]}], + "technical_notes": "http://example.com/technical_notes.pdf", + "tag_string": "economy,mental health,government", # 'temporal_coverage_start': '2007', # 'temporal_coverage_end': '2011', - 'update_frequency': 'annually', - 'citation': 'Citation information', - 'visibility_type': 'private', - 'license_id': 'cc-by-4.0', - 'featured_dataset': True, - 'short_description': 'A short description of the dataset', - 'notes': 'Some useful notes about the data', - 'author': 'Joe Bloggs', - 'author_email': 'joe@example.com', - 'maintainer': 'Joe Bloggs', - 'maintainer_email': 'joe@example.com', - 'function': 'This data is used to...', - 'restrictions': 'This data is restricted to...', - 'reason_for_adding': 'This data is being added because...', - 'learn_more': 'https://example.com/learn_more.pdf', - 'cautions': 'This data should be used with caution because...', - 'methodology': 'A short methodology of the dataset' + "update_frequency": "annually", + "citation": "Citation information", + "visibility_type": "private", + "license_id": "cc-by-4.0", + "featured_dataset": True, + "short_description": "A short description of the dataset", + "notes": "Some useful notes about the data", + "author": "Joe Bloggs", + "author_email": "joe@example.com", + "maintainer": "Joe Bloggs", + "maintainer_email": "joe@example.com", + "function": "This data is used to...", + "restrictions": "This data is restricted to...", + "reason_for_adding": "This data is being added because...", + "learn_more": "https://example.com/learn_more.pdf", + "cautions": "This data should be used with caution because...", + "methodology": "A short methodology of the dataset", } dataset["name"] = "dataset-w-polygon" - dataset["spatial"] = json.dumps({"type":"Polygon","coordinates":[[[47.78942,8.003],[44.9636,5.00162],[43.66087,4.95755],[42.76967,4.25259],[42.12861,4.23413],[41.85508309264397,3.918911920483727],[41.1718,3.91909],[40.76848,4.25702],[39.85494,3.83879],[39.55938425876585,3.42206],[38.89251,3.50074],[38.67114,3.61607],[38.43697,3.58851],[38.120915,3.598605],[36.85509323800812,4.447864127672769],[36.159078632855646,4.447864127672769],[35.817447662353516,4.77696566346189],[35.817447662353516,5.338232082790797],[35.29800711823298,5.506],[34.70702,6.594220000000121],[34.25032,6.82607],[34.0751,7.22595],[33.568290000000104,7.71334],[32.95418,7.784970000000101],[33.29480000000012,8.35458],[33.82550000000015,8.37916],[33.97498,8.68456],[33.96162,9.58358],[34.25745,10.63009],[34.73115000000013,10.910170000000107],[34.83163000000013,11.318960000000118],[35.26049,12.08286],[35.86363,12.57828],[36.27022,13.563330000000121],[36.42951,14.42211],[37.59377,14.2131],[37.90607000000011,14.959430000000168],[38.51295,14.50547],[39.0994,14.74064],[39.34061,14.53155],[40.02625000000012,14.51959],[40.8966,14.118640000000141],[41.1552,13.77333],[41.59856,13.452090000000112],[42.00975,12.86582],[42.35156000000012,12.542230000000131],[42.000000000000114,12.100000000000136],[41.66176000000013,11.6312],[41.73959000000019,11.355110000000138],[41.755570000000205,11.050910000000101],[42.31414000000012,11.0342],[42.55493000000013,11.105110000000195],[42.77685184100096,10.92687856693442],[42.55876,10.57258000000013],[42.92812,10.021940000000143],[43.29699000000011,9.540480000000173],[43.67875,9.18358000000012],[46.94834,7.99688],[47.78942,8.003]]]}) + dataset["spatial"] = json.dumps( + { + "type": "Polygon", + "coordinates": [ + [ + [47.78942, 8.003], + [44.9636, 5.00162], + [43.66087, 4.95755], + [42.76967, 4.25259], + [42.12861, 4.23413], + [41.85508309264397, 3.918911920483727], + [41.1718, 3.91909], + [40.76848, 4.25702], + [39.85494, 3.83879], + [39.55938425876585, 3.42206], + [38.89251, 3.50074], + [38.67114, 3.61607], + [38.43697, 3.58851], + [38.120915, 3.598605], + [36.85509323800812, 4.447864127672769], + [36.159078632855646, 4.447864127672769], + [35.817447662353516, 4.77696566346189], + [35.817447662353516, 5.338232082790797], + [35.29800711823298, 5.506], + [34.70702, 6.594220000000121], + [34.25032, 6.82607], + [34.0751, 7.22595], + [33.568290000000104, 7.71334], + [32.95418, 7.784970000000101], + [33.29480000000012, 8.35458], + [33.82550000000015, 8.37916], + [33.97498, 8.68456], + [33.96162, 9.58358], + [34.25745, 10.63009], + [34.73115000000013, 10.910170000000107], + [34.83163000000013, 11.318960000000118], + [35.26049, 12.08286], + [35.86363, 12.57828], + [36.27022, 13.563330000000121], + [36.42951, 14.42211], + [37.59377, 14.2131], + [37.90607000000011, 14.959430000000168], + [38.51295, 14.50547], + [39.0994, 14.74064], + [39.34061, 14.53155], + [40.02625000000012, 14.51959], + [40.8966, 14.118640000000141], + [41.1552, 13.77333], + [41.59856, 13.452090000000112], + [42.00975, 12.86582], + [42.35156000000012, 12.542230000000131], + [42.000000000000114, 12.100000000000136], + [41.66176000000013, 11.6312], + [41.73959000000019, 11.355110000000138], + [41.755570000000205, 11.050910000000101], + [42.31414000000012, 11.0342], + [42.55493000000013, 11.105110000000195], + [42.77685184100096, 10.92687856693442], + [42.55876, 10.57258000000013], + [42.92812, 10.021940000000143], + [43.29699000000011, 9.540480000000173], + [43.67875, 9.18358000000012], + [46.94834, 7.99688], + [47.78942, 8.003], + ] + ], + } + ) try: - get_action('dataset_purge')( - context={'ignore_auth': True}, - data_dict={'id': dataset['name']} + get_action("dataset_purge")( + context={"ignore_auth": True}, data_dict={"id": dataset["name"]} ) except NotFound: pass - result_1 = get_action('package_create')( - context=context, - data_dict=dataset - ) + result_1 = get_action("package_create")(context=context, data_dict=dataset) - search_1 = get_action('package_search')( - context=context, - data_dict={'ext_location_q': '10,10', 'ext_address_q': "test"} - )['results'] + search_1 = get_action("package_search")( + context=context, data_dict={"ext_location_q": "10,10", "ext_address_q": "test"} + )["results"] assert len(search_1) == 0 - search_2 = get_action('package_search')( - context=context, - data_dict={'ext_location_q': '9,40', 'ext_address_q': ""} - )['results'] + search_2 = get_action("package_search")( + context=context, data_dict={"ext_location_q": "9,40", "ext_address_q": ""} + )["results"] - assert any(result['name'] == dataset['name'] for result in search_2) + assert any(result["name"] == dataset["name"] for result in search_2) try: - get_action('package_delete')( - context={'ignore_auth': True}, - data_dict={'id': dataset['name']} + get_action("package_delete")( + context={"ignore_auth": True}, data_dict={"id": dataset["name"]} ) except NotFound: pass + @mock.patch("ckan.plugins.toolkit.mail_user") -@pytest.mark.usefixtures(u'with_plugins', u'test_request_context') +@pytest.mark.usefixtures("with_plugins", "test_request_context") def test_location_search_3(mail_user): userobj = factories.Sysadmin() session = model.Session context = { - 'model': model, 'session': session, - 'user': userobj['name'], 'ignore_auth': True, - 'user_obj': userobj + "model": model, + "session": session, + "user": userobj["name"], + "ignore_auth": True, + "user_obj": userobj, } - context['auth_user_obj'] = model.User.get(context['user']) + context["auth_user_obj"] = model.User.get(context["user"]) organization_dict = factories.Organization() group_dict = factories.Group() dataset = { - 'type': 'dataset', - 'title': 'Test Dataset Schema', - 'name': 'test-dataset-schema', - 'url': 'http://example.com/dataset.json', - 'language': 'en', - 'owner_org': organization_dict['id'], - 'project': 'American Cities Climate Challenge: Renewables Accelerator (U.S. Energy)', - 'application': 'rw app', - 'groups': [{'id': group_dict['id']}], - 'technical_notes': 'http://example.com/technical_notes.pdf', - 'tag_string': 'economy,mental health,government', + "type": "dataset", + "title": "Test Dataset Schema", + "name": "test-dataset-schema", + "url": "http://example.com/dataset.json", + "language": "en", + "owner_org": organization_dict["id"], + "project": "American Cities Climate Challenge: Renewables Accelerator (U.S. Energy)", + "application": "rw app", + "groups": [{"id": group_dict["id"]}], + "technical_notes": "http://example.com/technical_notes.pdf", + "tag_string": "economy,mental health,government", # 'temporal_coverage_start': '2007', # 'temporal_coverage_end': '2011', - 'update_frequency': 'annually', - 'citation': 'Citation information', - 'visibility_type': 'private', - 'license_id': 'cc-by-4.0', - 'featured_dataset': True, - 'short_description': 'A short description of the dataset', - 'notes': 'Some useful notes about the data', - 'author': 'Joe Bloggs', - 'author_email': 'joe@example.com', - 'maintainer': 'Joe Bloggs', - 'maintainer_email': 'joe@example.com', - 'function': 'This data is used to...', - 'restrictions': 'This data is restricted to...', - 'reason_for_adding': 'This data is being added because...', - 'learn_more': 'https://example.com/learn_more.pdf', - 'cautions': 'This data should be used with caution because...', - 'methodology': 'A short methodology of the dataset' + "update_frequency": "annually", + "citation": "Citation information", + "visibility_type": "private", + "license_id": "cc-by-4.0", + "featured_dataset": True, + "short_description": "A short description of the dataset", + "notes": "Some useful notes about the data", + "author": "Joe Bloggs", + "author_email": "joe@example.com", + "maintainer": "Joe Bloggs", + "maintainer_email": "joe@example.com", + "function": "This data is used to...", + "restrictions": "This data is restricted to...", + "reason_for_adding": "This data is being added because...", + "learn_more": "https://example.com/learn_more.pdf", + "cautions": "This data should be used with caution because...", + "methodology": "A short methodology of the dataset", } dataset["name"] = "dataset-w-address" dataset["spatial_address"] = "Sao Paulo, Sao Paulo, Brazil" try: - get_action('dataset_purge')( - context={'ignore_auth': True}, - data_dict={'id': dataset['name']} + get_action("dataset_purge")( + context={"ignore_auth": True}, data_dict={"id": dataset["name"]} ) except NotFound: pass - result_1 = get_action('package_create')( - context=context, - data_dict=dataset - ) + result_1 = get_action("package_create")(context=context, data_dict=dataset) - search_1 = get_action('package_search')( - context=context, - data_dict={'ext_location_q': '10,10', 'ext_address_q': "test"} - )['results'] + search_1 = get_action("package_search")( + context=context, data_dict={"ext_location_q": "10,10", "ext_address_q": "test"} + )["results"] assert len(search_1) == 0 - #search_3 = get_action('package_search')( + # search_3 = get_action('package_search')( # context=context, # data_dict={'ext_location_q': '0,0', 'ext_address_q': "Brazil"} - #)['results'] + # )['results'] + + # assert any(result['name'] == dataset['name'] for result in search_3) + + try: + get_action("package_delete")( + context={"ignore_auth": True}, data_dict={"id": dataset["name"]} + ) + except NotFound: + pass + + +@mock.patch("ckan.plugins.toolkit.mail_user") +@pytest.mark.usefixtures("with_plugins", "test_request_context") +def test_location_search_4(mail_user): + userobj = factories.Sysadmin() + session = model.Session + context = { + "model": model, + "session": session, + "user": userobj["name"], + "ignore_auth": True, + "user_obj": userobj, + } + context["auth_user_obj"] = model.User.get(context["user"]) - #assert any(result['name'] == dataset['name'] for result in search_3) + organization_dict = factories.Organization() + group_dict = factories.Group() + + dataset = { + "type": "dataset", + "title": "Test Dataset Schema", + "name": "test-dataset-schema", + "url": "http://example.com/dataset.json", + "language": "en", + "owner_org": organization_dict["id"], + "project": "American Cities Climate Challenge: Renewables Accelerator (U.S. Energy)", + "application": "rw app", + "groups": [{"id": group_dict["id"]}], + "technical_notes": "http://example.com/technical_notes.pdf", + "tag_string": "economy,mental health,government", + # 'temporal_coverage_start': '2007', + # 'temporal_coverage_end': '2011', + "update_frequency": "annually", + "citation": "Citation information", + "visibility_type": "private", + "license_id": "cc-by-4.0", + "featured_dataset": True, + "short_description": "A short description of the dataset", + "spatial_type": "derived_from_resources", + "notes": "Some useful notes about the data", + "author": "Joe Bloggs", + "author_email": "joe@example.com", + "maintainer": "Joe Bloggs", + "maintainer_email": "joe@example.com", + "function": "This data is used to...", + "restrictions": "This data is restricted to...", + "reason_for_adding": "This data is being added because...", + "learn_more": "https://example.com/learn_more.pdf", + "cautions": "This data should be used with caution because...", + "methodology": "A short methodology of the dataset", + "resources": [ + { + "url": "http://example.com/dataset.json", + "format": "json", + "name": "Test Dataset Schema", + "spatial_geom": { + "type": "Feature", + "geometry": { + "type": "Polygon", + "coordinates": [ + [[-40, 0], [-30, 0], [-30, -10], [-40, -10], [-40, 0]] + ], + }, + }, + }, + { + "url": "http://example.com/dataset.json", + "format": "json", + "name": "Test Dataset Schema", + "spatial_geom": { + "type": "Feature", + "geometry": { + "type": "Polygon", + "coordinates": [ + [[20, 0], [30, 0], [30, -10], [20, -10], [20, 0]] + ], + }, + }, + }, + ], + } + dataset["name"] = "dataset-z-address" try: - get_action('package_delete')( - context={'ignore_auth': True}, - data_dict={'id': dataset['name']} + get_action("dataset_purge")( + context={"ignore_auth": True}, data_dict={"id": dataset["name"]} ) except NotFound: pass + result_1 = get_action("package_create")(context=context, data_dict=dataset) + + search_1 = get_action("package_search")( + context=context, data_dict={"ext_location_q": "10,10", "ext_address_q": "test"} + )["results"] + + assert len(search_1) == 0 + + search_2 = get_action("package_search")( + context=context, data_dict={"ext_location_q": "-8,-35", "ext_address_q": ""} + )["results"] + + assert any(result["name"] == dataset["name"] for result in search_2) + + search_3 = get_action("package_search")( + context=context, data_dict={"ext_location_q": "-4,15", "ext_address_q": ""} + )["results"] + + assert any(result["name"] == dataset["name"] for result in search_3) + + try: + get_action("package_delete")( + context={"ignore_auth": True}, data_dict={"id": dataset["name"]} + ) + except NotFound: + pass diff --git a/deployment/frontend/src/components/dashboard/datasets/admin/EditDatasetForm.tsx b/deployment/frontend/src/components/dashboard/datasets/admin/EditDatasetForm.tsx index df9f4296e..2860425be 100644 --- a/deployment/frontend/src/components/dashboard/datasets/admin/EditDatasetForm.tsx +++ b/deployment/frontend/src/components/dashboard/datasets/admin/EditDatasetForm.tsx @@ -162,12 +162,16 @@ export default function EditDatasetForm({ dataset }: { dataset: WriDataset }) { (option) => option.value === dataset.language ), topics: dataset.groups - //@ts-ignore - ? dataset.groups.filter(g => g.type === 'group').map((group) => group.name) + ? //@ts-ignore + dataset.groups + .filter((g) => g.type === 'group') + .map((group) => group.name) : [], applications: dataset.groups - //@ts-ignore - ? dataset.groups.filter(g => g.type === 'application').map((group) => group.name) + ? //@ts-ignore + dataset.groups + .filter((g) => g.type === 'application') + .map((group) => group.name) : [], team: dataset.organization ? { @@ -205,17 +209,17 @@ export default function EditDatasetForm({ dataset }: { dataset: WriDataset }) { schema: resource.schema ? schema.value : undefined, } }), - spatial_type: - dataset.spatial_address === 'Global' - ? 'global' - : dataset.spatial_address + spatial_type: dataset.spatial_type + ? dataset.spatial_type as "address" | "geom" | "global" | "derived_from_resources" + : dataset.spatial_address === 'Global' + ? 'global' + : dataset.spatial_address ? 'address' : dataset.spatial - ? 'geom' - : undefined, + ? 'geom' + : undefined, }, }) - console.log('ERRORS', formObj.formState.errors) const editDataset = api.dataset.editDataset.useMutation({ onSuccess: async ({ title, name, visibility_type }) => { diff --git a/deployment/frontend/src/components/dashboard/datasets/admin/metadata/LocationForm.tsx b/deployment/frontend/src/components/dashboard/datasets/admin/metadata/LocationForm.tsx index 31a8c1f96..f042dc5ff 100644 --- a/deployment/frontend/src/components/dashboard/datasets/admin/metadata/LocationForm.tsx +++ b/deployment/frontend/src/components/dashboard/datasets/admin/metadata/LocationForm.tsx @@ -134,7 +134,7 @@ export function LocationForm({ : setValue('spatial', undefined) setValue('spatial_type', 'geom') - setValue('spatial_address', undefined) + setValue('spatial_address', null) }} id="tabUpload" className={classNames( @@ -211,7 +211,7 @@ export function LocationForm({ 'derived_from_resources' ) setValue(`spatial`, undefined) - setValue(`spatial_address`, undefined) + setValue(`spatial_address`, null) }} > {({ selected }) => ( diff --git a/deployment/frontend/src/schema/ckan.schema.ts b/deployment/frontend/src/schema/ckan.schema.ts index 42f7e7dea..bc8c66c1c 100644 --- a/deployment/frontend/src/schema/ckan.schema.ts +++ b/deployment/frontend/src/schema/ckan.schema.ts @@ -134,6 +134,7 @@ export interface WriDataset extends Dataset { extras?: Extra[] spatial?: any spatial_address?: string + spatial_type?: string connectorUrl?: string connectorType?: string provider?: string diff --git a/deployment/frontend/src/schema/dataset.schema.ts b/deployment/frontend/src/schema/dataset.schema.ts index 63527d4e2..cd54c6f77 100644 --- a/deployment/frontend/src/schema/dataset.schema.ts +++ b/deployment/frontend/src/schema/dataset.schema.ts @@ -216,7 +216,7 @@ const DatasetSchemaObject = z.object({ ), resources: z.array(ResourceSchema), collaborators: z.array(CollaboratorSchema).default([]), - spatial_address: z.string().optional(), + spatial_address: z.string().optional().nullable(), spatial: z.any().optional(), spatial_type: z.enum(['address', 'geom', 'global', 'derived_from_resources']).optional(), release_notes: z.string().optional(), diff --git a/deployment/frontend/src/utils/apiUtils.ts b/deployment/frontend/src/utils/apiUtils.ts index cc31a76bc..fe3f3b918 100644 --- a/deployment/frontend/src/utils/apiUtils.ts +++ b/deployment/frontend/src/utils/apiUtils.ts @@ -2269,7 +2269,6 @@ export async function approvePendingDataset( const layer = layerFilter[0]! if (!submittedDataset.rw_id && isLayer && layer) { - console.log('FAILED HERE 4') const rwDataset = { title: submittedDataset.title! ?? '', connectorType: layer.connectorType!, @@ -2383,6 +2382,7 @@ export async function approvePendingDataset( } ) const dataset = (await datasetRes.json()) as CkanResponse + console.log('DATASET UPDATED', dataset) if (!dataset.success && dataset.error) { if (dataset.error.message) throw Error(