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


Python HydroShare.setAccessRules方法代码示例

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


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

示例1: test_create_get_delete_resource

# 需要导入模块: from hs_restclient import HydroShare [as 别名]
# 或者: from hs_restclient.HydroShare import setAccessRules [as 别名]
    def test_create_get_delete_resource(self):
        hs = HydroShare(prompt_auth=False)

        abstract = 'Abstract for hello world resource'
        title = 'Minimal hello world resource'
        keywords = ('hello', 'world')
        rtype = 'GenericResource'
        fname = 'mocks/data/minimal_resource_file.txt'
        metadata = json.dumps([{'coverage': {'type': 'period', 'value': {'start': '01/01/2000',
                                             'end': '12/12/2010'}}},
                               {'creator': {'name': 'John Smith'}},
                               {'contributor': {'name': 'Lisa Miller'}}])

        extra_metadata = json.dumps({'latitude': '40', 'longitude': '-111'})

        with HTTMock(mocks.hydroshare.createResourceCRUD):
            # Create
            newres = hs.createResource(rtype, title, resource_file=fname, keywords=keywords,
                                       abstract=abstract, metadata=metadata, extra_metadata=extra_metadata)
            self.assertIsNotNone(newres)
            sysmeta = hs.getSystemMetadata(newres)
            self.assertEqual(sysmeta['resource_id'], newres)
            self.assertEqual(sysmeta['resource_type'], rtype)
            self.assertFalse(sysmeta['public'])

        with HTTMock(mocks.hydroshare.accessRules_put):
            # Make resource public
            hs.setAccessRules(newres, public=True)
            sysmeta = hs.getSystemMetadata(newres)
            self.assertTrue(sysmeta['public'])

        with HTTMock(mocks.hydroshare.createResourceCRUD):
            # Get
            tmpdir = tempfile.mkdtemp()
            hs.getResource(newres, destination=tmpdir)
            with ZipFile(os.path.join(tmpdir, '511debf8858a4ea081f78d66870da76c.zip'), 'r') as zfile:
                self.assertTrue('511debf8858a4ea081f78d66870da76c/data/contents/minimal_resource_file.txt' in zfile.namelist())
                downloaded = zfile.open('511debf8858a4ea081f78d66870da76c/data/contents/minimal_resource_file.txt', 'r')
                original = open('mocks/data/minimal_resource_file.txt', 'rb')
                self.assertEqual(downloaded.read(), original.read())
                downloaded.close()
                original.close()
            shutil.rmtree(tmpdir)

            # Delete
            delres = hs.deleteResource(newres)
            self.assertEqual(delres, newres)
开发者ID:hydroshare,项目名称:hs_restclient,代码行数:49,代码来源:test_hs_restclient.py

示例2: test_create_get_delete_resource

# 需要导入模块: from hs_restclient import HydroShare [as 别名]
# 或者: from hs_restclient.HydroShare import setAccessRules [as 别名]
    def test_create_get_delete_resource(self):
        hs = HydroShare()

        abstract = 'Abstract for hello world resource'
        title = 'Minimal hello world resource'
        keywords = ('hello', 'world')
        rtype = 'GenericResource'
        fname = 'mocks/data/minimal_resource_file.txt'

        with HTTMock(mocks.hydroshare.createResourceCRUD):
            # Create
            newres = hs.createResource(rtype, title, resource_file=fname, keywords=keywords, abstract=abstract)
            self.assertIsNotNone(newres)
            sysmeta = hs.getSystemMetadata(newres)
            self.assertEqual(sysmeta['resource_id'], newres)
            self.assertEqual(sysmeta['resource_type'], rtype)
            self.assertFalse(sysmeta['public'])

        with HTTMock(mocks.hydroshare.accessRules_put):
            # Make resource public
            hs.setAccessRules(newres, public=True)
            sysmeta = hs.getSystemMetadata(newres)
            self.assertTrue(sysmeta['public'])

        with HTTMock(mocks.hydroshare.createResourceCRUD):
            # Get
            tmpdir = tempfile.mkdtemp()
            hs.getResource(newres, destination=tmpdir)
            with ZipFile(os.path.join(tmpdir, '511debf8858a4ea081f78d66870da76c.zip'), 'r') as zfile:
                self.assertTrue('511debf8858a4ea081f78d66870da76c/data/contents/minimal_resource_file.txt' in zfile.namelist())
                downloaded = zfile.open('511debf8858a4ea081f78d66870da76c/data/contents/minimal_resource_file.txt', 'r')
                original = open('mocks/data/minimal_resource_file.txt', 'r')
                self.assertEqual(downloaded.read(), original.read())
                downloaded.close()
                original.close()
            shutil.rmtree(tmpdir)

            # Delete
            delres = hs.deleteResource(newres)
            self.assertEqual(delres, newres)
开发者ID:mtpain,项目名称:hs_restclient,代码行数:42,代码来源:test_hs_restclient.py


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