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


Python EUDATHandleClient.retrieve_handle_record_json方法代码示例

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


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

示例1: test_global_resolve

# 需要导入模块: from b2handle.handleclient import EUDATHandleClient [as 别名]
# 或者: from b2handle.handleclient.EUDATHandleClient import retrieve_handle_record_json [as 别名]
    def test_global_resolve(self):
        """Testing if instantiating with default handle server'works
        and if a handle is correctly retrieved. """

        # Create instance with default server url:
        inst = EUDATHandleClient(HTTPS_verify=self.https_verify)
        rec = inst.retrieve_handle_record_json(self.handle_global)

        self.assertIn("handle", rec, 'Response lacks "handle".')
        self.assertIn("responseCode", rec, 'Response lacks "responseCode".')
开发者ID:NicolasLiampotis,项目名称:B2HANDLE,代码行数:12,代码来源:handleclient_readaccess_test.py

示例2: EUDATHandleClientReadaccessPatchedTestCase

# 需要导入模块: from b2handle.handleclient import EUDATHandleClient [as 别名]
# 或者: from b2handle.handleclient.EUDATHandleClient import retrieve_handle_record_json [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

示例3: EUDATHandleClientNoaccessTestCase

# 需要导入模块: from b2handle.handleclient import EUDATHandleClient [as 别名]
# 或者: from b2handle.handleclient.EUDATHandleClient import retrieve_handle_record_json [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: EUDATHandleClientReadaccessTestCase

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

#.........这里部分代码省略.........
        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

    def test_retrieve_handle_record_json(self):
        """Test reading handle record from server."""

        rec = self.inst.retrieve_handle_record_json(self.handle)

        self.assertEqual(rec['values'][2]['type'], 'test3',
            'The type should be "test3".')
        self.assertEqual(rec['values'][2]['data']['value'], 'val3',
            'The value should be "val3".')

    # get_value_from_handle

    def test_get_value_from_handle_normal(self):
        """Test reading existent and inexistent handle value from server."""
        val = self.inst.get_value_from_handle(self.handle, 'test1')
        self.assertEqual(val, 'val1',
            'Retrieving "test1" should lead to "val1", but it lead to: '+str(val))

    def test_get_value_from_handle_inexistent_key(self):
        val = self.inst.get_value_from_handle(self.handle, 'test100')
        self.assertIsNone(val,
            'Retrieving "test100" should lead to "None", but it lead to: '+str(val))

    def test_get_value_from_handle_inexistent_record(self):
        """Test reading handle value from inexistent handle."""
        with self.assertRaises(HandleNotFoundException):
            val = self.inst.get_value_from_handle(self.inexistent_handle, 'anykey')

    # instantiate

    def test_instantiate_with_username_and_wrong_password(self):
        """Test instantiation of client: No exception if password wrong."""
开发者ID:TonyWildish,项目名称:B2HANDLE,代码行数:69,代码来源:handleclient_readaccess_test.py

示例5: EUDATHandleClientReadaccessPatchedTestCase

# 需要导入模块: from b2handle.handleclient import EUDATHandleClient [as 别名]
# 或者: from b2handle.handleclient.EUDATHandleClient import retrieve_handle_record_json [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_json方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。