• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python data_utils.random_bytes函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tempest.lib.common.utils.data_utils.random_bytes函数的典型用法代码示例。如果您正苦于以下问题:Python random_bytes函数的具体用法?Python random_bytes怎么用?Python random_bytes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_copy_object_in_same_container

    def test_copy_object_in_same_container(self):
        # create source object
        src_object_name = data_utils.rand_name(name='SrcObject')
        src_data = data_utils.random_bytes(size=len(src_object_name) * 2)
        resp, _ = self.object_client.create_object(self.container_name,
                                                   src_object_name,
                                                   src_data)
        # create destination object
        dst_object_name = data_utils.rand_name(name='DstObject')
        dst_data = data_utils.random_bytes(size=len(dst_object_name) * 3)
        resp, _ = self.object_client.create_object(self.container_name,
                                                   dst_object_name,
                                                   dst_data)
        # copy source object to destination
        headers = {}
        headers['X-Copy-From'] = "%s/%s" % (str(self.container_name),
                                            str(src_object_name))
        resp, body = self.object_client.create_object(self.container_name,
                                                      dst_object_name,
                                                      data=None,
                                                      headers=headers)
        self.assertHeaders(resp, 'Object', 'PUT')

        # check data
        resp, body = self.object_client.get_object(self.container_name,
                                                   dst_object_name)
        self.assertEqual(body, src_data)
开发者ID:Juniper,项目名称:tempest,代码行数:27,代码来源:test_object_services.py


示例2: test_random_bytes

    def test_random_bytes(self):
        actual = data_utils.random_bytes()  # default size=1024
        self.assertIsInstance(actual, bytes)
        self.assertEqual(1024, len(actual))
        actual2 = data_utils.random_bytes()
        self.assertNotEqual(actual, actual2)

        actual = data_utils.random_bytes(size=2048)
        self.assertEqual(2048, len(actual))
开发者ID:Tesora,项目名称:tesora-tempest,代码行数:9,代码来源:test_data_utils.py


示例3: test_random_bytes

    def test_random_bytes(self):
        actual = data_utils.random_bytes()  # default size=1024
        self.assertIsInstance(actual, str)
        self.assertRegex(actual, "^[\x00-\xFF]{1024}")
        actual2 = data_utils.random_bytes()
        self.assertNotEqual(actual, actual2)

        actual = data_utils.random_bytes(size=2048)
        self.assertRegex(actual, "^[\x00-\xFF]{2048}")
开发者ID:dwalleck,项目名称:tempest,代码行数:9,代码来源:test_data_utils.py


示例4: _create_manifest

    def _create_manifest(self):
        # Create a manifest file for SLO uploading
        object_name = data_utils.rand_name(name='TestObject')
        object_name_base_1 = object_name + '_01'
        object_name_base_2 = object_name + '_02'
        data_size = MIN_SEGMENT_SIZE
        self.content = data_utils.random_bytes(data_size)
        self._create_object(self.container_name,
                            object_name_base_1,
                            self.content)
        self._create_object(self.container_name,
                            object_name_base_2,
                            self.content)

        path_object_1 = '/%s/%s' % (self.container_name,
                                    object_name_base_1)
        path_object_2 = '/%s/%s' % (self.container_name,
                                    object_name_base_2)
        data_manifest = [{'path': path_object_1,
                          'etag': hashlib.md5(self.content).hexdigest(),
                          'size_bytes': data_size},
                         {'path': path_object_2,
                          'etag': hashlib.md5(self.content).hexdigest(),
                          'size_bytes': data_size}]

        return json.dumps(data_manifest)
开发者ID:vedujoshi,项目名称:tempest,代码行数:26,代码来源:test_object_slo.py


示例5: test_deactivate_reactivate_image

    def test_deactivate_reactivate_image(self):
        # Create image
        image_name = data_utils.rand_name('image')
        image = self.create_image(name=image_name,
                                  container_format='bare',
                                  disk_format='raw',
                                  visibility='private')

        # Upload an image file
        content = data_utils.random_bytes()
        image_file = six.BytesIO(content)
        self.client.store_image_file(image['id'], image_file)

        # Deactivate image
        self.client.deactivate_image(image['id'])
        body = self.client.show_image(image['id'])
        self.assertEqual("deactivated", body['status'])

        # User unable to download deactivated image
        self.assertRaises(lib_exc.Forbidden, self.client.show_image_file,
                          image['id'])

        # Reactivate image
        self.client.reactivate_image(image['id'])
        body = self.client.show_image(image['id'])
        self.assertEqual("active", body['status'])

        # User able to download image after reactivation
        body = self.client.show_image_file(image['id'])
        self.assertEqual(content, body.data)
开发者ID:openstack,项目名称:tempest,代码行数:30,代码来源:test_images.py


