Skip to content

Commit

Permalink
[c2f,bug,#33][s]: Add test against empty keywords
Browse files Browse the repository at this point in the history
* Add test_ckan_round_trip_does_not_generate_empty_keywords.
* Do not create empty list of `keywords` when tags are empty.
  • Loading branch information
Sebastien Lavoie committed Jul 14, 2020
1 parent b6feb94 commit 4c30eba
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions frictionless_ckan_mapper/ckan_to_frictionless.py
Expand Up @@ -111,6 +111,8 @@ def dataset(ckandict):
if 'tags' in ckandict:
outdict['keywords'] = [tag['name'] for tag in ckandict['tags']]
del outdict['tags']
if outdict.get("keywords") == []:
del outdict["keywords"]

# author, maintainer => contributors
# what to do if contributors already there? Options:
Expand Down
1 change: 0 additions & 1 deletion tests/fixtures/full_ckan_package_first_round_trip.json
Expand Up @@ -34,7 +34,6 @@
"type": "dataset",
"version": "",
"url": "",
"keywords": [],
"extras": [
{
"key": "creator_user_id",
Expand Down
15 changes: 15 additions & 0 deletions tests/test_roundtrip.py
Expand Up @@ -59,3 +59,18 @@ def test_differences_ckan_round_trip(self):
# - Keys defined in CKAN but ignored in Frictionless, such as `id`
# (because a Frictionless package doesn't have an id property) will
# also go to 'extras'.

def test_ckan_round_trip_does_not_generate_empty_keywords(self):
'''When CKAN does not have `tags`, it should not create the empty
`keywords` list in a Frictionless package. This would lead to a round
trip where `tags` is also not there nor empty.'''
ckan1 = {
"x": "yyy",
"tags": []
}
exp_fd1 = {"x": "yyy"}
fd1 = ckan_to_frictionless.dataset(ckan1)
assert fd1 == exp_fd1
ckan2 = frictionless_to_ckan.package(fd1)
exp_ckan2 = {'extras': [{'key': 'x', 'value': 'yyy'}]}
assert ckan2 == exp_ckan2

0 comments on commit 4c30eba

Please sign in to comment.