yunify / qingcloud-sdk-python

QingCloud SDK for Python
Apache License 2.0
54 stars 49 forks source link

Add get and set bucket CORS methods #22

Closed markduan closed 7 years ago

osier commented 8 years ago

The method to delete cors is missed, others looks good to me.

osier commented 8 years ago

Please add the method to delete cors. Thanks.

markduan commented 7 years ago

I just add the method to delete CORS, please accept this pull request.

pengsrc commented 7 years ago

Tests for those changes are missing, I will check that.

pengsrc commented 7 years ago

@markduan, for your reference

def test_bucket_get_cors(self):
    body = {
        "cors_rules": [
            {
                "allowed_origin": "http://*.qingcloud.com",
                "allowed_methods": [
                    "PUT",
                    "GET",
                    "DELETE",
                    "POST"
                ],
                "allowed_headers": [
                    "X-QS-Date",
                    "Content-Type",
                    "Content-MD5",
                    "Authorization"
                ],
                "max_age_seconds": 200,
                "expose_headers": [
                    "X-QS-Date"
                ]
            }
        ]
    }
    self.mock_http_response(status_code=200, body=json.dumps(body))
    acls = self.bucket.get_cors()
    self.assertDictEqual(acls, body)

def test_bucket_set_cors(self):
    self.mock_http_response(status_code=200)
    ret = self.bucket.set_cors({
        "cors_rules": [
            {
                "allowed_origin": "http://*.example.com",
                "allowed_methods": [
                    "PUT",
                    "GET",
                    "DELETE",
                    "POST"
                ],
                "allowed_headers": [
                    "*"
                ],
                "max_age_seconds": 400
            }
        ]
    })
    self.assertTrue(ret)

def test_bucket_delete_cors(self):
    self.mock_http_response(status_code=204)
    ret = self.bucket.delete_cors()
    self.assertTrue(ret)
markduan commented 7 years ago

@prettyxw check it again, please.