Skip to content

Commit

Permalink
Release 1.0.2
Browse files Browse the repository at this point in the history
Release 1.0.2
Merge pull request #79 from EUDAT-B2SAFE/devel
  • Loading branch information
merretbuurman committed May 11, 2016
2 parents 121530c + 341ddb8 commit 9bab15a
Show file tree
Hide file tree
Showing 14 changed files with 520 additions and 225 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
The b2handle Python library is a client library for interaction with a [Handle System](https://handle.net) server, using the native REST interface introduced in Handle System 8. The library offers methods to create, update and delete Handles as well as advanced functionality such as searching over Handles using an additional search servlet and managing multiple location entries per Handle.

The library currently supports Python 2.6 and Python 2.7 and requires at least a Handle System server 8.1.
The library requires OpenSSL v1.0.1 or higher.

# Installation and use

Expand Down
10 changes: 6 additions & 4 deletions b2handle/handleclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,19 @@ def __init__(self, handle_server_url=None, **args):
:param REST_API_url_extension: Optional. The extension of a Handle
Server's URL to access its REST API. Defaults to '/api/handles/'.
:param allowed_search_keys: Optional. The keys that can be used for
reverse lookup of handles, as a list of strings. Defaults to 'url'
and 'checksum'. If the list is empty, all keys are passed to the
reverse lookup of handles, as a list of strings. Defaults to 'URL'
and 'CHECKSUM'. If the list is empty, all keys are passed to the
reverse lookup servlet and exceptions are passed on to the user.
:param 10320LOC_chooseby: Optional. The value to give to a handle
record's 10320/LOC entry's 'chooseby' attribute as string (e.g.
'locatt,weighted'). Defaults to None (attribute not set).
:param modify_HS_ADMIN: Optional. Advanced usage. Determines whether
the HS_ADMIN handle record entry can be modified using this library.
Defaults to False and should not be modified.
:param HTTPS_verify: Optional. If set to False, the certificate is not
verified in HTTP requests. Defaults to True.
:param HTTPS_verify: Optional. This parameter can have three values.
'True', 'False' or 'the path to a CA_BUNDLE file or directory with
certificates of trusted CAs'. If set to False, the certificate is
not verified in HTTP requests. Defaults to True.
:param reverselookup_baseuri: Optional. The base URL of the reverse
lookup service. If not set, the handle server base URL is used.
:param reverselookup_url_extension: Optional. The path to append to
Expand Down
18 changes: 13 additions & 5 deletions b2handle/searcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,16 @@ def search_handle(self, **args):
msg = 'No search terms have been specified. Please specify'+\
' at least one key-value-pair.'
raise ReverseLookupException(msg=msg)
else:
isnone = util.return_keys_of_value_none(args)
if len(isnone) > 0:
LOGGER.debug('search_handle: These keys had value None: '+str(isnone))
args = util.remove_value_none_from_dict(args)
if len(args) == 0:
LOGGER.debug('search_handle: No key value pair with valid value was specified.')
msg = ('No search terms have been specified. Please specify'
' at least one key-value-pair.')
raise ReverseLookupException(msg=msg)

# Perform the search:
list_of_handles = []
Expand Down Expand Up @@ -286,22 +296,20 @@ def create_revlookup_query(self, *fulltext_searchterms, **keyvalue_searchterms):
only_search_for_allowed_keys = True

fulltext_searchterms_given = True
fulltext_searchterms = util.remove_value_none_from_list(fulltext_searchterms)
if len(fulltext_searchterms) == 0:
fulltext_searchterms_given = False
if len(fulltext_searchterms) == 1 and fulltext_searchterms[0] is None:
fulltext_searchterms_given = False

if fulltext_searchterms_given:
msg = 'Full-text search is not implemented yet.'+\
' The provided searchterms '+str(fulltext_searchterms)+\
' can not be used.'
raise ReverseLookupException(msg=msg)

keyvalue_searchterms_given = True
keyvalue_searchterms = util.remove_value_none_from_dict(keyvalue_searchterms)
if len(keyvalue_searchterms) == 0:
keyvalue_searchterms_given = False
if len(keyvalue_searchterms) == 1 and\
keyvalue_searchterms.itervalues().next() is None:
keyvalue_searchterms_given = False

if not keyvalue_searchterms_given and not fulltext_searchterms_given:
msg = 'No search terms have been specified. Please specify'+\
Expand Down
20 changes: 20 additions & 0 deletions b2handle/tests/handleclient_search_noaccess_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,26 @@ def test_create_revlookup_query_normal(self):
self.assertEqual(query, '?URL=foo',
'The query is: '+query)

def test_create_revlookup_query_normal_checksum(self):
query = self.searcher.create_revlookup_query(CHECKSUM='foo')
self.assertEqual(query, '?CHECKSUM=foo',
'The query is: '+query)

def test_create_revlookup_query_normal_checksum_and_url(self):
query = self.searcher.create_revlookup_query(CHECKSUM='foo', URL='bar')
self.assertEqual(query, '?URL=bar&CHECKSUM=foo',
'The query is: '+query)

def test_create_revlookup_query_checksum_and_none_url(self):
query = self.searcher.create_revlookup_query(CHECKSUM='foo', URL=None)
self.assertEqual(query, '?URL=bar&CHECKSUM=foo',
'The query is: '+query)

def test_create_revlookup_query_checksum_and_none_url(self):
query = self.searcher.create_revlookup_query(CHECKSUM='foo', URL=None, something=None)
self.assertEqual(query, '?CHECKSUM=foo',
'The query is: '+query)

def test_instantiate_wrong_search_url(self):

inst = EUDATHandleClient.instantiate_for_read_and_search(
Expand Down
21 changes: 21 additions & 0 deletions b2handle/tests/handleclient_searchaccess_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,27 @@ def test_search_handle_for_url_and_checksum(self):
self.assertEqual(val1, [], 'val1 is: '+str(val1)+', instead of []')
self.assertEqual(val2, [], 'val2 is: '+str(val2)+', instead of []')

def test_search_handle_for_checksum(self):
"""Test searching for checksum with wildcards."""
log_new_test_case("test_search_handle_for_checksum")

log_start_test_code()
val1 = self.inst.search_handle(None, CHECKSUM='*1111111111111*')

log_end_test_code()
log_start_test_code()
val2 = self.inst.search_handle(URL=None, CHECKSUM='*1111111111111*')
log_end_test_code()

# Check desired outcome:
self.assertEqual(type(val1),type([]),
'Searching did not return a list, but: '+str(val1)+', type: '+str(type(val1)))
self.assertEqual(val1, val2,
'Searching with or without keyword did not return the same result:'+\
'\nwith keyword: '+str(val1)+'\nwithout: '+str(val2))
self.assertEqual(val1, [], 'val1 is: '+str(val1)+', instead of []')
self.assertEqual(val2, [], 'val2 is: '+str(val2)+', instead of []')

def test_search_handle_prefixfilter(self):
"""Test filtering for prefixes."""
log_new_test_case("test_search_handle_prefixfilter")
Expand Down
8 changes: 8 additions & 0 deletions b2handle/tests/utilconfig_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ def test_valid_https_verify_string_false(self):
"""Test return bool False when getting string False"""
self.assertEqual(get_valid_https_verify('False'), False)

def test_valid_https_verify_unicode_string_true(self):
"""Test return bool True when getting unicode string True"""
self.assertEqual(get_valid_https_verify(u'True'), True)

def test_valid_https_verify_unicode_string_false(self):
"""Test return bool False when getting unicode string False"""
self.assertEqual(get_valid_https_verify(u'False'), False)

def test_valid_https_verify_bool_string(self):
"""Test return string when getting a string value in https_verify"""
self.assertEqual(get_valid_https_verify('ca_cert.crt'), 'ca_cert.crt')
29 changes: 29 additions & 0 deletions b2handle/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,35 @@ def check_presence_of_mandatory_args(args, mandatory_args):
else:
return True

def return_keys_of_value_none(dictionary):
isnone = []
for key,value in dictionary.iteritems():
if value is None:
isnone.append(key)
return isnone

def remove_value_none_from_dict(dictionary):
isnone = return_keys_of_value_none(dictionary)
if len(isnone) > 0:
for nonekey in isnone:
dictionary.pop(nonekey)
return dictionary

def return_indices_of_value_none(mylist):
isnone = []
for i in xrange(len(mylist)):
if mylist[i] is None:
isnone.append(i)
return isnone

def remove_value_none_from_list(mylist):
isnone = return_indices_of_value_none(mylist)
if len(isnone) > 0:
for index in isnone:
mylist.pop(index)
return mylist


def log_instantiation(LOGGER, classname, args, forbidden, with_date=False):
'''
Log the instantiation of an object to the given logger.
Expand Down
2 changes: 1 addition & 1 deletion b2handle/utilconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def get_valid_https_verify(value):

if isinstance(value, bool):
http_verify_value = value
elif isinstance(value, str) and value.lower() in bool_values.keys():
elif (isinstance(value, str) or isinstance(value, unicode)) and value.lower() in bool_values.keys():
http_verify_value = bool_values[value.lower()]

return http_verify_value
4 changes: 3 additions & 1 deletion docs/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
&& rm -rf /var/lib/apt/lists/*

RUN easy_install pip
RUN pip install sphinx
RUN pip install \
sphinx \
sphinx_rtd_theme

VOLUME /opt/B2HANDLE/docs

Expand Down
Loading

0 comments on commit 9bab15a

Please sign in to comment.