示例6: test_update_image

    def test_update_image(self):
        # Updates an image by image_id

        # Create image
        image_name = data_utils.rand_name('image')
        container_format = CONF.image.container_formats[0]
        disk_format = CONF.image.disk_formats[0]
        image = self.create_image(name=image_name,
                                  container_format=container_format,
                                  disk_format=disk_format,
                                  visibility='private')
        self.assertEqual('queued', image['status'])

        # NOTE: This Glance API returns different status codes for image
        # condition. In this empty data case, Glance should return 204,
        # so here should check the status code.
        image_file = self.client.show_image_file(image['id'])
        self.assertEqual(0, len(image_file.data))
        self.assertEqual(204, image_file.response.status)

        # Now try uploading an image file
        image_file = six.BytesIO(data_utils.random_bytes())
        self.client.store_image_file(image['id'], image_file)

        # Update Image
        new_image_name = data_utils.rand_name('new-image')
        self.client.update_image(image['id'], [
            dict(replace='/name', value=new_image_name)])

        # Verifying updating

        body = self.client.show_image(image['id'])
        self.assertEqual(image['id'], body['id'])
        self.assertEqual(new_image_name, body['name'])
开发者ID:openstack,项目名称:tempest,代码行数:34,代码来源:test_images.py


示例7: test_admin_deactivate_reactivate_image

 def test_admin_deactivate_reactivate_image(self):
     # Create image by non-admin tenant
     image_name = data_utils.rand_name('image')
     body = self.client.create_image(name=image_name,
                                     container_format='bare',
                                     disk_format='raw',
                                     visibility='private')
     image_id = body['id']
     self.addCleanup(self.client.delete_image, image_id)
     # upload an image file
     content = data_utils.random_bytes()
     image_file = moves.cStringIO(content)
     self.client.store_image_file(image_id, image_file)
     # deactivate image
     self.admin_client.deactivate_image(image_id)
     body = self.client.show_image(image_id)
     self.assertEqual("deactivated", body['status'])
     # non-admin user unable to download deactivated image
     self.assertRaises(lib_exc.Forbidden, self.client.show_image_file,
                       image_id)
     # reactivate image
     self.admin_client.reactivate_image(image_id)
     body = self.client.show_image(image_id)
     self.assertEqual("active", body['status'])
     # non-admin user able to download image after reactivation by admin
     body = self.client.show_image_file(image_id)
     self.assertEqual(content, body.data)
开发者ID:Hybrid-Cloud,项目名称:hybrid-tempest,代码行数:27,代码来源:test_images.py


示例8: _create_image

 def _create_image(self):
     image_file = six.BytesIO(data_utils.random_bytes())
     image = self.create_image(container_format='bare',
                               disk_format='raw',
                               is_public=False,
                               data=image_file)
     return image['id']
开发者ID:masayukig,项目名称:tempest,代码行数:7,代码来源:base.py


示例9: test_access_public_container_object_without_using_creds

    def test_access_public_container_object_without_using_creds(self):
        # make container public-readable and access an object in it object
        # anonymously, without using credentials

        # update container metadata to make it publicly readable
        cont_headers = {'X-Container-Read': '.r:*,.rlistings'}
        resp_meta, body = self.container_client.update_container_metadata(
            self.container_name, metadata=cont_headers, metadata_prefix='')
        self.assertHeaders(resp_meta, 'Container', 'POST')

        # create object
        object_name = data_utils.rand_name(name='Object')
        data = data_utils.random_bytes(size=len(object_name))
        resp, _ = self.object_client.create_object(self.container_name,
                                                   object_name, data)
        self.assertHeaders(resp, 'Object', 'PUT')

        # list container metadata
        resp_meta, _ = self.container_client.list_container_metadata(
            self.container_name)
        self.assertHeaders(resp_meta, 'Container', 'HEAD')

        self.assertIn('x-container-read', resp_meta)
        self.assertEqual(resp_meta['x-container-read'], '.r:*,.rlistings')

        # trying to get object with empty headers as it is public readable
        self.object_client.auth_provider.set_alt_auth_data(
            request_part='headers',
            auth_data=None
        )
        resp, body = self.object_client.get_object(
            self.container_name, object_name)
        self.assertHeaders(resp, 'Object', 'GET')

        self.assertEqual(body, data)
开发者ID:vedujoshi,项目名称:tempest,代码行数:35,代码来源:test_object_services.py


