def search(args): """perform search action""" # load credentials credentials = PIDClientCredentials.load_from_JSON(args.credpath) # set username and password for search if 'reverse_username' in credentials.get_config(): reverselookup_username = credentials.get_config()['reverse_username'] else: reverselookup_username = credentials.get_prefix() if 'reverse_password' in credentials.get_config(): reverselookup_password = credentials.get_config()['reverse_password'] else: reverselookup_password = credentials.get_password() # retrieve and set extra values extra_config = {} # setup connection to handle server client = EUDATHandleClient.instantiate_for_read_and_search( credentials.get_server_URL(), reverselookup_username, reverselookup_password, **extra_config) kvpairs = dict([(args.key, str(''.join(args.value)))]) # search for handle result = client.search_handle(**kvpairs) json_result = str(json.dumps(result)) if json_result == '[]': json_result = 'empty' sys.stdout.write(json_result)
def test_instantiate_for_read_an_search(self): """Testing if instantiating with default handle server works. """ # Try to create client instance for search without a search URL: with self.assertRaises(TypeError): inst = EUDATHandleClient.instantiate_for_read_and_search( None, 'johndoe', 'passywordy')
def test_instantiate_wrong_search_url(self): inst = EUDATHandleClient.instantiate_for_read_and_search( "someurl", "someuser", "somepassword", reverselookup_baseuri="http://something_random_foo_bar" ) self.assertIsInstance(inst, EUDATHandleClient)
def test_instantiate_wrong_search_url(self): inst = EUDATHandleClient.instantiate_for_read_and_search( 'someurl', 'someuser', 'somepassword', reverselookup_baseuri='http://something_random_foo_bar') self.assertIsInstance(inst, EUDATHandleClient)
def setUp(self): '''Providing a client instance that has read and search access to the servers specified in the test resources JSON file. ''' REQUESTLOGGER.info("\n"+60*"*"+"\nsetUp of EUDATHandleClientSearchTestCase") self.inst = EUDATHandleClient.instantiate_for_read_and_search( self.url, self.searchuser, self.searchpassword, reverselookup_baseuri=self.searchurl, reverselookup_url_extension=self.searchpath, HTTPS_verify=self.https_verify)
def test_search_handle_wrong_url_test(self): """Test exception when wrong search servlet URL is given.""" log_new_test_case("test_search_handle_wrong_url_test") # Make new client instance with existing but wrong url for searching: inst = EUDATHandleClient.instantiate_for_read_and_search( self.url, self.searchuser, self.searchpassword, reverselookup_baseuri=self.searchurl_wrong, reverselookup_url_extension=self.searchpath, HTTPS_verify=self.https_verify) # Run code to be tested + check exception: log_start_test_code() with self.assertRaises(ReverseLookupException): inst.search_handle(URL='*') log_end_test_code()
def test_search_handle_hs_url_test(self): """Test exception when wrong search servlet URL (Handle Server REST API URL) is given.""" log_new_test_case("test_search_handle_hs_url_test") # Make new instance with handle server url as search url: self.inst = EUDATHandleClient.instantiate_for_read_and_search( self.url, self.searchuser, self.searchpassword, reverselookup_baseuri=self.url, reverselookup_url_extension=self.path_to_api, HTTPS_verify=self.https_verify) # Run code to be tested + check exception: log_start_test_code() with self.assertRaises(ReverseLookupException): self.inst.search_handle(URL='*') # TODO specify exception log_end_test_code()