当前位置: 首页>>代码示例>>Python>>正文


Python EUDATHandleClient.create_authentication_string方法代码示例

本文整理汇总了Python中b2handle.handleclient.EUDATHandleClient.create_authentication_string方法的典型用法代码示例。如果您正苦于以下问题:Python EUDATHandleClient.create_authentication_string方法的具体用法?Python EUDATHandleClient.create_authentication_string怎么用?Python EUDATHandleClient.create_authentication_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在b2handle.handleclient.EUDATHandleClient的用法示例。


在下文中一共展示了EUDATHandleClient.create_authentication_string方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: EUDATHandleClientReadaccessTestCase

# 需要导入模块: from b2handle.handleclient import EUDATHandleClient [as 别名]
# 或者: from b2handle.handleclient.EUDATHandleClient import create_authentication_string [as 别名]
class EUDATHandleClientReadaccessTestCase(unittest.TestCase):

    def __init__(self, *args, **kwargs):
        unittest.TestCase.__init__(self, *args, **kwargs)

        # Read resources from file:
        self.testvalues = json.load(open(RESOURCES_FILE))

        # Test values that need to be given by user:
        self.handle = self.testvalues['handle_for_read_tests']
        self.handle_global = self.testvalues['handle_globally_resolvable']
        self.user = self.testvalues['user']

        # Optional:
        self.https_verify = True
        if 'HTTPS_verify' in self.testvalues:
            self.https_verify = self.testvalues['HTTPS_verify']
        self.url = 'http://hdl.handle.net'
        if 'handle_server_url_read' in self.testvalues.keys():
            self.url = self.testvalues['handle_server_url_read']
        self.path_to_api = None
        if 'url_extension_REST_API' in self.testvalues.keys():
            self.path_to_api = self.testvalues['url_extension_REST_API']

        # Others
        prefix = self.handle.split('/')[0]
        self.inexistent_handle = prefix+'/07e1fbf3-2b72-430a-a035-8584d4eada41'
        self.randompassword = 'some_random_password_shrgfgh345345'

    def setUp(self):
        """ For most test, provide a client instance with the user-specified
        handle server url."""

        self.inst = EUDATHandleClient(
            HTTPS_verify=self.https_verify,
            handle_server_url=self.url,
            url_extension_REST_API=self.path_to_api)

        # Before being able to run these tests without write access,
        # the handle that we use for testing must exist. With this code,
        # you can create it. You only need to create it once and leave it
        # on the server, it will not be modified and can be used eternally.
        if False:
            # This should always be false!!! Except for creating the
            # required handle once! 
            self.create_required_test_handles()

    def tearDown(self):
        pass
        pass

    def create_required_test_handles(self):

        # Creating an instance that knows how to write:
        pw = self.testvalues['password']
        inst = EUDATHandleClient.instantiate_with_username_and_password(
            self.testvalues['handle_server_url_write'],
            self.user,
            pw,
            HTTPS_verify=self.https_verify)

        authstring = self.inst.create_authentication_string(self.user, pw)
        headers = {
            'Content-Type': 'application/json',
            'Authorization': 'Basic '+authstring
        }

        list_of_all_entries = [
            {
                "index":111,
                "type":"test1",
                "data":"val1"
            },
            {
                "index":2222,
                "type":"test2",
                "data":"val2"
            },
            {
                "index":333,
                "type":"test3",
                "data":"val3"
            },
            {
                "index":4,
                "type":"test4",
                "data":"val4"
            }
        ]

        testhandle = self.handle
        url = inst.make_handle_URL(testhandle)
        veri = self.https_verify
        head = headers
        data = json.dumps({'values':list_of_all_entries})
        resp = requests.put(url, data=data, headers=head, verify=veri)


    # retrieve_handle_record_json

#.........这里部分代码省略.........
开发者ID:TonyWildish,项目名称:B2HANDLE,代码行数:103,代码来源:handleclient_readaccess_test.py


注:本文中的b2handle.handleclient.EUDATHandleClient.create_authentication_string方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。