示例10: test_update_image

    def test_update_image(self):
        # Updates an image by image_id

        # Create image
        image_name = data_utils.rand_name('image')
        container_format = CONF.image.container_formats[0]
        disk_format = CONF.image.disk_formats[0]
        image = self.create_image(name=image_name,
                                  container_format=container_format,
                                  disk_format=disk_format,
                                  visibility='private')
        self.assertEqual('queued', image['status'])

        # Now try uploading an image file
        image_file = six.BytesIO(data_utils.random_bytes())
        self.client.store_image_file(image['id'], image_file)

        # Update Image
        new_image_name = data_utils.rand_name('new-image')
        body = self.client.update_image(image['id'], [
            dict(replace='/name', value=new_image_name)])

        # Verifying updating

        body = self.client.show_image(image['id'])
        self.assertEqual(image['id'], body['id'])
        self.assertEqual(new_image_name, body['name'])
开发者ID:vedujoshi,项目名称:tempest,代码行数:27,代码来源:test_images.py


示例11: test_update_object_metadata_with_create_and_remove_metadata

    def test_update_object_metadata_with_create_and_remove_metadata(self):
        # creation and deletion of metadata with one request
        object_name = data_utils.rand_name(name='TestObject')
        data = data_utils.random_bytes()
        create_metadata = {'X-Object-Meta-test-meta1': 'Meta1'}
        self.object_client.create_object(self.container_name,
                                         object_name,
                                         data,
                                         metadata=create_metadata)

        update_metadata = {'X-Object-Meta-test-meta2': 'Meta2',
                           'X-Remove-Object-Meta-test-meta1': 'Meta1'}
        resp, _ = self.object_client.update_object_metadata(
            self.container_name,
            object_name,
            update_metadata,
            metadata_prefix='')
        self.assertHeaders(resp, 'Object', 'POST')

        resp, _ = self.object_client.list_object_metadata(
            self.container_name,
            object_name)
        self.assertNotIn('x-object-meta-test-meta1', resp)
        self.assertIn('x-object-meta-test-meta2', resp)
        self.assertEqual(resp['x-object-meta-test-meta2'], 'Meta2')
开发者ID:vedujoshi,项目名称:tempest,代码行数:25,代码来源:test_object_services.py


示例12: test_versioned_container

    def test_versioned_container(self):
        # create container
        vers_container_name = data_utils.rand_name(name='TestVersionContainer')
        resp, body = self.container_client.create_container(
            vers_container_name)
        self.containers.append(vers_container_name)
        self.assertHeaders(resp, 'Container', 'PUT')
        self.assertContainer(vers_container_name, '0', '0', 'Missing Header')

        base_container_name = data_utils.rand_name(name='TestBaseContainer')
        headers = {'X-versions-Location': vers_container_name}
        resp, body = self.container_client.create_container(
            base_container_name,
            metadata=headers,
            metadata_prefix='')
        self.containers.append(base_container_name)
        self.assertHeaders(resp, 'Container', 'PUT')
        self.assertContainer(base_container_name, '0', '0',
                             vers_container_name)
        object_name = data_utils.rand_name(name='TestObject')
        # create object
        data_1 = data_utils.random_bytes()
        resp, _ = self.object_client.create_object(base_container_name,
                                                   object_name, data_1)
        # create 2nd version of object
        data_2 = data_utils.random_bytes()
        resp, _ = self.object_client.create_object(base_container_name,
                                                   object_name, data_2)
        resp, body = self.object_client.get_object(base_container_name,
                                                   object_name)
        self.assertEqual(body, data_2)
        # delete object version 2
        resp, _ = self.object_client.delete_object(base_container_name,
                                                   object_name)
        self.assertContainer(base_container_name, '1', '1024',
                             vers_container_name)
        resp, body = self.object_client.get_object(base_container_name,
                                                   object_name)
        self.assertEqual(body, data_1)
        # delete object version 1
        resp, _ = self.object_client.delete_object(base_container_name,
                                                   object_name)
        # containers should be empty
        self.assertContainer(base_container_name, '0', '0',
                             vers_container_name)
        self.assertContainer(vers_container_name, '0', '0',
                             'Missing Header')
开发者ID:vedujoshi,项目名称:tempest,代码行数:47,代码来源:test_object_version.py


示例13: test_create_object

    def test_create_object(self):
        # create object
        object_name = data_utils.rand_name(name='TestObject')
        data = data_utils.random_bytes()
        resp, _ = self.object_client.create_object(self.container_name,
                                                   object_name, data)
        # create another object
        object_name = data_utils.rand_name(name='TestObject')
        data = data_utils.random_bytes()
        resp, _ = self.object_client.create_object(self.container_name,
                                                   object_name, data)
        self.assertHeaders(resp, 'Object', 'PUT')

        # check uploaded content
        _, body = self.object_client.get_object(self.container_name,
                                                object_name)
        self.assertEqual(data, body)
开发者ID:Juniper,项目名称:tempest,代码行数:17,代码来源:test_object_services.py


