Skip to content

Commit

Permalink
renaming route to keywords search
Browse files Browse the repository at this point in the history
  • Loading branch information
Guts committed Mar 31, 2018
1 parent fad82f7 commit 7b6d8f8
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 31 deletions.
59 changes: 35 additions & 24 deletions isogeo_pysdk/isogeo_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,18 +651,18 @@ def thesaurus(self, token, thez_id="1616597fbc4348c8b11ef9d59cf594c8", prot="htt
# end of method
return thez_req.json()

def keywords_thesaurus(self,
token,
thez_id,
query="",
offset=0,
order_by="text",
order_dir="desc",
page_size=20,
specific_md=None,
specific_tag=None,
sub_resources=[],
prot="https"):
def keywords(self,
token,
thez_id="1616597fbc4348c8b11ef9d59cf594c8",
query="",
offset=0,
order_by="text",
order_dir="desc",
page_size=20,
specific_md=[],
specific_tag=[],
sub_resources=[],
prot="https"):
"""Search for keywords within a specific thesaurus.
:param str token: API auth token
Expand All @@ -671,23 +671,34 @@ def keywords_thesaurus(self,
(use it only for dev and tracking needs).
"""
# checking bearer validity
token = checker.check_bearer_validity(token, self.connect(self.app_id, self.ct))
token = checker.check_bearer_validity(token,
self.connect(self.app_id,
self.ct))

# specific resources specific parsing
if type(specific_md) is list and len(specific_md) > 0:
specific_md = ",".join(specific_md)
elif specific_md is None:
specific_md = ""
if isinstance(specific_md, list):
if len(specific_md) > 0:
# checking UUIDs and poping bad ones
for md in specific_md:
if not checker.check_is_uuid(md):
specific_md.remove(md)
logging.error("Metadata UUID is not correct: {}"
.format(md))
# joining survivors
specific_md = ",".join(specific_md)
else:
specific_md = ""
else:
specific_md = ""
raise TypeError("'specific_md' expects a list")

# specific tags specific parsing
if type(specific_tag) is list and len(specific_tag) > 0:
specific_tag = ",".join(specific_tag)
elif specific_tag is None:
specific_tag = ""
# specific tag specific parsing
if isinstance(specific_tag, list):
if len(specific_tag) > 0:
specific_tag = ",".join(specific_tag)
else:
specific_tag = ""
else:
specific_tag = ""
raise TypeError("'specific_tag' expects a list")

# sub resources specific parsing
if isinstance(sub_resources, string_types)\
Expand Down
98 changes: 98 additions & 0 deletions tests/test_keywords.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# -*- coding: UTF-8 -*-
#!/usr/bin/env python
from __future__ import (absolute_import, print_function, unicode_literals)

# #############################################################################
# ########## Libraries #############
# ##################################

# Standard library
from os import environ
import logging
from random import randint
from sys import exit
import unittest

# module target
from isogeo_pysdk import Isogeo, __version__ as pysdk_version


# #############################################################################
# ######## Globals #################
# ##################################

# API access
app_id = environ.get('ISOGEO_API_DEV_ID')
app_secret = environ.get('ISOGEO_API_DEV_SECRET')

# #############################################################################
# ########## Classes ###############
# ##################################


class TestKeywords(unittest.TestCase):
"""Test request to unique resource."""
if not app_id or not app_secret:
logging.critical("No API credentials set as env variables.")
exit()
else:
pass
logging.debug('Isogeo PySDK version: {0}'.format(pysdk_version))

# standard methods
def setUp(self):
"""Executed before each test."""
self.isogeo = Isogeo(client_id=app_id,
client_secret=app_secret)
self.bearer = self.isogeo.connect()

# a random metadata
search = self.isogeo.search(self.bearer,
whole_share=0,
check=0)
self.md_rand = search.get("results")[randint(0, 99)]
self.thez_isogeo = "1616597fbc4348c8b11ef9d59cf594c8"

def tearDown(self):
"""Executed after each test."""
pass

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

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

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

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

# specific md

# specific tag

# ##############################################################################
# ##### Stand alone program ########
# ##################################
if __name__ == '__main__':
unittest.main()
17 changes: 10 additions & 7 deletions tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,14 @@ def test_licenses(self):
# get a workgroup id and a license within tags
for tag in search.get("tags"):
if tag.startswith("license:"):
lic = tag.split(":")[1]
continue
elif tag.startswith("owner:"):
lic = tag.split(":")[2]
else:
pass

if tag.startswith("owner:"):
wg = tag.split(":")[1]
continue
else:
pass

# get workgroup licenses
licenses = self.isogeo.licenses(self.bearer,
Expand All @@ -110,9 +113,9 @@ def test_keywords(self):
thez_id = self.isogeo.thesauri(self.bearer)[0]\
.get("_id")
# list tags
thez_keywords = self.isogeo.keywords_thesaurus(self.bearer,
thez_id=thez_id,
page_size=1)
thez_keywords = self.isogeo.keywords(self.bearer,
thez_id=thez_id,
page_size=1)
self.assertIsInstance(thez_keywords, dict)
self.assertIn("limit", thez_keywords)
self.assertIn("offset", thez_keywords)
Expand Down

0 comments on commit 7b6d8f8

Please sign in to comment.