Skip to content
This repository has been archived by the owner on Dec 7, 2020. It is now read-only.

Commit

Permalink
corrected refactoring, docs
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasWeigel committed Feb 9, 2015
1 parent be182e3 commit 761c0d3
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 30 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
/build/
/dist/
/timingtest.py
/testing-config.cfg
19 changes: 13 additions & 6 deletions lapis/infra/handleinfrastructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,19 @@ class HandleInfrastructure(DOInfrastructure):
def __init__(self, host, port, user, user_index, password, path, prefix = None, additional_identifier_element = None, unsafe_ssl=False):
'''
Constructor.
:param _prefix: The Handle _prefix to use (without trailing slash). If not given, all operations will work
nonetheless, except for random handle creation. Note that setting a _prefix does not mean that identifier
strings can omit it - all identifiers must ALWAYS include the _prefix, no matter what.
:param _additional_identifier_element: A string that is inserted inbetween Handle _prefix and suffix, e.g. if set
:param host: Host name of the Handle server.
:param port: Port for the Handle server, usually 443 or 8443.
:param user: Full user Handle name to authenticate for administrative permissions for modifying Handles. The full user name will usually be of the form 'prefix/suffix'.
:param user_index: The index to use within the user Handle.
:param password: The user password.
:param path: The server path for the API endpoint, e.g. 'api/handles'. Does not include the host name.
:param prefix: The Handle prefix to use (without trailing slash). If not given, all operations will work
nonetheless, except for random handle creation. Note that setting a prefix does not mean that identifier
strings can omit it - all identifiers must ALWAYS include the prefix, no matter what.
:param additional_identifier_element: A string that is inserted inbetween Handle prefix and suffix, e.g. if set
to "test-", 10876/identifier becomes 10876/test-identifier.
:unsafe_ssl: If set to True, SSL certificate warnings will be ignored. Do not activate this in productive environments!
'''
super(HandleInfrastructure, self).__init__()
self._host = host
Expand All @@ -98,7 +105,7 @@ def __init__(self, host, port, user, user_index, password, path, prefix = None,
self.__connpool = HTTPSConnectionPool(host, port=port)
self.__user_handle = prefix+"/"+user
self.__user_index = user_index
self.__authstring = b64encode(user_index+"%3A"+prefix+"/"+user+":"+password)
self.__authstring = b64encode(user_index+"%3A"+user+":"+password)
self.__http_headers = {"Content-Type": "application/json", "Authorization": "Basic %s" % self.__authstring}
if not self._path.endswith("/"):
self._path = self._path + "/"
Expand Down
2 changes: 1 addition & 1 deletion lapis/model/do.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __init__(self, do_infrastructure, identifier, references=None, alias_identif
infrastructure, no resource location or object-type entries should be given in the annotations dict. Also note
that the annotations dict is assigned directly, not copied.
:param resource_location: The resource location of the Digital Object's data, in case of external data.
:param _resource_type: The resource type for external data. Note that resource_location and _resource_type are not
:param resource_type: The resource type for external data. Note that resource_location and resource_type are not
checked for consistency by the constructor. It is the caller's task to provide meaningful values.
:param references: The references of this instance to other Digital Objects. As with annotations, this is a dict
that is assigned directly, not copied.
Expand Down
44 changes: 22 additions & 22 deletions lapis/model/infra_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
from lapis.model.dolist import DigitalObjectArray, DigitalObjectLinkedList
from lapis.model.hashmap import BASE_INDEX_HASHMAP_SIZE

TESTING_CONFIG_DEFAULTS = { "handle-_prefix": "10876.test", "server-address": "handle8.dkrz.de", "server-port": 443 }
TESTING_CONFIG_DEFAULTS = { "handle-prefix": "10876.test", "server-address": "handle8.dkrz.de", "server-port": 443 }

logger = logging.getLogger(__name__)

Expand All @@ -57,7 +57,7 @@ def setUp(self):
self.logger = logging.getLogger(__name__)
self.random = Random(43210)
self.created_pids = []
self._prefix = TESTING_CONFIG_DEFAULTS["handle-_prefix"]+"/"
self.prefix = TESTING_CONFIG_DEFAULTS["handle-prefix"]+"/"

def tearDown(self):
pass
Expand All @@ -78,11 +78,11 @@ def __check_dobj3_references(self, dobj3, dobj1, dobj2):

def test_do_values(self):
# values
pid = self._prefix+"test_do_values"
pid = self.prefix+"test_do_values"
resloc = "http://www.example.com/1"
restype = "MY_TEST_TYPE"
pid2 = self._prefix+"test_do_values_2"
pid3 = self._prefix+"test_do_values_3"
pid2 = self.prefix+"test_do_values_2"
pid3 = self.prefix+"test_do_values_3"
# create DO
dobj = self.do_infra.create_do(pid)
self.created_pids.append(pid)
Expand Down Expand Up @@ -140,14 +140,14 @@ def test_do_values(self):
assert dobj == None

def test_infra_operations(self):
dobj = self.do_infra.lookup_pid(self._prefix+"does-not-exist")
dobj = self.do_infra.lookup_pid(self.prefix+"does-not-exist")
assert dobj == None
# duplication attempts
dobj = self.do_infra.create_do(self._prefix+"duplicate")
self.created_pids.append(self._prefix+"duplicate")
dobj = self.do_infra.create_do(self.prefix+"duplicate")
self.created_pids.append(self.prefix+"duplicate")
assert dobj != None
try:
dobj2 = self.do_infra.create_do(self._prefix+"duplicate")
dobj2 = self.do_infra.create_do(self.prefix+"duplicate")
self.fail("Creation attempt of object with duplicate PID successful!")
except PIDAlreadyExistsError:
pass
Expand All @@ -163,9 +163,9 @@ def test_random_pid_allocation(self):

def test_aliases(self):
resloc = "http://www.example.com/alias_original"
id_orig = self._prefix+"alias_original"
id_alias1 = self._prefix+"alias1"
id_alias2 = self._prefix+"alias2"
id_orig = self.prefix+"alias_original"
id_alias1 = self.prefix+"alias1"
id_alias2 = self.prefix+"alias2"
dobj1 = self.do_infra.create_do(id_orig)
id_orig = dobj1.identifier
self.created_pids.append(id_orig)
Expand Down Expand Up @@ -214,9 +214,9 @@ def test_aliases(self):

def test_sets(self):
# create a set
id_ele = [self._prefix+"setele1", self._prefix+"setele2", self._prefix+"setele3"]
id_set = self._prefix+"set"
non_ele_id = self._prefix+"some-non-ele"
id_ele = [self.prefix+"setele1", self.prefix+"setele2", self.prefix+"setele3"]
id_set = self.prefix+"set"
non_ele_id = self.prefix+"some-non-ele"
ele = []
for i in range(len(id_ele)):
newele = self.do_infra.create_do(id_ele[i])
Expand All @@ -241,7 +241,7 @@ def test_sets(self):
assert ele_set.num_set_elements() == 3
# now extend and check again
ele_set = self.do_infra.lookup_pid(id_set)
id_ele += [self._prefix+"setele4"]
id_ele += [self.prefix+"setele4"]
newele = self.do_infra.create_do(id_ele[3])
id_ele[3] = newele.identifier
self.created_pids.append(newele.identifier)
Expand Down Expand Up @@ -282,7 +282,7 @@ def test_sets(self):


def test_lists(self):
id_listele = [self._prefix+"listele1", self._prefix+"listele2", self._prefix+"listele3"]
id_listele = [self.prefix+"listele1", self.prefix+"listele2", self.prefix+"listele3"]
listele = []
# create elements
for i in range(len(id_listele)):
Expand All @@ -291,12 +291,12 @@ def test_lists(self):
id_listele[i] = newele.identifier
self.created_pids.append(newele.identifier)
# test array
id_array = self._prefix+"array"
id_array = self.prefix+"array"
do_array = self.do_infra.create_do(id_array, DigitalObjectArray)
self.created_pids.append(do_array.identifier)
self.list_basic(do_array, id_listele, listele)
# test linked list
id_llist = self._prefix+"linkedlist"
id_llist = self.prefix+"linkedlist"
do_llist = self.do_infra.create_do(id_llist, DigitalObjectLinkedList)
self.created_pids.append(do_llist.identifier)
self.list_basic(do_llist, id_listele, listele)
Expand Down Expand Up @@ -393,7 +393,7 @@ def setUp(self):
host = TESTING_CONFIG_DEFAULTS["server-address"]
port = TESTING_CONFIG_DEFAULTS["server-port"]
urlpath = "/api/handles/"
prefix = TESTING_CONFIG_DEFAULTS["handle-_prefix"]
prefix = TESTING_CONFIG_DEFAULTS["handle-prefix"]
additional_identifier_element = ""
user = ""
password = ""
Expand All @@ -410,11 +410,11 @@ def setUp(self):
if cfgparse.has_option("server", "user_index"): user_index = cfgparse.get("server", "user_index")
if cfgparse.has_option("server", "password"): password = cfgparse.get("server", "password")
if cfgparse.has_option("server", "unsafe_ssl"): unsafe_ssl = cfgparse.getboolean("server", "unsafe_ssl")
if cfgparse.has_option("handle", "_prefix"): prefix = cfgparse.get("handle", "_prefix")
if cfgparse.has_option("handle", "prefix"): prefix = cfgparse.get("handle", "prefix")
if cfgparse.has_option("handle", "additionalelement"): additional_identifier_element = cfgparse.get("handle", "additionalelement")
# now create infra instance
logger.info("Running tests with following parameters:")
logger.info("Host: %s, Port: %s, User: %s, User index: %s, URL path: %s, _prefix: %s, additional element: %s, unsafe_ssl: %s" % (host, port, user, user_index, urlpath, prefix, additional_identifier_element, unsafe_ssl))
logger.info("Host: %s, Port: %s, User: %s, User index: %s, URL path: %s, prefix: %s, additional element: %s, unsafe_ssl: %s" % (host, port, user, user_index, urlpath, prefix, additional_identifier_element, unsafe_ssl))
self.do_infra = HandleInfrastructure(host, port, user, user_index, password, urlpath, prefix=prefix, additional_identifier_element=additional_identifier_element, unsafe_ssl=unsafe_ssl)


Expand Down
2 changes: 1 addition & 1 deletion testing-config.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
host = handle8.dkrz.de
port = 443
path = /api/handles/
user = admin
user = 10876.test/admin
user_index = 300
password = password
unsafe_ssl = True
Expand Down

0 comments on commit 761c0d3

Please sign in to comment.