OCHA-DAP / hdx-python-api

Python API for interacting with the HDX Data Portal
http://data.humdata.org
MIT License
80 stars 16 forks source link

move client slide location validation to a separate module #14

Closed bdon closed 7 years ago

bdon commented 7 years ago

Having worked with this library a bit more, it made more sense to remove the fetching and validation of locations from the main Configuration object. This could be replaced by a separate import e.g.

from hdx.locations import get_valid_locations
locations = get_valid_locations(configuration) #makes a network call to appropriate HDX endpoint
if some_code not in locations:

This way the control over how network requests is made, or how the list of locations is cached, is the responsibility of the library user. If the locations is a plain python List this means it can also be replaced by a test object without patching or deep mocks

mcarans commented 7 years ago

I could create a new class hdx.locations, put location config in it and also the HDX specific functions that are currently in hdx.utilities.location (the class that is there I would probably remove and just leave a few non-HDX specific functions).

mcarans commented 7 years ago

I have released a new version of HDX Python with this change. Please close this if all is well.

bdon commented 7 years ago

I am running into problems on this latest release (2.1.2):

1) dataset "maintainer" seems required now, can this match "owner_org" ? 2) client side validation of a dataset fails when it is created without any resources. However in our application it is important that a dataset can be created first, and resources can be added later.

Are either of these specific to the new version of CKAN?

bdon commented 7 years ago

I am not sure of the value of "Maintainer". for owner_org we use a UUID that corresponds to the organization. In our case we don't have any individual appropriate to set as "Maintainer" since it's a bot uploading datasets. Passing the UUID of the owner_org as "Maintainer" does work, but inspecting the field in the HDX Edit Dataset UI doesn't seem to make sense (it doesn't link that UUID to a user or organization account).

mcarans commented 7 years ago

I have added an allow_no_resources flag to dataset.create_in_hdx. By default it is False. For your purposes, you can set it to True. Let me know if this works ok for you.

The omission of maintainer as mandatory was a long standing mistake as it is mandatory in the UI and by default set to the logged in user. It should be the person to contact if something needs to be asked about the dataset (and that person must have an account on HDX and be part of your organization). It is an HDX Username (which can be found under profile for the user on HDX). You could set it to the bot's user if you are for example ok with receiving emails at the bot's email address.

NB: Test suite is pytest