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


Python EUDATHandleClient.check_handle_syntax方法代码示例

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


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

示例1: EUDATHandleClientReadaccessFakedTestCase

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


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