示例14: test_store_image_file

    def test_store_image_file(self):
        data = six.BytesIO(data_utils.random_bytes())

        self.check_service_client_function(
            self.client.store_image_file,
            'tempest.lib.common.rest_client.RestClient.raw_request',
            {},
            image_id=self.FAKE_CREATE_UPDATE_SHOW_IMAGE["id"],
            status=204,
            data=data)
开发者ID:Juniper,项目名称:tempest,代码行数:10,代码来源:test_images_client.py


示例15: test_delete_object

 def test_delete_object(self):
     # create object
     object_name = data_utils.rand_name(name='TestObject')
     data = data_utils.random_bytes()
     resp, _ = self.object_client.create_object(self.container_name,
                                                object_name, data)
     # delete object
     resp, _ = self.object_client.delete_object(self.container_name,
                                                object_name)
     self.assertHeaders(resp, 'Object', 'DELETE')
开发者ID:Juniper,项目名称:tempest,代码行数:10,代码来源:test_object_services.py


示例16: test_get_object_with_if_none_match

    def test_get_object_with_if_none_match(self):
        # get object with if_none_match
        object_name = data_utils.rand_name(name='TestObject')
        data = data_utils.random_bytes()
        create_md5 = hashlib.md5(data).hexdigest()
        create_metadata = {'Etag': create_md5}
        self.object_client.create_object(self.container_name,
                                         object_name,
                                         data,
                                         metadata=create_metadata)

        list_data = data_utils.random_bytes()
        list_md5 = hashlib.md5(list_data).hexdigest()
        list_metadata = {'If-None-Match': list_md5}
        resp, body = self.object_client.get_object(
            self.container_name,
            object_name,
            metadata=list_metadata)
        self.assertHeaders(resp, 'Object', 'GET')
        self.assertEqual(body, data)
开发者ID:Juniper,项目名称:tempest,代码行数:20,代码来源:test_object_services.py


示例17: _create_standard_image

    def _create_standard_image(cls, name, container_format,
                               disk_format, size):
        """Create a new standard image and return newly-registered image-id"""

        image_file = six.BytesIO(data_utils.random_bytes(size))
        name = 'New Standard Image %s' % name
        image = cls.create_image(name=name,
                                 container_format=container_format,
                                 disk_format=disk_format,
                                 is_public=False, data=image_file,
                                 properties={'key1': 'value1'})
        return image['id']
开发者ID:Juniper,项目名称:tempest,代码行数:12,代码来源:test_images.py


示例18: test_check_glance_v2_notifications

    def test_check_glance_v2_notifications(self):
        body = self.create_image(self.image_client_v2, visibility='private')

        file_content = data_utils.random_bytes()
        image_file = six.BytesIO(file_content)
        self.image_client_v2.store_image_file(body['id'], image_file)
        self.image_client_v2.show_image_file(body['id'])

        query = 'resource', 'eq', body['id']

        for metric in self.glance_v2_notifications:
            self.await_samples(metric, query)
开发者ID:cloudbase,项目名称:ceilometer,代码行数:12,代码来源:test_telemetry_notification_api.py


示例19: test_copy_object_2d_way

    def test_copy_object_2d_way(self):
        # create source object
        src_object_name = data_utils.rand_name(name='SrcObject')
        src_data = data_utils.random_bytes(size=len(src_object_name) * 2)
        resp, _ = self.object_client.create_object(self.container_name,
                                                   src_object_name, src_data)
        # create destination object
        dst_object_name = data_utils.rand_name(name='DstObject')
        dst_data = data_utils.random_bytes(size=len(dst_object_name) * 3)
        resp, _ = self.object_client.create_object(self.container_name,
                                                   dst_object_name, dst_data)
        # copy source object to destination
        resp, _ = self.object_client.copy_object_2d_way(self.container_name,
                                                        src_object_name,
                                                        dst_object_name)
        self.assertHeaders(resp, 'Object', 'COPY')
        self.assertEqual(
            resp['x-copied-from'],
            self.container_name + "/" + src_object_name)

        # check data
        self._check_copied_obj(dst_object_name, src_data)
开发者ID:Juniper,项目名称:tempest,代码行数:22,代码来源:test_object_services.py


示例20: create_object

    def create_object(cls, container_name, object_name=None,
                      data=None, metadata=None):
        # wrapper that returns a test object
        if object_name is None:
            object_name = data_utils.rand_name(name='TestObject')
        if data is None:
            data = data_utils.random_bytes()
        cls.object_client.create_object(container_name,
                                        object_name,
                                        data,
                                        metadata=metadata)

        return object_name, data
开发者ID:Juniper,项目名称:tempest,代码行数:13,代码来源:base.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python misc.find_test_caller函数代码示例发布时间:2022-05-27
下一篇:
Python data_utils.rand_uuid_hex函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap