Skip to content

Commit 8cc5f0f

Browse files
committed
When creating or updating a resource that doesn't have an id, if you supply a parameter dataset, then the resource will be assigned to that dataset and it will be compared to resources in that dataset. If a match is found, then the resource will be given the corresponding id and that resource on HDX will be overwritten.
1 parent be7a5b6 commit 8cc5f0f

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

documentation/index.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,13 @@ The built-in configuration assumes data will be of form similar to below:
899899

900900
## Resource Specific Operations
901901

902+
When creating or updating a resource that doesn't have an id, if you supply a parameter
903+
dataset, then the resource will be assigned to that dataset and it will be compared to
904+
resources in that dataset. If a match is found, then the resource will be given the
905+
corresponding id and that resource on HDX will be overwritten.
906+
907+
resource.create_in_hdx(dataset=DATASET)
908+
902909
You can download a resource using the **download** function eg.
903910

904911
url, path = resource.download("FOLDER_TO_DOWNLOAD_TO")

tests/hdx/data/test_resource.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from .. import MockResponse, dataset_resultdict, resource_data
1313
from .test_resource_view import resource_view_list, resource_view_mocklist
1414
from hdx.api.configuration import Configuration
15+
from hdx.data.dataset import Dataset
1516
from hdx.data.hdxobject import HDXError
1617
from hdx.data.resource import Resource
1718
from hdx.utilities.dateparse import parse_date
@@ -1068,3 +1069,16 @@ def test_get_api_url(self, configuration, read):
10681069
)
10691070
del resource["id"]
10701071
assert resource.get_api_url() is None
1072+
1073+
def test_get_resource_id(self, configuration, read):
1074+
resources = [
1075+
{"id": "abcd", "name": "test_resource", "format": "CSV"},
1076+
{"id": "efgh", "name": "test_resource2", "format": "CSV"},
1077+
{"id": "ijkl", "name": "test_resource2", "format": "XLSX"},
1078+
]
1079+
dataset = Dataset({"id": "1234", "name": "test_dataset", "format": "CSV"})
1080+
dataset.add_update_resources(resources)
1081+
1082+
resource = Resource({"name": "test_resource2", "format": "CSV"})
1083+
result = resource._get_resource_id(dataset=dataset)
1084+
assert result == "efgh"

0 commit comments

Comments
 (0)