Skip to content

Commit

Permalink
consistent parameters between API and SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
Guts committed Apr 5, 2018
1 parent 55bbff7 commit 7189ad4
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 84 deletions.
22 changes: 11 additions & 11 deletions isogeo_pysdk/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,10 @@ def _check_filter_specific_tag(self, specific_tag):
raise TypeError("'specific_tag' expects a list")
return specific_tag

def _check_filter_sub_resources(self, sub_resources, resource="metadata"):
def _check_filter_includes(self, includes, resource="metadata"):
"""Check if specific_resources parameter is valid.
:param list sub_resources: sub resources to check
:param list includes: sub resources to check
:param str resource: resource type to check sub resources.
Must be one of: metadata | keyword.
"""
Expand All @@ -392,17 +392,17 @@ def _check_filter_sub_resources(self, sub_resources, resource="metadata"):
raise ValueError("Must be one of: metadata | keyword.")

# sub resources manager
if isinstance(sub_resources, string_types)\
and sub_resources.lower() == "all":
sub_resources = ",".join(ref_subresources)
elif isinstance(sub_resources, list):
if len(sub_resources) > 0:
sub_resources = ",".join(sub_resources)
if isinstance(includes, string_types)\
and includes.lower() == "all":
includes = ",".join(ref_subresources)
elif isinstance(includes, list):
if len(includes) > 0:
includes = ",".join(includes)
else:
sub_resources = ""
includes = ""
else:
raise TypeError("'sub_resources' expect a list or a str='all'")
return sub_resources
raise TypeError("'includes' expect a list or a str='all'")
return includes


