Skip to content

Commit

Permalink
minor fixes in tag dictionarization test
Browse files Browse the repository at this point in the history
  • Loading branch information
Guts committed Aug 3, 2018
1 parent 009500f commit ba05437
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
5 changes: 3 additions & 2 deletions isogeo_pysdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def get_url_base_from_url_token(self, url_api_token="https://id.api.isogeo.com/o
return api_url_base.geturl()

# -- SEARCH --------------------------------------------------------------
def tags_to_dict(self, tags=dict, duplicated="ignore"):
def tags_to_dict(self, tags=dict, duplicated="rename"):
"""Reverse search tags dictionary to values as keys.
Useful to populate filters comboboxes for example.
Expand Down Expand Up @@ -412,7 +412,8 @@ def _duplicate_mng(target_dict, duplicate, mode=duplicated, workgroups=wgs):
tags_as_dicts.get("owners")[v] = k
continue
elif k.startswith("provider"):
tags_as_dicts.get("providers")[v] = k
# providers are particular bcause its value is always null.
tags_as_dicts.get("providers")[k.split(":")[1]] = k
continue
elif k.startswith("share"):
tags_as_dicts.get("shares")[v] = k
Expand Down
22 changes: 22 additions & 0 deletions tests/fixtures/out_api_search_tags_providers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"envelope": null,
"limit": 0,
"offset": 0,
"query": {
"_tags": [],
"_terms": []
},
"results": [],
"tags": {
"action:download": "Download",
"action:other": "Other",
"action:view": "View",
"provider:auto": null,
"provider:manual": null,
"type:raster-dataset": "Dataset (raster)",
"type:resource": "Resource",
"type:service": "Service",
"type:vector-dataset": "Dataset (vector)"
},
"total": 626
}
19 changes: 15 additions & 4 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
#!/usr/bin/env python
from __future__ import (absolute_import, print_function, unicode_literals)

"""
Usage from the repo root folder:
```python
python -m unittest tests.test_search
# for a specific test method
python -m unittest tests.test_search.TestSearch.test_search_tags_dictionarized
```
"""

# #############################################################################
# ########## Libraries #############
# ##################################
Expand Down Expand Up @@ -98,7 +108,7 @@ def test_search_length(self):
self.assertEqual(len(search_whole.get("results")), search_whole.get("total"))

# specific md
def test_search_specifc_mds_ok(self):
def test_search_specific_mds_ok(self):
"""Searches filtering on specific metadata."""
# get random metadata within a small search
search_10 = self.isogeo.search(self.bearer,
Expand All @@ -119,7 +129,7 @@ def test_search_specifc_mds_ok(self):
self.assertEqual(len(search_ids_2.get("results")), 2)
self.assertEqual(len(search_ids_3.get("results")), 2)

def test_search_specifc_mds_bad(self):
def test_search_specific_mds_bad(self):
"""Searches filtering on specific metadata."""
# get random metadata within a small search
search_5 = self.isogeo.search(self.bearer,
Expand Down Expand Up @@ -380,14 +390,15 @@ def test_search_tags_dictionarized(self):
continue
elif k.startswith("license"):
self.assertIn(v, tags_dicts.get("licenses"))
self.assertEqual(k, tags_dicts.get("licenses").get(v))
#self.assertEqual(k, tags_dicts.get("licenses").get(v))
continue
elif k.startswith("owner"):
self.assertIn(v, tags_dicts.get("owners"))
self.assertEqual(k, tags_dicts.get("owners").get(v))
continue
elif k.startswith("provider"):
self.assertIn(v, tags_dicts.get("providers"))
v = k.split(":")[1] # handle specific case of tags which are only a bool value
self.assertIn(k.split(":")[1], tags_dicts.get("providers"))
self.assertEqual(k, tags_dicts.get("providers").get(v))
continue
elif k.startswith("share"):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,15 +440,15 @@ def test_credentials_loader_bad_file_structure(self):

# -- Tags utils --------
def test_tags_dictionarization(self):
"""Tags dictionazition bullet-proof."""
"""Tags dictionarization bullet-proof."""
with open(self.tags_sample, "r") as f:
search = json.loads(f.read())
self.utils.tags_to_dict(search.get("tags"))
self.utils.tags_to_dict(search.get("tags"), duplicated="merge")
self.utils.tags_to_dict(search.get("tags"), duplicated="rename")

def test_tags_dictionarization_bad(self):
"""Tags dictionazition bullet-proof."""
"""Tags dictionarization bullet-proof."""
with open(self.tags_sample, "r") as f:
search = json.loads(f.read())
with self.assertRaises(ValueError):
Expand Down

0 comments on commit ba05437

Please sign in to comment.