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


Python EUDATHandleClient.retrieve_handle_record方法代码示例

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


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

示例1: EUDATHandleClientReadaccessPatchedTestCase

# 需要导入模块: from b2handle.handleclient import EUDATHandleClient [as 别名]
# 或者: from b2handle.handleclient.EUDATHandleClient import retrieve_handle_record [as 别名]
class EUDATHandleClientReadaccessPatchedTestCase(unittest.TestCase):
    '''Testing methods that read the 10320/loc entry.'''

    def setUp(self):
        self.inst = EUDATHandleClient()

    def tearDown(self):
        pass

    # retrieve_handle_record_json:

    @mock.patch('b2handle.handleclient.requests.Session.get')
    def test_retrieve_handle_record_json_normal(self, getpatch):
        """Test if retrieve_handle_record_json returns the correct things.."""

        # Test variables:
        handlerecord = RECORD
        expected = json.loads(handlerecord)

        # Define the replacement for the patched method:
        mock_response = MockResponse(success=True, content=handlerecord)
        getpatch.return_value = mock_response

        # Call method and check result:
        received = self.inst.retrieve_handle_record_json(expected['handle'])
        self.assertEqual(received, expected,
            'Unexpected return from handle retrieval.')

    @mock.patch('b2handle.handleclient.requests.Session.get')
    def test_retrieve_handle_record_json_handle_does_not_exist(self, getpatch):
        """Test return value (None) if handle does not exist (retrieve_handle_record_json)."""

        # Test variables:
        testhandle = 'dont/exist'

        # Define the replacement for the patched method:
        mock_response = MockResponse(notfound=True)
        getpatch.return_value = mock_response

        # Call method and check result:
        json_record = self.inst.retrieve_handle_record_json(testhandle)
        self.assertIsNone(json_record,
            'The return value should be None if the handle does not exist, not: '+str(json_record))

    @mock.patch('b2handle.handleclient.requests.Session.get')
    def test_retrieve_handle_record_json_handle_empty(self, getpatch):
        """Test return value if handle is empty (retrieve_handle_record_json)."""

        # Test variables:
        testhandle = 'dont/exist'

        # Define the replacement for the patched method:
        mock_response = MockResponse(empty=True)
        getpatch.return_value = mock_response

        # Call method and check result:
        json_record = self.inst.retrieve_handle_record_json(testhandle)
        self.assertEquals(json_record['responseCode'],200,
            'Unexpected return value: '+str(json_record))

    @mock.patch('b2handle.handleclient.requests.Session.get')
    def test_retrieve_handle_record_json_genericerror(self, getpatch):
        """Test exception if retrieve_handle_record_json returns a strange HTTP code."""

        # Test variables:
        testhandle = 'dont/exist'

        # Define the replacement for the patched method:
        mock_response = MockResponse(status_code=99999)
        getpatch.return_value = mock_response

        # Call method and check result:
        with self.assertRaises(GenericHandleError):
            json_record = self.inst.retrieve_handle_record_json(testhandle)

    # retrieve_handle_record:

    #@mock.patch('b2handle.handleclient.EUDATHandleClient._EUDATHandleClient__send_handle_get_request')
    @mock.patch('b2handle.handleclient.requests.Session.get')
    def test_retrieve_handle_record_when_json_not_given(self, getpatch):
        """Test retrieving a handle record"""

        # Test variables
        handlerecord_string = RECORD
        handlerecord_json = json.loads(handlerecord_string)
        testhandle = handlerecord_json['handle']
        
        # Define the replacement for the patched method:
        mock_response = MockResponse(success=True, content=handlerecord_string)
        getpatch.return_value = mock_response

        # Call method and check result:
        dict_record = self.inst.retrieve_handle_record(testhandle)
        self.assertIn('TEST1', dict_record,
            'Key "test1" not in handlerecord dictionary!')
        self.assertIn('TEST2', dict_record,
            'Key "test2" not in handlerecord dictionary!')
        self.assertIn('TESTDUP', dict_record,
            'Key "TESTDUP" not in handlerecord dictionary!')
        self.assertIn('HS_ADMIN', dict_record,
#.........这里部分代码省略.........
开发者ID:EUDAT-B2SAFE,项目名称:B2HANDLE,代码行数:103,代码来源:handleclient_2_read_patched_unit_test.py

示例2: EUDATHandleClientReadaccessFakedTestCase

# 需要导入模块: from b2handle.handleclient import EUDATHandleClient [as 别名]
# 或者: from b2handle.handleclient.EUDATHandleClient import retrieve_handle_record [as 别名]
class EUDATHandleClientReadaccessFakedTestCase(unittest.TestCase):
    '''Testing methods for retrieving values and indices.'''

    def setUp(self):
        self.inst = EUDATHandleClient()

    def tearDown(self):
        pass

    # get_value_from_handle

    def test_get_value_from_handle_normal(self):
        """Test retrieving a specific value from a handle record."""

        handlerecord = json.load(open('resources/handlerecord_for_reading.json'))
        handle = handlerecord['handle']

        val = self.inst.get_value_from_handle(handle,
                                              'test1',
                                              handlerecord)
        self.assertEquals(val, 'val1',
            'The value of "test1" should be "val1".')

    def test_get_value_from_handle_inexistentvalue(self):
        """Test retrieving an inexistent value from a handle record."""

        handlerecord = json.load(open('resources/handlerecord_for_reading.json'))
        handle = handlerecord['handle']

        val = self.inst.get_value_from_handle(handle,
                                              'test100',
                                              handlerecord)
        self.assertIsNone(val,
            'The value of "test100" should be None.')

    def test_get_value_from_handle_HS_ADMIN(self):
        """Test retrieving an HS_ADMIN value from a handle record."""

        handlerecord = json.load(open('resources/handlerecord_for_reading.json'))
        handle = handlerecord['handle']

        val = self.inst.get_value_from_handle(handle,
                                              'HS_ADMIN',
                                              handlerecord)
        self.assertIn('handle', val,
            'The HS_ADMIN has no entry "handle".')
        self.assertIn('index', val,
            'The HS_ADMIN has no entry "index".')
        self.assertIn('permissions', val,
            'The HS_ADMIN has no entry "permissions".')
        syntax_ok = self.inst.check_handle_syntax(val['handle'])
        self.assertTrue(syntax_ok,
            'The handle in HS_ADMIN is not well-formatted.')
        self.assertIsInstance(val['index'], (int, long),
            'The index of the HS_ADMIN is not an integer.')
        self.assertEqual(str(val['permissions']).replace('0','').replace('1',''), '',
            'The permission value in the HS_ADMIN contains not just 0 and 1.')

    def test_get_value_from_handle_duplicatekey(self):
        """Test retrieving a value of a duplicate key."""

        handlerecord = json.load(open('resources/handlerecord_for_reading.json'))
        handle = handlerecord['handle']

        val = self.inst.get_value_from_handle(handle,
                                              'testdup',
                                              handlerecord)
        self.assertIn(val, ("dup1", "dup2"),
            'The value of the duplicate key "testdup" should be "dup1" or "dup2".')

    # retrieve_handle_record

    def test_retrieve_handle_record_normal(self):

        handlerecord = json.load(open('resources/handlerecord_for_reading.json'))
        handle = handlerecord['handle']

        dict_record = self.inst.retrieve_handle_record(handle, handlerecord)

        self.assertIn('test1', dict_record,
            'Key "test1" not in handlerecord dictionary!')
        self.assertIn('test2', dict_record,
            'Key "test2" not in handlerecord dictionary!')
        self.assertIn('testdup', dict_record,
            'Key "testdup" not in handlerecord dictionary!')
        self.assertIn('HS_ADMIN', dict_record,
            'Key "HS_ADMIN" not in handlerecord dictionary!')

        self.assertEqual(dict_record['test1'], 'val1',
            'The value of "test1" is not "val1.')
        self.assertEqual(dict_record['test2'], 'val2',
            'The value of "test2" is not "val2.')
        self.assertIn(dict_record['testdup'], ("dup1", "dup2"),
            'The value of the duplicate key "testdup" should be "dup1" or "dup2".')
        self.assertIn('permissions', dict_record['HS_ADMIN'],
            'The HS_ADMIN has no permissions: '+dict_record['HS_ADMIN'])

        self.assertEqual(len(dict_record), 4,
            'The record should have a length of 5 (as the duplicate is ignored.')

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

示例3: EUDATHandleClientNoaccessTestCase

# 需要导入模块: from b2handle.handleclient import EUDATHandleClient [as 别名]
# 或者: from b2handle.handleclient.EUDATHandleClient import retrieve_handle_record [as 别名]

#.........这里部分代码省略.........

    def test_check_handle_syntax_two_slashes(self):
        """Handle Syntax: No exception if too many slashes in handle."""
        check_handle_syntax("foo/bar/foo")

    def test_check_handle_syntax_no_slashes(self):
        """Handle Syntax: Exception if too many slashes in handle."""
        with self.assertRaises(HandleSyntaxError):
            check_handle_syntax("foobar")

    def test_check_handle_syntax_no_prefix(self):
        """Handle Syntax: Exception if no prefix."""
        with self.assertRaises(HandleSyntaxError):
            check_handle_syntax("/bar")

    def test_check_handle_syntax_no_suffix(self):
        """Handle Syntax: Exception if no suffix."""
        with self.assertRaises(HandleSyntaxError):
            check_handle_syntax("foo/")

    def test_check_handle_syntax_with_index(self):
        """Test check handle syntax with index."""
        syntax_checked = check_handle_syntax("300:foo/bar")
        self.assertTrue(syntax_checked,
            'The syntax of the handle is not index:prefix/suffix.')

    def test_check_handle_syntax_none(self):
        """Test check handle syntax where handle is None"""
        with self.assertRaises(HandleSyntaxError):
            syntax_checked = check_handle_syntax(None)

    def test_check_handle_syntax_with_index_nan(self):
        """Handle Syntax: Exception if index not a number."""
        with self.assertRaises(HandleSyntaxError):
            check_handle_syntax_with_index("nonumber:foo/bar")

    def test_check_handle_syntax_with_index_noindex(self):
        """Handle Syntax: Exception if index not existent."""
        with self.assertRaises(HandleSyntaxError):
            check_handle_syntax_with_index("index/missing")

    def test_check_handle_syntax_with_index_twocolons(self):
        """Handle Syntax: Exception if two colons."""
        with self.assertRaises(HandleSyntaxError):
            check_handle_syntax_with_index("too:many:colons")

    def test_check_handle_syntax_with_index_onlyindex(self):
        """Handle Syntax: Exception if no prefix and suffix."""
        with self.assertRaises(HandleSyntaxError):
            check_handle_syntax_with_index("onlyindex:")

    def test_remove_index_from_handle(self):
        handle_with_index = "300:foo/bar"
        syntax_checked = check_handle_syntax(handle_with_index)
        self.assertTrue(syntax_checked,
            'Test precondition failed!')
        index, handle = remove_index_from_handle(handle_with_index)
        syntax_checked = check_handle_syntax(handle)
        self.assertTrue(syntax_checked,
            'After removing the index, the syntax of the handle should '+\
            'be prefix/suffix.')

    def test_remove_index_noindex(self):
        handle_with_index = "foo/bar"
        syntax_checked = check_handle_syntax(handle_with_index)
        self.assertTrue(syntax_checked,
            'Test precondition failed!')
        index, handle = remove_index_from_handle(handle_with_index)
        syntax_checked = check_handle_syntax(handle)
        self.assertTrue(syntax_checked,
            'After removing the index, the syntax of the handle should '+\
            'be prefix/suffix.')

    def test_remove_index_toomany(self):
        handle_with_index = "100:100:foo/bar"
        with self.assertRaises(HandleSyntaxError):
            index, handle = remove_index_from_handle(handle_with_index)

    # retrieve handle record (failing before any server access)

    def test_retrieve_handle_record_json_handlesyntax_wrong(self):
        """Test exception if handle syntax is wrong (retrieve_handle_record_json)."""

        with self.assertRaises(HandleSyntaxError):
            json_record = self.inst.retrieve_handle_record_json('testhandle')

    def test_retrieve_handle_record_when_handle_is_None(self):
        """Test error when retrieving a handle record with a None input."""

        # Call method and check result:
        with self.assertRaises(HandleSyntaxError):
            self.inst.retrieve_handle_record(None)

    # make_authentication_string

    def test_create_authentication_string(self):
        auth = create_authentication_string('100:user/name', 'password123')
        expected = 'MTAwJTNBdXNlci9uYW1lOnBhc3N3b3JkMTIz'
        self.assertEquals(expected, auth,
            'Authentication string is: '+auth+', but should be: '+expected)
开发者ID:EUDAT-B2SAFE,项目名称:B2HANDLE,代码行数:104,代码来源:handleclient_unit_test.py

示例4: EUDATHandleClientReadaccessPatchedTestCase

# 需要导入模块: from b2handle.handleclient import EUDATHandleClient [as 别名]
# 或者: from b2handle.handleclient.EUDATHandleClient import retrieve_handle_record [as 别名]
class EUDATHandleClientReadaccessPatchedTestCase(unittest.TestCase):
    """Testing methods that read the 10320/loc entry."""

    def setUp(self):
        self.inst = EUDATHandleClient()

    def tearDown(self):
        pass

    # retrieve_handle_record_json:

    @patch("b2handle.handleclient.requests.get")
    def test_retrieve_handle_record_json_normal(self, getpatch):
        """Test if retrieve_handle_record_json returns the correct things.."""

        # Test variables:
        handlerecord = open("resources/handlerecord_for_reading.json").read()
        expected = json.loads(handlerecord)

        # Define the replacement for the patched method:
        mock_response = MockResponse(success=True, content=handlerecord)
        getpatch.return_value = mock_response

        # Call method and check result:
        received = self.inst.retrieve_handle_record_json(expected["handle"])
        self.assertEqual(received, expected, "Unexpected return from handle retrieval.")

    @patch("b2handle.handleclient.requests.get")
    def test_retrieve_handle_record_json_handle_does_not_exist(self, getpatch):
        """Test return value (None) if handle does not exist (retrieve_handle_record_json)."""

        # Test variables:
        testhandle = "dont/exist"

        # Define the replacement for the patched method:
        mock_response = MockResponse(notfound=True)
        getpatch.return_value = mock_response

        # Call method and check result:
        json_record = self.inst.retrieve_handle_record_json(testhandle)
        self.assertIsNone(
            json_record, "The return value should be None if the handle does not exist, not: " + str(json_record)
        )

    @patch("b2handle.handleclient.requests.get")
    def test_retrieve_handle_record_json_handle_empty(self, getpatch):
        """Test return value if handle is empty (retrieve_handle_record_json)."""

        # Test variables:
        testhandle = "dont/exist"

        # Define the replacement for the patched method:
        mock_response = MockResponse(empty=True)
        getpatch.return_value = mock_response

        # Call method and check result:
        json_record = self.inst.retrieve_handle_record_json(testhandle)
        self.assertEquals(json_record["responseCode"], 200, "Unexpected return value: " + str(json_record))

    @patch("b2handle.handleclient.requests.get")
    def test_retrieve_handle_record_json_genericerror(self, getpatch):
        """Test exception if retrieve_handle_record_json returns a strange HTTP code."""

        # Test variables:
        testhandle = "dont/exist"

        # Define the replacement for the patched method:
        mock_response = MockResponse(status_code=99999)
        getpatch.return_value = mock_response

        # Call method and check result:
        with self.assertRaises(GenericHandleError):
            json_record = self.inst.retrieve_handle_record_json(testhandle)

    # retrieve_handle_record:

    # @patch('b2handle.handleclient.EUDATHandleClient._EUDATHandleClient__send_handle_get_request')
    @patch("b2handle.handleclient.requests.get")
    def test_retrieve_handle_record_when_json_not_given(self, getpatch):
        """Test retrieving a handle record"""

        # Test variables
        handlerecord_string = open("resources/handlerecord_for_reading.json").read()
        handlerecord_json = json.loads(handlerecord_string)
        testhandle = handlerecord_json["handle"]

        # Define the replacement for the patched method:
        mock_response = MockResponse(success=True, content=handlerecord_string)
        getpatch.return_value = mock_response

        # Call method and check result:
        dict_record = self.inst.retrieve_handle_record(testhandle)
        self.assertIn("test1", dict_record, 'Key "test1" not in handlerecord dictionary!')
        self.assertIn("test2", dict_record, 'Key "test2" not in handlerecord dictionary!')
        self.assertIn("testdup", dict_record, 'Key "testdup" not in handlerecord dictionary!')
        self.assertIn("HS_ADMIN", dict_record, 'Key "HS_ADMIN" not in handlerecord dictionary!')

        self.assertEqual(dict_record["test1"], "val1", 'The value of "test1" is not "val1.')
        self.assertEqual(dict_record["test2"], "val2", 'The value of "test2" is not "val2.')
        self.assertIn(
#.........这里部分代码省略.........
开发者ID:TonyWildish,项目名称:B2HANDLE,代码行数:103,代码来源:handleclient_readaccess_patched_test.py


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