]> git-server-git.apps.pok.os.sepia.ceph.com Git - s3-tests.git/commitdiff
add test case for lifecycle expiration date. 170/head
authorZhang Shaowen <zhangshaowen@cmss.chinamobile.com>
Mon, 19 Jun 2017 09:52:43 +0000 (17:52 +0800)
committerZhang Shaowen <zhangshaowen@cmss.chinamobile.com>
Tue, 20 Jun 2017 08:07:03 +0000 (16:07 +0800)
Signed-off-by: Zhang Shaowen <zhangshaowen@cmss.chinamobile.com>
s3tests/functional/test_s3.py

index ed87400be86540ab9f09f87fb72c55a285f23c4c..11b4d3bf33349c618217afce91457a7cc94863ed 100644 (file)
@@ -7583,6 +7583,8 @@ def generate_lifecycle_body(rules):
             if 'ExpiredObjectDeleteMarker' in rule['Expiration'].keys():
                 body += '<Expiration><ExpiredObjectDeleteMarker>%s</ExpiredObjectDeleteMarker></Expiration>' \
                         % rule['Expiration']['ExpiredObjectDeleteMarker']
+            elif 'Date' in rule['Expiration'].keys():
+                body += '<Expiration><Date>%s</Date></Expiration>' % rule['Expiration']['Date']
             else:
                 body += '<Expiration><Days>%d</Days></Expiration>' % rule['Expiration']['Days']
         if 'NoncurrentVersionExpiration' in rule.keys():
@@ -7596,6 +7598,73 @@ def generate_lifecycle_body(rules):
     return body
 
 
+@attr(resource='bucket')
+@attr(method='put')
+@attr(operation='set lifecycle config with expiration date')
+@attr('lifecycle')
+def test_lifecycle_set_date():
+    bucket = get_new_bucket()
+    rules = [
+        {'ID': 'rule1', 'Prefix': 'test1/', 'Status': 'Enabled',
+         'Expiration': {'Date': '2017-09-27'}}
+    ]
+    body = generate_lifecycle_body(rules)
+    fp = StringIO(body)
+    md5 = boto.utils.compute_md5(fp)
+    headers = {'Content-MD5': md5[1], 'Content-Type': 'text/xml'}
+    res = bucket.connection.make_request('PUT', bucket.name, data=fp.getvalue(), query_args='lifecycle',
+                                         headers=headers)
+    eq(res.status, 200)
+    eq(res.reason, 'OK')
+
+
+@attr(resource='bucket')
+@attr(method='put')
+@attr(operation='set lifecycle config with not iso8601 date')
+@attr('lifecycle')
+@attr(assertion='fails 400')
+def test_lifecycle_set_invalid_date():
+    bucket = get_new_bucket()
+    rules = [
+        {'ID': 'rule1', 'Prefix': 'test1/', 'Status': 'Enabled',
+         'Expiration': {'Date': '20200101'}}
+    ]
+    body = generate_lifecycle_body(rules)
+    fp = StringIO(body)
+    md5 = boto.utils.compute_md5(fp)
+    headers = {'Content-MD5': md5[1], 'Content-Type': 'text/xml'}
+    res = bucket.connection.make_request('PUT', bucket.name, data=fp.getvalue(), query_args='lifecycle',
+                                         headers=headers)
+    eq(res.status, 400)
+
+
+@attr(resource='bucket')
+@attr(method='put')
+@attr(operation='test lifecycle expiration with date')
+@attr('lifecycle')
+@attr('fails_on_aws')
+def test_lifecycle_expiration_date():
+    bucket = get_new_bucket()
+    _create_keys(bucket=bucket, keys=['past/foo', 'future/bar'])
+    init_keys = bucket.get_all_keys()
+    rules = [
+        {'ID': 'rule1', 'Prefix': 'past/', 'Status': 'Enabled',
+         'Expiration': {'Date': '2015-01-01'}},
+        {'ID': 'rule2', 'Prefix': 'future/', 'Status': 'Enabled',
+         'Expiration': {'Date': '2030-01-01'}}
+    ]
+    body = generate_lifecycle_body(rules)
+    fp = StringIO(body)
+    md5 = boto.utils.compute_md5(fp)
+    headers = {'Content-MD5': md5[1], 'Content-Type': 'text/xml'}
+    bucket.connection.make_request('PUT', bucket.name, data=fp.getvalue(), query_args='lifecycle',
+                                         headers=headers)
+    time.sleep(20)
+    expire_keys = bucket.get_all_keys()
+    eq(len(init_keys), 2)
+    eq(len(expire_keys), 1)
+
+
 @attr(resource='bucket')
 @attr(method='put')
 @attr(operation='set lifecycle config with noncurrent version expiration')