# ##############################################################################
Expand Down
51 changes: 26 additions & 25 deletions isogeo_pysdk/isogeo_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def search(self,
offset=0,
share=None,
specific_md=[],
sub_resources=[],
include=[],
whole_share=True,
check=True,
augment=False,
Expand Down Expand Up @@ -279,7 +279,7 @@ def search(self,
from a specific results index
:param str share: share UUID to filter on
:param list specific_md: list of metadata UUIDs to filter on
:param list sub_resources: subresources that should be returned.
:param list include: subresources that should be returned.
Must be a list of strings. Available values: *isogeo.SUBRESOURCES*
:param str whole_share: option to return all results or only the
page size. *True* by DEFAULT.
Expand All @@ -299,11 +299,11 @@ def search(self,
specific_md = checker._check_filter_specific_md(specific_md)

# sub resources specific parsing
sub_resources = checker._check_filter_sub_resources(sub_resources)
include = checker._check_filter_includes(include)

# handling request parameters
payload = {'_id': specific_md,
'_include': sub_resources,
'_include': include,
'_lang': self.lang,
'_limit': page_size,
'_offset': offset,
Expand Down Expand Up @@ -373,14 +373,13 @@ def search(self,
# end of method
return search_rez

def resource(self, token, id_resource, sub_resources=[], prot="https"):
def resource(self, token, id_resource, include=[], prot="https"):
"""Get complete or partial metadata about one specific resource.
:param str token: API auth token
:param str id_resource: metadata UUID to get
:param list sub_resources: subresources that should be returned.
Must be a list of strings.
To get available values: 'isogeo.SUBRESOURCES'
:param list include: subresources that should be included.
Must be a list of strings. Available values: 'isogeo.SUBRESOURCES'
:param str prot: https [DEFAULT] or http
(use it only for dev and tracking needs).
"""
Expand All @@ -390,11 +389,11 @@ def resource(self, token, id_resource, sub_resources=[], prot="https"):
self.ct))

# sub resources specific parsing
sub_resources = checker._check_filter_sub_resources(sub_resources)
include = checker._check_filter_includes(include)

# handling request parameters
payload = {"id": id_resource,
"_include": sub_resources
"_include": include
}

# resource search
Expand Down Expand Up @@ -619,7 +618,7 @@ def keywords(self,
page_size=20,
specific_md=[],
specific_tag=[],
sub_resources=[],
include=[],
prot="https"):
"""Search for keywords within a specific thesaurus.
Expand All @@ -636,14 +635,14 @@ def keywords(self,
# specific resources specific parsing
specific_md = checker._check_filter_specific_md(specific_md)
# sub resources specific parsing
sub_resources = checker._check_filter_sub_resources(sub_resources,
"keyword")
include = checker._check_filter_includes(include,
"keyword")
# specific tag specific parsing
specific_tag = checker._check_filter_specific_tag(specific_tag)

# handling request parameters
payload = {'_id': specific_md,
'_include': sub_resources,
'_include': include,
'_limit': page_size,
'_offset': offset,
'_tag': specific_tag,
Expand Down Expand Up @@ -816,7 +815,6 @@ def get_app_properties(self, token, prot="https"):
:param str prot: https [DEFAULT] or http
(use it only for dev and tracking needs).
"""
mng_base_url = "https://manage.isogeo.com/applications/"
# checking bearer validity
token = checker.check_bearer_validity(token, self.connect(self.app_id,
self.ct))
Expand Down Expand Up @@ -973,7 +971,6 @@ def get_formats(self, token, format_code=None, prot="https"):
# ##############################################################################
# ##### Stand alone program ########
# ##################################

if __name__ == '__main__':
""" standalone execution """
# ------------ Specific imports ----------------
Expand All @@ -1000,22 +997,26 @@ def get_formats(self, token, format_code=None, prot="https"):
client_secret=share_token,
auth_mode="group",
lang="fr",
platform="qa"
# platform="qa"
)

# getting a token
token = isogeo.connect()
print(token)
# print(token)

# let's search for metadatas!
search = isogeo.search(token,
# sub_resources='all',
# sub_resources=["conditions", "contacts"],
# sub_resources=isogeo.SUBRESOURCES,
query="keyword:isogeo:2015\
type:dataset",
prot='https')
# search = isogeo.search(token,
# # sub_resources='all',
# # sub_resources=["conditions", "contacts"],
# # sub_resources=isogeo.SUBRESOURCES,
# query="keyword:isogeo:2015\
# type:dataset",
# prot='https')

isogeo.get_app_properties(token)
app = isogeo.app_properties
# print(app, type(app))
srs = isogeo.get_coordinate_systems(token)
print(len(srs), len(srs[0]), srs[0])
srs_4326 = isogeo.get_coordinate_systems(token, srs_code="4326")
print(len(srs_4326), srs_4326)
32 changes: 16 additions & 16 deletions tests/test_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,37 +267,37 @@ def test_check_edit_tab_bad(self):
checker.check_edit_tab(tab="attributes", md_type="service")

# requests parameters
def test_check_filter_sub_resources_ok(self):
def test_check_filter_includes_ok(self):
"""Check sub resources"""
# metadata sub resources - empty
subresources = checker._check_filter_sub_resources(sub_resources=[],
resource="metadata")
subresources = checker._check_filter_includes(includes=[],
resource="metadata")
self.assertIsInstance(subresources, string_types)
# metadata sub resources - 1
subresources = checker._check_filter_sub_resources(sub_resources=["links", ],
resource="metadata")
subresources = checker._check_filter_includes(includes=["links", ],
resource="metadata")
self.assertIsInstance(subresources, string_types)
# metadata sub resources - >1
subresources = checker._check_filter_sub_resources(sub_resources=["contacts", "links"],
resource="metadata")
subresources = checker._check_filter_includes(includes=["contacts", "links"],
resource="metadata")
self.assertIsInstance(subresources, string_types)
# metadata sub resources - all
subresources = checker._check_filter_sub_resources(sub_resources="all",
resource="metadata")
subresources = checker._check_filter_includes(includes="all",
resource="metadata")
self.assertIsInstance(subresources, string_types)
# keyword sub resources
subresources = checker._check_filter_sub_resources(sub_resources="all",
resource="keyword")
subresources = checker._check_filter_includes(includes="all",
resource="keyword")
self.assertIsInstance(subresources, string_types)

def test_check_filter_sub_resources_bad(self):
def test_check_filter_includes_bad(self):
"""Raise errors"""
with self.assertRaises(ValueError):
checker._check_filter_sub_resources(sub_resources="all",
resource="Metadata")
checker._check_filter_includes(includes="all",
resource="Metadata")
with self.assertRaises(TypeError):
checker._check_filter_sub_resources(sub_resources="layers",
resource="metadata")
checker._check_filter_includes(includes="layers",
resource="metadata")

def test_check_filter_specific_md_ok(self):
"""Check specific md"""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_download_hosted.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_dl_hosted(self):
"""Download an hosted data from Isogeo metadata."""
search = self.isogeo.search(self.bearer, whole_share=0,
query="action:download type:dataset",
sub_resources=["links", ],
include=["links", ],
page_size=100)
# get an hosted link
for md in search.get("results"):
Expand Down
16 changes: 8 additions & 8 deletions tests/test_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,33 +58,33 @@ def tearDown(self):
pass

# subresources
def test_keywords_subresources_ok(self):
def test_keywords_includes_ok(self):
"""Resource with a few sub resources."""
self.isogeo.keywords(self.bearer,
page_size=0,
sub_resources=["count", ],
include=["count", ],
)

def test_keywords_subresources_all_ok(self):
def test_keywords_includes_all_ok(self):
"""Resource with all sub resources."""
self.isogeo.keywords(self.bearer,
page_size=0,
sub_resources="all",
include="all",
)

def test_keywords_subresources_empty(self):
def test_keywords_includes_empty(self):
"""Resource with empty sub_resources list."""
self.isogeo.keywords(self.bearer,
page_size=0,
sub_resources=[],
include=[],
)

def test_keywords_subresources_bad(self):
def test_keywords_includes_bad(self):
"""Include sub_resources requires a list."""
with self.assertRaises(TypeError):
self.isogeo.keywords(self.bearer,
page_size=0,
sub_resources="count",
include="count",
)

# specific md
Expand Down
2 changes: 1 addition & 1 deletion tests/test_metadata_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def test_search_result_inspire_compliance(self):
# from a specific md. Can be viewed here: https://goo.gl/RDWDWJ
search = self.isogeo.search(self.bearer, whole_share=0,
specific_md=["3c649da21ed9405e8d508bfdbe831516",],
sub_resources=["contacts", ])
include=["contacts", ])
md = search.get("results")[0]
self.assertIsInstance(md, dict)

Expand Down
16 changes: 8 additions & 8 deletions tests/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,33 +57,33 @@ def tearDown(self):
pass

# subresources
def test_resource_subresources_ok(self):
def test_resource_includes_ok(self):
"""Resource with a few sub resources."""
self.isogeo.resource(self.bearer,
id_resource=self.md_rand.get("_id"),
sub_resources=["links", "contacts", ],
include=["links", "contacts", ],
)

def test_resource_subresources_all_ok(self):
def test_resource_includes_all_ok(self):
"""Resource with all sub resources."""
self.isogeo.resource(self.bearer,
id_resource=self.md_rand.get("_id"),
sub_resources="all",
include="all",
)

def test_resource_subresources_empty(self):
def test_resource_includes_empty(self):
"""Resource with empty sub_resources list."""
self.isogeo.resource(self.bearer,
id_resource=self.md_rand.get("_id"),
sub_resources=[],
include=[],
)

def test_resource_subresources_bad(self):
def test_resource_includes_bad(self):
"""Include sub_resrouces requires a list."""
with self.assertRaises(TypeError):
self.isogeo.resource(self.bearer,
id_resource=self.md_rand.get("_id"),
sub_resources="contacts",
include="contacts",
)


Expand Down
24 changes: 12 additions & 12 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,35 +133,35 @@ def test_search_specifc_mds_bad(self):
whole_share=0,
specific_md=md)

