test_storage_uri.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:cuny-bdif 作者: aristotle-tek 项目源码 文件源码
def testSetAclXml(self):
        """Ensures that calls to the set_xml_acl functions succeed."""
        b = self._MakeBucket()
        k = b.new_key("obj")
        k.set_contents_from_string("stringdata")
        bucket_uri = storage_uri("gs://%s/" % b.name)

        # Get a valid ACL for an object.
        bucket_uri.object_name = "obj"
        bucket_acl = bucket_uri.get_acl()
        bucket_uri.object_name = None

        # Add a permission to the ACL.
        all_users_read_permission = ("<Entry><Scope type='AllUsers'/>"
                                     "<Permission>READ</Permission></Entry>")
        acl_string = re.sub(r"</Entries>",
                           all_users_read_permission + "</Entries>",
                           bucket_acl.to_xml())

        # Test-generated owner IDs are not currently valid for buckets
        acl_no_owner_string = re.sub(r"<Owner>.*</Owner>", "", acl_string)

        # Set ACL on an object.
        bucket_uri.set_xml_acl(acl_string, "obj")
        # Set ACL on a bucket.
        bucket_uri.set_xml_acl(acl_no_owner_string)
        # Set the default ACL for a bucket.
        bucket_uri.set_def_xml_acl(acl_no_owner_string)

        # Verify all the ACLs were successfully applied.
        new_obj_acl_string = k.get_acl().to_xml()
        new_bucket_acl_string = bucket_uri.get_acl().to_xml()
        new_bucket_def_acl_string = bucket_uri.get_def_acl().to_xml()
        self.assertRegexpMatches(new_obj_acl_string, r"AllUsers")
        self.assertRegexpMatches(new_bucket_acl_string, r"AllUsers")
        self.assertRegexpMatches(new_bucket_def_acl_string, r"AllUsers")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号