]> git-server-git.apps.pok.os.sepia.ceph.com Git - s3-tests.git/commitdiff
Add tests for conditional gets 74/head
authorAndrew Gaul <andrew@gaul.org>
Thu, 13 Aug 2015 01:14:08 +0000 (18:14 -0700)
committerAndrew Gaul <andrew@gaul.org>
Thu, 13 Aug 2015 03:43:50 +0000 (20:43 -0700)
Fixes #72.

Signed-off-by: Andrew Gaul <andrew@gaul.org>
s3tests/functional/test_s3.py

index 3376127bb34eb5cc5f692931cb1dcdd43995f218..885fb0f8d23e4a6415edd6fd0f10b9ca135538c0 100644 (file)
@@ -26,6 +26,7 @@ import random
 
 import xml.etree.ElementTree as ET
 
+from email.Utils import formatdate
 from httplib import HTTPConnection, HTTPSConnection
 from urlparse import urlparse
 
@@ -2119,6 +2120,116 @@ def test_post_object_upload_size_below_minimum():
        eq(r.status_code, 400)
 
 
+@attr(resource='object')
+@attr(method='get')
+@attr(operation='get w/ If-Match: the latest ETag')
+@attr(assertion='succeeds')
+def test_get_object_ifmatch_good():
+    bucket = get_new_bucket()
+    key = bucket.new_key('foo')
+    key.set_contents_from_string('bar')
+
+    new_key = bucket.get_key('foo', headers={'If-Match': key.etag})
+    got = new_key.get_contents_as_string()
+    eq(got, 'bar')
+
+@attr(resource='object')
+@attr(method='get')
+@attr(operation='get w/ If-Match: bogus ETag')
+@attr(assertion='fails 412')
+def test_get_object_ifmatch_failed():
+    bucket = get_new_bucket()
+    key = bucket.new_key('foo')
+    key.set_contents_from_string('bar')
+
+    e = assert_raises(boto.exception.S3ResponseError, bucket.get_key, 'foo', headers={'If-Match': 'ABCORZ'})
+    eq(e.status, 412)
+    eq(e.reason, 'Precondition Failed')
+
+@attr(resource='object')
+@attr(method='get')
+@attr(operation='get w/ If-None-Match: the latest ETag')
+@attr(assertion='fails 304')
+def test_get_object_ifnonematch_good():
+    bucket = get_new_bucket()
+    key = bucket.new_key('foo')
+    key.set_contents_from_string('bar')
+
+    e = assert_raises(boto.exception.S3ResponseError, bucket.get_key, 'foo', headers={'If-None-Match': key.etag})
+    eq(e.status, 304)
+    eq(e.reason, 'Not Modified')
+
+@attr(resource='object')
+@attr(method='get')
+@attr(operation='get w/ If-None-Match: bogus ETag')
+@attr(assertion='succeeds')
+def test_get_object_ifnonematch_failed():
+    bucket = get_new_bucket()
+    key = bucket.new_key('foo')
+    key.set_contents_from_string('bar')
+
+    new_key = bucket.get_key('foo', headers={'If-None-Match': 'ABCORZ'})
+    got = new_key.get_contents_as_string()
+    eq(got, 'bar')
+
+@attr(resource='object')
+@attr(method='get')
+@attr(operation='get w/ If-Modified-Since: before')
+@attr(assertion='succeeds')
+def test_get_object_ifmodifiedsince_good():
+    bucket = get_new_bucket()
+    key = bucket.new_key('foo')
+    key.set_contents_from_string('bar')
+
+    new_key = bucket.get_key('foo', headers={'If-Modified-Since': 'Sat, 29 Oct 1994 19:43:31 GMT'})
+    got = new_key.get_contents_as_string()
+    eq(got, 'bar')
+
+@attr(resource='object')
+@attr(method='get')
+@attr(operation='get w/ If-Modified-Since: after')
+@attr(assertion='fails 304')
+def test_get_object_ifmodifiedsince_failed():
+    bucket = get_new_bucket()
+    key = bucket.new_key('foo')
+    key.set_contents_from_string('bar')
+
+    # Sleep since Amazon returns 200 if the date is in the future:
+    # https://forums.aws.amazon.com/message.jspa?messageID=325930
+    now = time.time()
+    time.sleep(20)
+    after = formatdate(now + 10)
+
+    e = assert_raises(boto.exception.S3ResponseError, bucket.get_key, 'foo', headers={'If-Modified-Since': after})
+    eq(e.status, 304)
+    eq(e.reason, 'Not Modified')
+
+@attr(resource='object')
+@attr(method='get')
+@attr(operation='get w/ If-Unmodified-Since: before')
+@attr(assertion='fails 412')
+def test_get_object_ifunmodifiedsince_good():
+    bucket = get_new_bucket()
+    key = bucket.new_key('foo')
+    key.set_contents_from_string('bar')
+
+    e = assert_raises(boto.exception.S3ResponseError, bucket.get_key, 'foo', headers={'If-Unmodified-Since': 'Sat, 29 Oct 1994 19:43:31 GMT'})
+    eq(e.status, 412)
+    eq(e.reason, 'Precondition Failed')
+
+@attr(resource='object')
+@attr(method='get')
+@attr(operation='get w/ If-Unmodified-Since: after')
+@attr(assertion='succeeds')
+def test_get_object_ifunmodifiedsince_failed():
+    bucket = get_new_bucket()
+    key = bucket.new_key('foo')
+    key.set_contents_from_string('bar')
+
+    new_key = bucket.get_key('foo', headers={'If-Unmodified-Since': 'Tue, 29 Oct 2030 19:43:31 GMT'})
+    got = new_key.get_contents_as_string()
+    eq(got, 'bar')
+
 @attr(resource='object')
 @attr(method='put')
 @attr(operation='data re-write w/ If-Match: the latest ETag')