# subresources
def test_search_subresources_ok(self):
"""Searches including subresources."""
# includes
def test_search_includes_ok(self):
"""Searches including includes."""
self.isogeo.search(self.bearer,
page_size=0,
whole_share=0,
sub_resources=["links", "contacts", ])
include=["links", "contacts", ])

def test_search_subresources_all_ok(self):
"""Searches including subresources."""
def test_search_includes_all_ok(self):
"""Searches including includes."""
self.isogeo.search(self.bearer,
page_size=0,
whole_share=0,
sub_resources="all")
include="all")

def test_search_subresources_empty(self):
"""Search with empty sub_resources list."""
def test_search_includes_empty(self):
"""Search with empty includes list."""
self.isogeo.search(self.bearer,
page_size=0,
whole_share=0,
sub_resources=[])
include=[])

def test_search_subresources_bad(self):
def test_search_includes_bad(self):
"""Include sub_resrouces require a list."""
with self.assertRaises(TypeError):
self.isogeo.search(self.bearer,
page_size=0,
whole_share=0,
sub_resources="links")
include="links")

# query
def test_search_parameter_query_ok(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def setUp(self):
self.bearer = self.isogeo.connect()
self.md_contacts = self.isogeo.resource(self.bearer,
"e5e5ab788aff4418a1cd4a38f842ccbe",
sub_resources=["contacts"],
include=["contacts"],
)
self.li_contacts_roles = [i.get("role")
for i in self.md_contacts.get("contacts")]
Expand Down

0 comments on commit 7189ad4

Please sign in to comment.