pytest: replace nose eq() with assert ==

Signed-off-by: Casey Bodley <cbodley@redhat.com>
This commit is contained in:
Casey Bodley 2023-01-21 14:05:46 -05:00
parent 7e7e8d5a42
commit f5d0bc9be3
12 changed files with 1639 additions and 1660 deletions

View file

@ -19,7 +19,6 @@ from urllib.parse import urlparse
from boto.s3.connection import S3Connection from boto.s3.connection import S3Connection
from nose.tools import eq_ as eq
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
from .utils import assert_raises from .utils import assert_raises
@ -194,9 +193,9 @@ def test_object_create_bad_contentlength_none():
key = _setup_bad_object(remove=('Content-Length',)) key = _setup_bad_object(remove=('Content-Length',))
e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar') e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar')
eq(e.status, 411) assert e.status == 411
eq(e.reason, 'Length Required') assert e.reason == 'Length Required'
eq(e.error_code,'MissingContentLength') assert e.error_code == 'MissingContentLength'
@tag('auth_common') @tag('auth_common')
@ -218,9 +217,9 @@ def test_object_create_bad_contentlength_mismatch_above():
key.should_retry = no_retry key.should_retry = no_retry
e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, content) e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, content)
eq(e.status, 400) assert e.status == 400
eq(e.reason.lower(), 'bad request') # some proxies vary the case assert e.reason.lower() == 'bad request' # some proxies vary the case
eq(e.error_code, 'RequestTimeout') assert e.error_code == 'RequestTimeout'
@tag('auth_common') @tag('auth_common')
@ -234,9 +233,9 @@ def test_object_create_bad_authorization_empty():
key = _setup_bad_object({'Authorization': ''}) key = _setup_bad_object({'Authorization': ''})
e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar') e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar')
eq(e.status, 403) assert e.status == 403
eq(e.reason, 'Forbidden') assert e.reason == 'Forbidden'
eq(e.error_code, 'AccessDenied') assert e.error_code == 'AccessDenied'
@tag('auth_common') @tag('auth_common')
@attr(resource='object') @attr(resource='object')
@ -275,9 +274,9 @@ def test_object_create_bad_authorization_none():
key = _setup_bad_object(remove=('Authorization',)) key = _setup_bad_object(remove=('Authorization',))
e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar') e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar')
eq(e.status, 403) assert e.status == 403
eq(e.reason, 'Forbidden') assert e.reason == 'Forbidden'
eq(e.error_code, 'AccessDenied') assert e.error_code == 'AccessDenied'
@tag('auth_common') @tag('auth_common')
@ -332,8 +331,8 @@ def test_bucket_create_bad_contentlength_empty():
conn = _create_new_connection() conn = _create_new_connection()
_add_custom_headers({'Content-Length': ''}) _add_custom_headers({'Content-Length': ''})
e = assert_raises(boto.exception.S3ResponseError, get_new_bucket, conn) e = assert_raises(boto.exception.S3ResponseError, get_new_bucket, conn)
eq(e.status, 400) assert e.status == 400
eq(e.reason.lower(), 'bad request') # some proxies vary the case assert e.reason.lower() == 'bad request' # some proxies vary the case
@tag('auth_common') @tag('auth_common')
@ -358,9 +357,9 @@ def test_bucket_create_bad_contentlength_none():
def test_bucket_create_bad_authorization_empty(): def test_bucket_create_bad_authorization_empty():
_add_custom_headers({'Authorization': ''}) _add_custom_headers({'Authorization': ''})
e = assert_raises(boto.exception.S3ResponseError, get_new_bucket) e = assert_raises(boto.exception.S3ResponseError, get_new_bucket)
eq(e.status, 403) assert e.status == 403
eq(e.reason, 'Forbidden') assert e.reason == 'Forbidden'
eq(e.error_code, 'AccessDenied') assert e.error_code == 'AccessDenied'
# the teardown is really messed up here. check it out # the teardown is really messed up here. check it out
@ -374,9 +373,9 @@ def test_bucket_create_bad_authorization_empty():
def test_bucket_create_bad_authorization_none(): def test_bucket_create_bad_authorization_none():
_add_custom_headers(remove=('Authorization',)) _add_custom_headers(remove=('Authorization',))
e = assert_raises(boto.exception.S3ResponseError, get_new_bucket) e = assert_raises(boto.exception.S3ResponseError, get_new_bucket)
eq(e.status, 403) assert e.status == 403
eq(e.reason, 'Forbidden') assert e.reason == 'Forbidden'
eq(e.error_code, 'AccessDenied') assert e.error_code == 'AccessDenied'
# #
# AWS2 specific tests # AWS2 specific tests
@ -395,9 +394,9 @@ def test_object_create_bad_contentlength_mismatch_below_aws2():
length = len(content) - 1 length = len(content) - 1
key = _setup_bad_object({'Content-Length': length}) key = _setup_bad_object({'Content-Length': length})
e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, content) e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, content)
eq(e.status, 400) assert e.status == 400
eq(e.reason.lower(), 'bad request') # some proxies vary the case assert e.reason.lower() == 'bad request' # some proxies vary the case
eq(e.error_code, 'BadDigest') assert e.error_code == 'BadDigest'
@tag('auth_aws2') @tag('auth_aws2')
@ -411,8 +410,8 @@ def test_object_create_bad_authorization_incorrect_aws2():
check_aws2_support() check_aws2_support()
key = _setup_bad_object({'Authorization': 'AWS AKIAIGR7ZNNBHC5BKSUB:FWeDfwojDSdS2Ztmpfeubhd9isU='}) key = _setup_bad_object({'Authorization': 'AWS AKIAIGR7ZNNBHC5BKSUB:FWeDfwojDSdS2Ztmpfeubhd9isU='})
e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar') e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar')
eq(e.status, 403) assert e.status == 403
eq(e.reason, 'Forbidden') assert e.reason == 'Forbidden'
assert e.error_code in ('AccessDenied', 'SignatureDoesNotMatch', 'InvalidAccessKeyId') assert e.error_code in ('AccessDenied', 'SignatureDoesNotMatch', 'InvalidAccessKeyId')
@ -427,9 +426,9 @@ def test_object_create_bad_authorization_invalid_aws2():
check_aws2_support() check_aws2_support()
key = _setup_bad_object({'Authorization': 'AWS HAHAHA'}) key = _setup_bad_object({'Authorization': 'AWS HAHAHA'})
e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar') e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar')
eq(e.status, 400) assert e.status == 400
eq(e.reason.lower(), 'bad request') # some proxies vary the case assert e.reason.lower() == 'bad request' # some proxies vary the case
eq(e.error_code, 'InvalidArgument') assert e.error_code == 'InvalidArgument'
@tag('auth_aws2') @tag('auth_aws2')
@attr(resource='object') @attr(resource='object')
@ -442,9 +441,9 @@ def test_object_create_bad_date_none_aws2():
check_aws2_support() check_aws2_support()
key = _setup_bad_object(remove=('Date',)) key = _setup_bad_object(remove=('Date',))
e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar') e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar')
eq(e.status, 403) assert e.status == 403
eq(e.reason, 'Forbidden') assert e.reason == 'Forbidden'
eq(e.error_code, 'AccessDenied') assert e.error_code == 'AccessDenied'
@tag('auth_aws2') @tag('auth_aws2')
@ -456,9 +455,9 @@ def test_bucket_create_bad_authorization_invalid_aws2():
check_aws2_support() check_aws2_support()
_add_custom_headers({'Authorization': 'AWS HAHAHA'}) _add_custom_headers({'Authorization': 'AWS HAHAHA'})
e = assert_raises(boto.exception.S3ResponseError, get_new_bucket) e = assert_raises(boto.exception.S3ResponseError, get_new_bucket)
eq(e.status, 400) assert e.status == 400
eq(e.reason.lower(), 'bad request') # some proxies vary the case assert e.reason.lower() == 'bad request' # some proxies vary the case
eq(e.error_code, 'InvalidArgument') assert e.error_code == 'InvalidArgument'
@tag('auth_aws2') @tag('auth_aws2')
@attr(resource='bucket') @attr(resource='bucket')
@ -471,9 +470,9 @@ def test_bucket_create_bad_date_none_aws2():
check_aws2_support() check_aws2_support()
_add_custom_headers(remove=('Date',)) _add_custom_headers(remove=('Date',))
e = assert_raises(boto.exception.S3ResponseError, get_new_bucket) e = assert_raises(boto.exception.S3ResponseError, get_new_bucket)
eq(e.status, 403) assert e.status == 403
eq(e.reason, 'Forbidden') assert e.reason == 'Forbidden'
eq(e.error_code, 'AccessDenied') assert e.error_code == 'AccessDenied'
# #
# AWS4 specific tests # AWS4 specific tests
@ -498,9 +497,9 @@ def test_object_create_bad_md5_invalid_garbage_aws4():
key = _setup_bad_object({'Content-MD5':'AWS4 HAHAHA'}) key = _setup_bad_object({'Content-MD5':'AWS4 HAHAHA'})
e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar') e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar')
eq(e.status, 400) assert e.status == 400
eq(e.reason.lower(), 'bad request') # some proxies vary the case assert e.reason.lower() == 'bad request' # some proxies vary the case
eq(e.error_code, 'InvalidDigest') assert e.error_code == 'InvalidDigest'
@tag('auth_aws4') @tag('auth_aws4')
@ -515,9 +514,9 @@ def test_object_create_bad_contentlength_mismatch_below_aws4():
key = _setup_bad_object({'Content-Length': length}) key = _setup_bad_object({'Content-Length': length})
e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, content) e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, content)
eq(e.status, 400) assert e.status == 400
eq(e.reason.lower(), 'bad request') # some proxies vary the case assert e.reason.lower() == 'bad request' # some proxies vary the case
eq(e.error_code, 'XAmzContentSHA256Mismatch') assert e.error_code == 'XAmzContentSHA256Mismatch'
@tag('auth_aws4') @tag('auth_aws4')
@ -530,8 +529,8 @@ def test_object_create_bad_authorization_incorrect_aws4():
key = _setup_bad_object({'Authorization': 'AWS4-HMAC-SHA256 Credential=AKIAIGR7ZNNBHC5BKSUB/20150930/us-east-1/s3/aws4_request,SignedHeaders=host;user-agent,Signature=FWeDfwojDSdS2Ztmpfeubhd9isU='}) key = _setup_bad_object({'Authorization': 'AWS4-HMAC-SHA256 Credential=AKIAIGR7ZNNBHC5BKSUB/20150930/us-east-1/s3/aws4_request,SignedHeaders=host;user-agent,Signature=FWeDfwojDSdS2Ztmpfeubhd9isU='})
e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar') e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar')
eq(e.status, 403) assert e.status == 403
eq(e.reason, 'Forbidden') assert e.reason == 'Forbidden'
assert e.error_code in ('AccessDenied', 'SignatureDoesNotMatch', 'InvalidAccessKeyId') assert e.error_code in ('AccessDenied', 'SignatureDoesNotMatch', 'InvalidAccessKeyId')
@ -545,8 +544,8 @@ def test_object_create_bad_authorization_invalid_aws4():
key = _setup_bad_object({'Authorization': 'AWS4-HMAC-SHA256 Credential=HAHAHA'}) key = _setup_bad_object({'Authorization': 'AWS4-HMAC-SHA256 Credential=HAHAHA'})
e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar') e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar')
eq(e.status, 400) assert e.status == 400
eq(e.reason.lower(), 'bad request') # some proxies vary the case assert e.reason.lower() == 'bad request' # some proxies vary the case
assert e.error_code in ('AuthorizationHeaderMalformed', 'InvalidArgument') assert e.error_code in ('AuthorizationHeaderMalformed', 'InvalidArgument')
@ -560,9 +559,9 @@ def test_object_create_bad_ua_empty_aws4():
key = _setup_bad_object({'User-Agent': ''}) key = _setup_bad_object({'User-Agent': ''})
e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar') e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar')
eq(e.status, 403) assert e.status == 403
eq(e.reason, 'Forbidden') assert e.reason == 'Forbidden'
eq(e.error_code, 'SignatureDoesNotMatch') assert e.error_code == 'SignatureDoesNotMatch'
@tag('auth_aws4') @tag('auth_aws4')
@ -575,9 +574,9 @@ def test_object_create_bad_ua_none_aws4():
key = _setup_bad_object(remove=('User-Agent',)) key = _setup_bad_object(remove=('User-Agent',))
e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar') e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar')
eq(e.status, 403) assert e.status == 403
eq(e.reason, 'Forbidden') assert e.reason == 'Forbidden'
eq(e.error_code, 'SignatureDoesNotMatch') assert e.error_code == 'SignatureDoesNotMatch'
@tag('auth_aws4') @tag('auth_aws4')
@ -601,8 +600,8 @@ def test_object_create_bad_amz_date_invalid_aws4():
key = _setup_bad_object({'X-Amz-Date': 'Bad Date'}) key = _setup_bad_object({'X-Amz-Date': 'Bad Date'})
e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar') e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar')
eq(e.status, 403) assert e.status == 403
eq(e.reason, 'Forbidden') assert e.reason == 'Forbidden'
assert e.error_code in ('AccessDenied', 'SignatureDoesNotMatch') assert e.error_code in ('AccessDenied', 'SignatureDoesNotMatch')
@ -627,8 +626,8 @@ def test_object_create_bad_amz_date_empty_aws4():
key = _setup_bad_object({'X-Amz-Date': ''}) key = _setup_bad_object({'X-Amz-Date': ''})
e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar') e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar')
eq(e.status, 403) assert e.status == 403
eq(e.reason, 'Forbidden') assert e.reason == 'Forbidden'
assert e.error_code in ('AccessDenied', 'SignatureDoesNotMatch') assert e.error_code in ('AccessDenied', 'SignatureDoesNotMatch')
@ -653,8 +652,8 @@ def test_object_create_bad_amz_date_none_aws4():
key = _setup_bad_object(remove=('X-Amz-Date',)) key = _setup_bad_object(remove=('X-Amz-Date',))
e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar') e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar')
eq(e.status, 403) assert e.status == 403
eq(e.reason, 'Forbidden') assert e.reason == 'Forbidden'
assert e.error_code in ('AccessDenied', 'SignatureDoesNotMatch') assert e.error_code in ('AccessDenied', 'SignatureDoesNotMatch')
@ -679,8 +678,8 @@ def test_object_create_bad_amz_date_before_today_aws4():
key = _setup_bad_object({'X-Amz-Date': '20100707T215304Z'}) key = _setup_bad_object({'X-Amz-Date': '20100707T215304Z'})
e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar') e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar')
eq(e.status, 403) assert e.status == 403
eq(e.reason, 'Forbidden') assert e.reason == 'Forbidden'
assert e.error_code in ('RequestTimeTooSkewed', 'SignatureDoesNotMatch') assert e.error_code in ('RequestTimeTooSkewed', 'SignatureDoesNotMatch')
@ -705,8 +704,8 @@ def test_object_create_bad_amz_date_after_today_aws4():
key = _setup_bad_object({'X-Amz-Date': '20300707T215304Z'}) key = _setup_bad_object({'X-Amz-Date': '20300707T215304Z'})
e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar') e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar')
eq(e.status, 403) assert e.status == 403
eq(e.reason, 'Forbidden') assert e.reason == 'Forbidden'
assert e.error_code in ('RequestTimeTooSkewed', 'SignatureDoesNotMatch') assert e.error_code in ('RequestTimeTooSkewed', 'SignatureDoesNotMatch')
@ -731,8 +730,8 @@ def test_object_create_bad_amz_date_before_epoch_aws4():
key = _setup_bad_object({'X-Amz-Date': '19500707T215304Z'}) key = _setup_bad_object({'X-Amz-Date': '19500707T215304Z'})
e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar') e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar')
eq(e.status, 403) assert e.status == 403
eq(e.reason, 'Forbidden') assert e.reason == 'Forbidden'
assert e.error_code in ('AccessDenied', 'SignatureDoesNotMatch') assert e.error_code in ('AccessDenied', 'SignatureDoesNotMatch')
@ -757,8 +756,8 @@ def test_object_create_bad_amz_date_after_end_aws4():
key = _setup_bad_object({'X-Amz-Date': '99990707T215304Z'}) key = _setup_bad_object({'X-Amz-Date': '99990707T215304Z'})
e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar') e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar')
eq(e.status, 403) assert e.status == 403
eq(e.reason, 'Forbidden') assert e.reason == 'Forbidden'
assert e.error_code in ('RequestTimeTooSkewed', 'SignatureDoesNotMatch') assert e.error_code in ('RequestTimeTooSkewed', 'SignatureDoesNotMatch')
@ -788,8 +787,8 @@ def test_object_create_missing_signed_custom_header_aws4():
res =_make_raw_request(host=s3.main.host, port=s3.main.port, method=method, path=path, res =_make_raw_request(host=s3.main.host, port=s3.main.port, method=method, path=path,
body=body, request_headers=request_headers, secure=s3.main.is_secure) body=body, request_headers=request_headers, secure=s3.main.is_secure)
eq(res.status, 403) assert res.status == 403
eq(res.reason, 'Forbidden') assert res.reason == 'Forbidden'
@tag('auth_aws4') @tag('auth_aws4')
@ -819,8 +818,8 @@ def test_object_create_missing_signed_header_aws4():
res =_make_raw_request(host=s3.main.host, port=s3.main.port, method=method, path=path, res =_make_raw_request(host=s3.main.host, port=s3.main.port, method=method, path=path,
body=body, request_headers=request_headers, secure=s3.main.is_secure) body=body, request_headers=request_headers, secure=s3.main.is_secure)
eq(res.status, 403) assert res.status == 403
eq(res.reason, 'Forbidden') assert res.reason == 'Forbidden'
@tag('auth_aws4') @tag('auth_aws4')
@ -833,9 +832,9 @@ def test_bucket_create_bad_authorization_invalid_aws4():
_add_custom_headers({'Authorization': 'AWS4 HAHAHA'}) _add_custom_headers({'Authorization': 'AWS4 HAHAHA'})
e = assert_raises(boto.exception.S3ResponseError, get_new_bucket) e = assert_raises(boto.exception.S3ResponseError, get_new_bucket)
eq(e.status, 400) assert e.status == 400
eq(e.reason.lower(), 'bad request') # some proxies vary the case assert e.reason.lower() == 'bad request' # some proxies vary the case
eq(e.error_code, 'InvalidArgument') assert e.error_code == 'InvalidArgument'
@tag('auth_aws4') @tag('auth_aws4')
@ -848,9 +847,9 @@ def test_bucket_create_bad_ua_empty_aws4():
_add_custom_headers({'User-Agent': ''}) _add_custom_headers({'User-Agent': ''})
e = assert_raises(boto.exception.S3ResponseError, get_new_bucket) e = assert_raises(boto.exception.S3ResponseError, get_new_bucket)
eq(e.status, 403) assert e.status == 403
eq(e.reason, 'Forbidden') assert e.reason == 'Forbidden'
eq(e.error_code, 'SignatureDoesNotMatch') assert e.error_code == 'SignatureDoesNotMatch'
@tag('auth_aws4') @tag('auth_aws4')
@attr(resource='bucket') @attr(resource='bucket')
@ -862,9 +861,9 @@ def test_bucket_create_bad_ua_none_aws4():
_add_custom_headers(remove=('User-Agent',)) _add_custom_headers(remove=('User-Agent',))
e = assert_raises(boto.exception.S3ResponseError, get_new_bucket) e = assert_raises(boto.exception.S3ResponseError, get_new_bucket)
eq(e.status, 403) assert e.status == 403
eq(e.reason, 'Forbidden') assert e.reason == 'Forbidden'
eq(e.error_code, 'SignatureDoesNotMatch') assert e.error_code == 'SignatureDoesNotMatch'
@tag('auth_aws4') @tag('auth_aws4')
@ -888,8 +887,8 @@ def test_bucket_create_bad_amz_date_invalid_aws4():
_add_custom_headers({'X-Amz-Date': 'Bad Date'}) _add_custom_headers({'X-Amz-Date': 'Bad Date'})
e = assert_raises(boto.exception.S3ResponseError, get_new_bucket) e = assert_raises(boto.exception.S3ResponseError, get_new_bucket)
eq(e.status, 403) assert e.status == 403
eq(e.reason, 'Forbidden') assert e.reason == 'Forbidden'
assert e.error_code in ('AccessDenied', 'SignatureDoesNotMatch') assert e.error_code in ('AccessDenied', 'SignatureDoesNotMatch')
@ -914,8 +913,8 @@ def test_bucket_create_bad_amz_date_empty_aws4():
_add_custom_headers({'X-Amz-Date': ''}) _add_custom_headers({'X-Amz-Date': ''})
e = assert_raises(boto.exception.S3ResponseError, get_new_bucket) e = assert_raises(boto.exception.S3ResponseError, get_new_bucket)
eq(e.status, 403) assert e.status == 403
eq(e.reason, 'Forbidden') assert e.reason == 'Forbidden'
assert e.error_code in ('AccessDenied', 'SignatureDoesNotMatch') assert e.error_code in ('AccessDenied', 'SignatureDoesNotMatch')
@tag('auth_aws4') @tag('auth_aws4')
@ -939,8 +938,8 @@ def test_bucket_create_bad_amz_date_none_aws4():
_add_custom_headers(remove=('X-Amz-Date',)) _add_custom_headers(remove=('X-Amz-Date',))
e = assert_raises(boto.exception.S3ResponseError, get_new_bucket) e = assert_raises(boto.exception.S3ResponseError, get_new_bucket)
eq(e.status, 403) assert e.status == 403
eq(e.reason, 'Forbidden') assert e.reason == 'Forbidden'
assert e.error_code in ('AccessDenied', 'SignatureDoesNotMatch') assert e.error_code in ('AccessDenied', 'SignatureDoesNotMatch')
@ -965,8 +964,8 @@ def test_bucket_create_bad_amz_date_before_today_aws4():
_add_custom_headers({'X-Amz-Date': '20100707T215304Z'}) _add_custom_headers({'X-Amz-Date': '20100707T215304Z'})
e = assert_raises(boto.exception.S3ResponseError, get_new_bucket) e = assert_raises(boto.exception.S3ResponseError, get_new_bucket)
eq(e.status, 403) assert e.status == 403
eq(e.reason, 'Forbidden') assert e.reason == 'Forbidden'
assert e.error_code in ('RequestTimeTooSkewed', 'SignatureDoesNotMatch') assert e.error_code in ('RequestTimeTooSkewed', 'SignatureDoesNotMatch')
@ -991,8 +990,8 @@ def test_bucket_create_bad_amz_date_after_today_aws4():
_add_custom_headers({'X-Amz-Date': '20300707T215304Z'}) _add_custom_headers({'X-Amz-Date': '20300707T215304Z'})
e = assert_raises(boto.exception.S3ResponseError, get_new_bucket) e = assert_raises(boto.exception.S3ResponseError, get_new_bucket)
eq(e.status, 403) assert e.status == 403
eq(e.reason, 'Forbidden') assert e.reason == 'Forbidden'
assert e.error_code in ('RequestTimeTooSkewed', 'SignatureDoesNotMatch') assert e.error_code in ('RequestTimeTooSkewed', 'SignatureDoesNotMatch')
@ -1017,6 +1016,6 @@ def test_bucket_create_bad_amz_date_before_epoch_aws4():
_add_custom_headers({'X-Amz-Date': '19500707T215304Z'}) _add_custom_headers({'X-Amz-Date': '19500707T215304Z'})
e = assert_raises(boto.exception.S3ResponseError, get_new_bucket) e = assert_raises(boto.exception.S3ResponseError, get_new_bucket)
eq(e.status, 403) assert e.status == 403
eq(e.reason, 'Forbidden') assert e.reason == 'Forbidden'
assert e.error_code in ('AccessDenied', 'SignatureDoesNotMatch') assert e.error_code in ('AccessDenied', 'SignatureDoesNotMatch')

View file

@ -28,7 +28,6 @@ import re
from collections import defaultdict from collections import defaultdict
from urllib.parse import urlparse from urllib.parse import urlparse
from nose.tools import eq_ as eq
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
from . import utils from . import utils
@ -55,9 +54,9 @@ from . import (
def check_access_denied(fn, *args, **kwargs): def check_access_denied(fn, *args, **kwargs):
e = assert_raises(boto.exception.S3ResponseError, fn, *args, **kwargs) e = assert_raises(boto.exception.S3ResponseError, fn, *args, **kwargs)
eq(e.status, 403) assert e.status == 403
eq(e.reason, 'Forbidden') assert e.reason == 'Forbidden'
eq(e.error_code, 'AccessDenied') assert e.error_code == 'AccessDenied'
def check_bad_bucket_name(name): def check_bad_bucket_name(name):
""" """
@ -65,9 +64,9 @@ def check_bad_bucket_name(name):
that the request fails because of an invalid bucket name. that the request fails because of an invalid bucket name.
""" """
e = assert_raises(boto.exception.S3ResponseError, get_new_bucket, targets.main.default, name) e = assert_raises(boto.exception.S3ResponseError, get_new_bucket, targets.main.default, name)
eq(e.status, 400) assert e.status == 400
eq(e.reason.lower(), 'bad request') # some proxies vary the case assert e.reason.lower() == 'bad request' # some proxies vary the case
eq(e.error_code, 'InvalidBucketName') assert e.error_code == 'InvalidBucketName'
def _create_keys(bucket=None, keys=[]): def _create_keys(bucket=None, keys=[]):
""" """
@ -108,9 +107,9 @@ def test_bucket_create_naming_bad_punctuation():
def check_versioning(bucket, status): def check_versioning(bucket, status):
try: try:
eq(bucket.get_versioning_status()['Versioning'], status) assert bucket.get_versioning_status()['Versioning'] == status
except KeyError: except KeyError:
eq(status, None) assert status == None
# amazon is eventual consistent, retry a bit if failed # amazon is eventual consistent, retry a bit if failed
def check_configure_versioning_retry(bucket, status, expected_string): def check_configure_versioning_retry(bucket, status, expected_string):
@ -129,7 +128,7 @@ def check_configure_versioning_retry(bucket, status, expected_string):
time.sleep(1) time.sleep(1)
eq(expected_string, read_status) assert expected_string == read_status
@attr(resource='object') @attr(resource='object')
@attr(method='create') @attr(method='create')
@ -152,7 +151,7 @@ def test_versioning_obj_read_not_exist_null():
key.set_contents_from_string(content) key.set_contents_from_string(content)
key = bucket.get_key(objname, version_id='null') key = bucket.get_key(objname, version_id='null')
eq(key, None) assert key == None
@attr(resource='object') @attr(resource='object')
@attr(method='put') @attr(method='put')
@ -177,11 +176,11 @@ def test_append_object():
res = _make_raw_request(host=s3.main.host, port=s3.main.port, method='PUT', path=path1, body='abc', secure=s3.main.is_secure) res = _make_raw_request(host=s3.main.host, port=s3.main.port, method='PUT', path=path1, body='abc', secure=s3.main.is_secure)
path2 = path + '&append&position=3' path2 = path + '&append&position=3'
res = _make_raw_request(host=s3.main.host, port=s3.main.port, method='PUT', path=path2, body='abc', secure=s3.main.is_secure) res = _make_raw_request(host=s3.main.host, port=s3.main.port, method='PUT', path=path2, body='abc', secure=s3.main.is_secure)
eq(res.status, 200) assert res.status == 200
eq(res.reason, 'OK') assert res.reason == 'OK'
key = bucket.get_key('foo') key = bucket.get_key('foo')
eq(key.size, 6) assert key.size == 6
@attr(resource='object') @attr(resource='object')
@attr(method='put') @attr(method='put')
@ -205,7 +204,7 @@ def test_append_normal_object():
path = o.path + '?' + o.query path = o.path + '?' + o.query
path = path + '&append&position=3' path = path + '&append&position=3'
res = _make_raw_request(host=s3.main.host, port=s3.main.port, method='PUT', path=path, body='abc', secure=s3.main.is_secure) res = _make_raw_request(host=s3.main.host, port=s3.main.port, method='PUT', path=path, body='abc', secure=s3.main.is_secure)
eq(res.status, 409) assert res.status == 409
@attr(resource='object') @attr(resource='object')
@ -231,8 +230,8 @@ def test_append_object_position_wrong():
res = _make_raw_request(host=s3.main.host, port=s3.main.port, method='PUT', path=path1, body='abc', secure=s3.main.is_secure) res = _make_raw_request(host=s3.main.host, port=s3.main.port, method='PUT', path=path1, body='abc', secure=s3.main.is_secure)
path2 = path + '&append&position=9' path2 = path + '&append&position=9'
res = _make_raw_request(host=s3.main.host, port=s3.main.port, method='PUT', path=path2, body='abc', secure=s3.main.is_secure) res = _make_raw_request(host=s3.main.host, port=s3.main.port, method='PUT', path=path2, body='abc', secure=s3.main.is_secure)
eq(res.status, 409) assert res.status == 409
eq(int(res.getheader('x-rgw-next-append-position')), 3) assert int(res.getheader('x-rgw-next-append-position')) == 3
# TODO rgw log_bucket.set_as_logging_target() gives 403 Forbidden # TODO rgw log_bucket.set_as_logging_target() gives 403 Forbidden
@ -329,13 +328,13 @@ def gen_rand_string(size, chars=string.ascii_uppercase + string.digits):
def verify_object(bucket, k, data=None, storage_class=None): def verify_object(bucket, k, data=None, storage_class=None):
if storage_class: if storage_class:
eq(k.storage_class, storage_class) assert k.storage_class == storage_class
if data: if data:
read_data = k.get_contents_as_string() read_data = k.get_contents_as_string()
equal = data == read_data # avoid spamming log if data not equal equal = data == read_data # avoid spamming log if data not equal
eq(equal, True) assert equal == True
def copy_object_storage_class(src_bucket, src_key, dest_bucket, dest_key, storage_class): def copy_object_storage_class(src_bucket, src_key, dest_bucket, dest_key, storage_class):
query_args=None query_args=None
@ -351,7 +350,7 @@ def copy_object_storage_class(src_bucket, src_key, dest_bucket, dest_key, storag
res = dest_bucket.connection.make_request('PUT', dest_bucket.name, dest_key.name, res = dest_bucket.connection.make_request('PUT', dest_bucket.name, dest_key.name,
query_args=query_args, headers=headers) query_args=query_args, headers=headers)
eq(res.status, 200) assert res.status == 200
def _populate_multipart_key(bucket, kname, size, storage_class=None): def _populate_multipart_key(bucket, kname, size, storage_class=None):
(upload, data) = _multipart_upload(bucket, kname, size, storage_class=storage_class) (upload, data) = _multipart_upload(bucket, kname, size, storage_class=storage_class)
@ -463,8 +462,8 @@ def test_object_storage_class_multipart():
(upload, data) = _multipart_upload(bucket, key, size, storage_class=storage_class) (upload, data) = _multipart_upload(bucket, key, size, storage_class=storage_class)
upload.complete_upload() upload.complete_upload()
key2 = bucket.get_key(key) key2 = bucket.get_key(key)
eq(key2.size, size) assert key2.size == size
eq(key2.storage_class, storage_class) assert key2.storage_class == storage_class
def _do_test_object_modify_storage_class(obj_write_func, size): def _do_test_object_modify_storage_class(obj_write_func, size):
sc = configured_storage_classes() sc = configured_storage_classes()
@ -609,7 +608,7 @@ class FakeFileVerifier(object):
if self.char == None: if self.char == None:
self.char = data[0] self.char = data[0]
self.size += size self.size += size
eq(data.decode(), self.char*size) assert data.decode() == self.char*size
def _verify_atomic_key_data(key, size=-1, char=None): def _verify_atomic_key_data(key, size=-1, char=None):
""" """
@ -618,7 +617,7 @@ def _verify_atomic_key_data(key, size=-1, char=None):
fp_verify = FakeFileVerifier(char) fp_verify = FakeFileVerifier(char)
key.get_contents_to_file(fp_verify) key.get_contents_to_file(fp_verify)
if size >= 0: if size >= 0:
eq(fp_verify.size, size) assert fp_verify.size == size
def _test_atomic_dual_conditional_write(file_size): def _test_atomic_dual_conditional_write(file_size):
""" """
@ -647,9 +646,9 @@ def _test_atomic_dual_conditional_write(file_size):
# key.set_contents_from_file(fp_c, headers={'If-Match': etag_fp_a}) # key.set_contents_from_file(fp_c, headers={'If-Match': etag_fp_a})
e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_file, fp_c, e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_file, fp_c,
headers={'If-Match': etag_fp_a}) headers={'If-Match': etag_fp_a})
eq(e.status, 412) assert e.status == 412
eq(e.reason, 'Precondition Failed') assert e.reason == 'Precondition Failed'
eq(e.error_code, 'PreconditionFailed') assert e.error_code == 'PreconditionFailed'
# verify the file # verify the file
_verify_atomic_key_data(key, file_size, 'B') _verify_atomic_key_data(key, file_size, 'B')
@ -684,9 +683,9 @@ def test_atomic_write_bucket_gone():
key = bucket.new_key('foo') key = bucket.new_key('foo')
fp_a = FakeWriteFile(1024*1024, 'A', remove_bucket) fp_a = FakeWriteFile(1024*1024, 'A', remove_bucket)
e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_file, fp_a) e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_file, fp_a)
eq(e.status, 404) assert e.status == 404
eq(e.reason, 'Not Found') assert e.reason == 'Not Found'
eq(e.error_code, 'NoSuchBucket') assert e.error_code == 'NoSuchBucket'
def _multipart_upload_enc(bucket, s3_key_name, size, part_size=5*1024*1024, def _multipart_upload_enc(bucket, s3_key_name, size, part_size=5*1024*1024,
do_list=None, init_headers=None, part_headers=None, do_list=None, init_headers=None, part_headers=None,
@ -740,7 +739,7 @@ def test_encryption_sse_c_multipart_invalid_chunks_1():
_multipart_upload_enc, bucket, key, objlen, _multipart_upload_enc, bucket, key, objlen,
init_headers=init_headers, part_headers=part_headers, init_headers=init_headers, part_headers=part_headers,
metadata={'foo': 'bar'}) metadata={'foo': 'bar'})
eq(e.status, 400) assert e.status == 400
@attr(resource='object') @attr(resource='object')
@attr(method='put') @attr(method='put')
@ -770,7 +769,7 @@ def test_encryption_sse_c_multipart_invalid_chunks_2():
_multipart_upload_enc, bucket, key, objlen, _multipart_upload_enc, bucket, key, objlen,
init_headers=init_headers, part_headers=part_headers, init_headers=init_headers, part_headers=part_headers,
metadata={'foo': 'bar'}) metadata={'foo': 'bar'})
eq(e.status, 400) assert e.status == 400
@attr(resource='bucket') @attr(resource='bucket')
@attr(method='get') @attr(method='get')
@ -841,18 +840,18 @@ def test_bucket_policy_set_condition_operator_end_with_IfExists():
} }
] ]
}''' % bucket.name }''' % bucket.name
eq(bucket.set_policy(policy), True) assert bucket.set_policy(policy) == True
res = _make_request('GET', bucket.name, bucket.get_key("foo"), res = _make_request('GET', bucket.name, bucket.get_key("foo"),
request_headers={'referer': 'http://www.example.com/'}) request_headers={'referer': 'http://www.example.com/'})
eq(res.status, 200) assert res.status == 200
res = _make_request('GET', bucket.name, bucket.get_key("foo"), res = _make_request('GET', bucket.name, bucket.get_key("foo"),
request_headers={'referer': 'http://www.example.com/index.html'}) request_headers={'referer': 'http://www.example.com/index.html'})
eq(res.status, 200) assert res.status == 200
res = _make_request('GET', bucket.name, bucket.get_key("foo")) res = _make_request('GET', bucket.name, bucket.get_key("foo"))
eq(res.status, 200) assert res.status == 200
res = _make_request('GET', bucket.name, bucket.get_key("foo"), res = _make_request('GET', bucket.name, bucket.get_key("foo"),
request_headers={'referer': 'http://example.com'}) request_headers={'referer': 'http://example.com'})
eq(res.status, 403) assert res.status == 403
def _make_arn_resource(path="*"): def _make_arn_resource(path="*"):
return "arn:aws:s3:::{}".format(path) return "arn:aws:s3:::{}".format(path)

View file

@ -12,7 +12,6 @@ import socket
from urllib.parse import urlparse from urllib.parse import urlparse
from nose.tools import eq_ as eq, ok_ as ok
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
from nose.tools import timed from nose.tools import timed
@ -160,7 +159,7 @@ def _test_website_prep(bucket, xml_template, hardcoded_fields = {}, expect_fail=
# Cleanup for our validation # Cleanup for our validation
common.assert_xml_equal(config_xmlcmp, config_xmlnew) common.assert_xml_equal(config_xmlcmp, config_xmlnew)
#print("config_xmlcmp\n", config_xmlcmp) #print("config_xmlcmp\n", config_xmlcmp)
#eq (config_xmlnew, config_xmlcmp) #assert config_xmlnew == config_xmlcmp
f['WebsiteConfiguration'] = config_xmlcmp f['WebsiteConfiguration'] = config_xmlcmp
return f return f
@ -171,9 +170,9 @@ def __website_expected_reponse_status(res, status, reason):
reason = set([reason]) reason = set([reason])
if status is not IGNORE_FIELD: if status is not IGNORE_FIELD:
ok(res.status in status, 'HTTP code was %s should be %s' % (res.status, status)) assert res.status in status, 'HTTP code was %s should be %s' % (res.status, status)
if reason is not IGNORE_FIELD: if reason is not IGNORE_FIELD:
ok(res.reason in reason, 'HTTP reason was was %s should be %s' % (res.reason, reason)) assert res.reason in reason, 'HTTP reason was was %s should be %s' % (res.reason, reason)
def _website_expected_default_html(**kwargs): def _website_expected_default_html(**kwargs):
fields = [] fields = []
@ -203,22 +202,22 @@ def _website_expected_error_response(res, bucket_name, status, reason, code, con
errorcode = res.getheader('x-amz-error-code', None) errorcode = res.getheader('x-amz-error-code', None)
if errorcode is not None: if errorcode is not None:
if code is not IGNORE_FIELD: if code is not IGNORE_FIELD:
eq(errorcode, code) assert errorcode == code
if not isinstance(content, collections.Container): if not isinstance(content, collections.Container):
content = set([content]) content = set([content])
for f in content: for f in content:
if f is not IGNORE_FIELD and f is not None: if f is not IGNORE_FIELD and f is not None:
f = bytes(f, 'utf-8') f = bytes(f, 'utf-8')
ok(f in body, 'HTML should contain "%s"' % (f, )) assert f in body, 'HTML should contain "%s"' % (f, )
def _website_expected_redirect_response(res, status, reason, new_url): def _website_expected_redirect_response(res, status, reason, new_url):
body = res.read() body = res.read()
print(body) print(body)
__website_expected_reponse_status(res, status, reason) __website_expected_reponse_status(res, status, reason)
loc = res.getheader('Location', None) loc = res.getheader('Location', None)
eq(loc, new_url, 'Location header should be set "%s" != "%s"' % (loc,new_url,)) assert loc == new_url, 'Location header should be set "%s" != "%s"' % (loc,new_url,)
ok(len(body) == 0, 'Body of a redirect should be empty') assert len(body) == 0, 'Body of a redirect should be empty'
def _website_request(bucket_name, path, connect_hostname=None, method='GET', timeout=None): def _website_request(bucket_name, path, connect_hostname=None, method='GET', timeout=None):
url = get_website_url(proto='http', bucket=bucket_name, path=path) url = get_website_url(proto='http', bucket=bucket_name, path=path)
@ -293,7 +292,7 @@ def test_website_public_bucket_list_public_index():
body = res.read() body = res.read()
print(body) print(body)
indexstring = bytes(indexstring, 'utf-8') indexstring = bytes(indexstring, 'utf-8')
eq(body, indexstring) # default content should match index.html set content assert body == indexstring # default content should match index.html set content
__website_expected_reponse_status(res, 200, 'OK') __website_expected_reponse_status(res, 200, 'OK')
indexhtml.delete() indexhtml.delete()
bucket.delete() bucket.delete()
@ -324,7 +323,7 @@ def test_website_private_bucket_list_public_index():
body = res.read() body = res.read()
print(body) print(body)
indexstring = bytes(indexstring, 'utf-8') indexstring = bytes(indexstring, 'utf-8')
eq(body, indexstring, 'default content should match index.html set content') assert body == indexstring, 'default content should match index.html set content'
indexhtml.delete() indexhtml.delete()
bucket.delete() bucket.delete()
@ -533,7 +532,7 @@ def test_website_private_bucket_list_empty_blockederrordoc():
print(body) print(body)
_website_expected_error_response(res, bucket.name, 403, 'Forbidden', 'AccessDenied', content=_website_expected_default_html(Code='AccessDenied'), body=body) _website_expected_error_response(res, bucket.name, 403, 'Forbidden', 'AccessDenied', content=_website_expected_default_html(Code='AccessDenied'), body=body)
errorstring = bytes(errorstring, 'utf-8') errorstring = bytes(errorstring, 'utf-8')
ok(errorstring not in body, 'error content should NOT match error.html set content') assert errorstring not in body, 'error content should NOT match error.html set content'
errorhtml.delete() errorhtml.delete()
bucket.delete() bucket.delete()
@ -586,7 +585,7 @@ def test_website_public_bucket_list_pubilc_errordoc():
except socket.timeout: except socket.timeout:
print('no invalid payload') print('no invalid payload')
ok(resp_len == 0, 'invalid payload') assert resp_len == 0, 'invalid payload'
errorhtml.delete() errorhtml.delete()
bucket.delete() bucket.delete()
@ -615,7 +614,7 @@ def test_website_public_bucket_list_empty_blockederrordoc():
print(body) print(body)
_website_expected_error_response(res, bucket.name, 404, 'Not Found', 'NoSuchKey', content=_website_expected_default_html(Code='NoSuchKey'), body=body) _website_expected_error_response(res, bucket.name, 404, 'Not Found', 'NoSuchKey', content=_website_expected_default_html(Code='NoSuchKey'), body=body)
errorstring = bytes(errorstring, 'utf-8') errorstring = bytes(errorstring, 'utf-8')
ok(errorstring not in body, 'error content should match error.html set content') assert errorstring not in body, 'error content should match error.html set content'
errorhtml.delete() errorhtml.delete()
bucket.delete() bucket.delete()
@ -649,7 +648,7 @@ def test_website_public_bucket_list_private_index_blockederrordoc():
print(body) print(body)
_website_expected_error_response(res, bucket.name, 403, 'Forbidden', 'AccessDenied', content=_website_expected_default_html(Code='AccessDenied'), body=body) _website_expected_error_response(res, bucket.name, 403, 'Forbidden', 'AccessDenied', content=_website_expected_default_html(Code='AccessDenied'), body=body)
errorstring = bytes(errorstring, 'utf-8') errorstring = bytes(errorstring, 'utf-8')
ok(errorstring not in body, 'error content should match error.html set content') assert errorstring not in body, 'error content should match error.html set content'
indexhtml.delete() indexhtml.delete()
errorhtml.delete() errorhtml.delete()
@ -684,7 +683,7 @@ def test_website_private_bucket_list_private_index_blockederrordoc():
print(body) print(body)
_website_expected_error_response(res, bucket.name, 403, 'Forbidden', 'AccessDenied', content=_website_expected_default_html(Code='AccessDenied'), body=body) _website_expected_error_response(res, bucket.name, 403, 'Forbidden', 'AccessDenied', content=_website_expected_default_html(Code='AccessDenied'), body=body)
errorstring = bytes(errorstring, 'utf-8') errorstring = bytes(errorstring, 'utf-8')
ok(errorstring not in body, 'error content should match error.html set content') assert errorstring not in body, 'error content should match error.html set content'
indexhtml.delete() indexhtml.delete()
errorhtml.delete() errorhtml.delete()
@ -889,7 +888,7 @@ def test_website_xredirect_nonwebsite():
headers = {'x-amz-website-redirect-location': redirect_dest} headers = {'x-amz-website-redirect-location': redirect_dest}
k.set_contents_from_string(content, headers=headers, policy='public-read') k.set_contents_from_string(content, headers=headers, policy='public-read')
redirect = k.get_redirect() redirect = k.get_redirect()
eq(k.get_redirect(), redirect_dest) assert k.get_redirect() == redirect_dest
res = _website_request(bucket.name, '/page') res = _website_request(bucket.name, '/page')
body = res.read() body = res.read()
@ -924,7 +923,7 @@ def test_website_xredirect_public_relative():
headers = {'x-amz-website-redirect-location': redirect_dest} headers = {'x-amz-website-redirect-location': redirect_dest}
k.set_contents_from_string(content, headers=headers, policy='public-read') k.set_contents_from_string(content, headers=headers, policy='public-read')
redirect = k.get_redirect() redirect = k.get_redirect()
eq(k.get_redirect(), redirect_dest) assert k.get_redirect() == redirect_dest
res = _website_request(bucket.name, '/page') res = _website_request(bucket.name, '/page')
#new_url = get_website_url(bucket_name=bucket.name, path=redirect_dest) #new_url = get_website_url(bucket_name=bucket.name, path=redirect_dest)
@ -954,7 +953,7 @@ def test_website_xredirect_public_abs():
headers = {'x-amz-website-redirect-location': redirect_dest} headers = {'x-amz-website-redirect-location': redirect_dest}
k.set_contents_from_string(content, headers=headers, policy='public-read') k.set_contents_from_string(content, headers=headers, policy='public-read')
redirect = k.get_redirect() redirect = k.get_redirect()
eq(k.get_redirect(), redirect_dest) assert k.get_redirect() == redirect_dest
res = _website_request(bucket.name, '/page') res = _website_request(bucket.name, '/page')
new_url = get_website_url(proto='http', hostname='example.com', path='/foo') new_url = get_website_url(proto='http', hostname='example.com', path='/foo')
@ -984,7 +983,7 @@ def test_website_xredirect_private_relative():
headers = {'x-amz-website-redirect-location': redirect_dest} headers = {'x-amz-website-redirect-location': redirect_dest}
k.set_contents_from_string(content, headers=headers, policy='private') k.set_contents_from_string(content, headers=headers, policy='private')
redirect = k.get_redirect() redirect = k.get_redirect()
eq(k.get_redirect(), redirect_dest) assert k.get_redirect() == redirect_dest
res = _website_request(bucket.name, '/page') res = _website_request(bucket.name, '/page')
# We get a 403 because the page is private # We get a 403 because the page is private
@ -1014,7 +1013,7 @@ def test_website_xredirect_private_abs():
headers = {'x-amz-website-redirect-location': redirect_dest} headers = {'x-amz-website-redirect-location': redirect_dest}
k.set_contents_from_string(content, headers=headers, policy='private') k.set_contents_from_string(content, headers=headers, policy='private')
redirect = k.get_redirect() redirect = k.get_redirect()
eq(k.get_redirect(), redirect_dest) assert k.get_redirect() == redirect_dest
res = _website_request(bucket.name, '/page') res = _website_request(bucket.name, '/page')
new_url = get_website_url(proto='http', hostname='example.com', path='/foo') new_url = get_website_url(proto='http', hostname='example.com', path='/foo')
@ -1253,8 +1252,8 @@ def routing_check(*args, **kwargs):
if args['code'] >= 200 and args['code'] < 300: if args['code'] >= 200 and args['code'] < 300:
#body = res.read() #body = res.read()
#print(body) #print(body)
#eq(body, args['content'], 'default content should match index.html set content') #assert body == args['content'], 'default content should match index.html set content'
ok(int(res.getheader('Content-Length', -1)) > 0) assert int(res.getheader('Content-Length', -1)) > 0
elif args['code'] >= 300 and args['code'] < 400: elif args['code'] >= 300 and args['code'] < 400:
_website_expected_redirect_response(res, args['code'], IGNORE_FIELD, new_url) _website_expected_redirect_response(res, args['code'], IGNORE_FIELD, new_url)
elif args['code'] >= 400: elif args['code'] >= 400:

View file

@ -1,11 +1,9 @@
from nose.tools import eq_ as eq
from . import utils from . import utils
def test_generate(): def test_generate():
FIVE_MB = 5 * 1024 * 1024 FIVE_MB = 5 * 1024 * 1024
eq(len(''.join(utils.generate_random(0))), 0) assert len(''.join(utils.generate_random(0))) == 0
eq(len(''.join(utils.generate_random(1))), 1) assert len(''.join(utils.generate_random(1))) == 1
eq(len(''.join(utils.generate_random(FIVE_MB - 1))), FIVE_MB - 1) assert len(''.join(utils.generate_random(FIVE_MB - 1))) == FIVE_MB - 1
eq(len(''.join(utils.generate_random(FIVE_MB))), FIVE_MB) assert len(''.join(utils.generate_random(FIVE_MB))) == FIVE_MB
eq(len(''.join(utils.generate_random(FIVE_MB + 1))), FIVE_MB + 1) assert len(''.join(utils.generate_random(FIVE_MB + 1))) == FIVE_MB + 1

View file

@ -3,8 +3,6 @@ import requests
import string import string
import time import time
from nose.tools import eq_ as eq
def assert_raises(excClass, callableObj, *args, **kwargs): def assert_raises(excClass, callableObj, *args, **kwargs):
""" """
Like unittest.TestCase.assertRaises, but returns the exception. Like unittest.TestCase.assertRaises, but returns the exception.
@ -48,7 +46,7 @@ def region_sync_meta(targets, region):
conf = r.conf conf = r.conf
if conf.sync_agent_addr: if conf.sync_agent_addr:
ret = requests.post('http://{addr}:{port}/metadata/incremental'.format(addr = conf.sync_agent_addr, port = conf.sync_agent_port)) ret = requests.post('http://{addr}:{port}/metadata/incremental'.format(addr = conf.sync_agent_addr, port = conf.sync_agent_port))
eq(ret.status_code, 200) assert ret.status_code == 200
if conf.sync_meta_wait: if conf.sync_meta_wait:
time.sleep(conf.sync_meta_wait) time.sleep(conf.sync_meta_wait)

View file

@ -1,5 +1,4 @@
import boto3 import boto3
from nose.tools import eq_ as eq
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
import nose import nose
import pytest import pytest
@ -171,8 +170,8 @@ def tag(*tags):
def test_object_create_bad_md5_invalid_short(): def test_object_create_bad_md5_invalid_short():
e = _add_header_create_bad_object({'Content-MD5':'YWJyYWNhZGFicmE='}) e = _add_header_create_bad_object({'Content-MD5':'YWJyYWNhZGFicmE='})
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 400) assert status == 400
eq(error_code, 'InvalidDigest') assert error_code == 'InvalidDigest'
@tag('auth_common') @tag('auth_common')
@attr(resource='object') @attr(resource='object')
@ -182,8 +181,8 @@ def test_object_create_bad_md5_invalid_short():
def test_object_create_bad_md5_bad(): def test_object_create_bad_md5_bad():
e = _add_header_create_bad_object({'Content-MD5':'rL0Y20xC+Fzt72VPzMSk2A=='}) e = _add_header_create_bad_object({'Content-MD5':'rL0Y20xC+Fzt72VPzMSk2A=='})
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 400) assert status == 400
eq(error_code, 'BadDigest') assert error_code == 'BadDigest'
@tag('auth_common') @tag('auth_common')
@attr(resource='object') @attr(resource='object')
@ -193,8 +192,8 @@ def test_object_create_bad_md5_bad():
def test_object_create_bad_md5_empty(): def test_object_create_bad_md5_empty():
e = _add_header_create_bad_object({'Content-MD5':''}) e = _add_header_create_bad_object({'Content-MD5':''})
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 400) assert status == 400
eq(error_code, 'InvalidDigest') assert error_code == 'InvalidDigest'
@tag('auth_common') @tag('auth_common')
@attr(resource='object') @attr(resource='object')
@ -247,7 +246,7 @@ def test_object_create_bad_expect_none():
def test_object_create_bad_contentlength_empty(): def test_object_create_bad_contentlength_empty():
e = _add_header_create_bad_object({'Content-Length':''}) e = _add_header_create_bad_object({'Content-Length':''})
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 400) assert status == 400
@tag('auth_common') @tag('auth_common')
@attr(resource='object') @attr(resource='object')
@ -262,7 +261,7 @@ def test_object_create_bad_contentlength_negative():
key_name = 'foo' key_name = 'foo'
e = assert_raises(ClientError, client.put_object, Bucket=bucket_name, Key=key_name, ContentLength=-1) e = assert_raises(ClientError, client.put_object, Bucket=bucket_name, Key=key_name, ContentLength=-1)
status = _get_status(e.response) status = _get_status(e.response)
eq(status, 400) assert status == 400
@tag('auth_common') @tag('auth_common')
@attr(resource='object') @attr(resource='object')
@ -276,8 +275,8 @@ def test_object_create_bad_contentlength_none():
remove = 'Content-Length' remove = 'Content-Length'
e = _remove_header_create_bad_object('Content-Length') e = _remove_header_create_bad_object('Content-Length')
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 411) assert status == 411
eq(error_code, 'MissingContentLength') assert error_code == 'MissingContentLength'
@tag('auth_common') @tag('auth_common')
@attr(resource='object') @attr(resource='object')
@ -324,7 +323,7 @@ def test_object_create_bad_contenttype_none():
def test_object_create_bad_authorization_empty(): def test_object_create_bad_authorization_empty():
e = _add_header_create_bad_object({'Authorization': ''}) e = _add_header_create_bad_object({'Authorization': ''})
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 403) assert status == 403
@tag('auth_common') @tag('auth_common')
@attr(resource='object') @attr(resource='object')
@ -366,7 +365,7 @@ def test_object_create_amz_date_and_no_date():
def test_object_create_bad_authorization_none(): def test_object_create_bad_authorization_none():
e = _remove_header_create_bad_object('Authorization') e = _remove_header_create_bad_object('Authorization')
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 403) assert status == 403
@tag('auth_common') @tag('auth_common')
@attr(resource='bucket') @attr(resource='bucket')
@ -416,7 +415,7 @@ def test_bucket_put_bad_canned_acl():
e = assert_raises(ClientError, client.put_bucket_acl, Bucket=bucket_name, ACL='public-read') e = assert_raises(ClientError, client.put_bucket_acl, Bucket=bucket_name, ACL='public-read')
status = _get_status(e.response) status = _get_status(e.response)
eq(status, 400) assert status == 400
@tag('auth_common') @tag('auth_common')
@attr(resource='bucket') @attr(resource='bucket')
@ -454,7 +453,7 @@ def test_bucket_create_bad_contentlength_empty():
headers = {'Content-Length': ''} headers = {'Content-Length': ''}
e = _add_header_create_bad_bucket(headers) e = _add_header_create_bad_bucket(headers)
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 400) assert status == 400
@tag('auth_common') @tag('auth_common')
@attr(resource='bucket') @attr(resource='bucket')
@ -467,7 +466,7 @@ def test_bucket_create_bad_contentlength_negative():
headers = {'Content-Length': '-1'} headers = {'Content-Length': '-1'}
e = _add_header_create_bad_bucket(headers) e = _add_header_create_bad_bucket(headers)
status = _get_status(e.response) status = _get_status(e.response)
eq(status, 400) assert status == 400
@tag('auth_common') @tag('auth_common')
@attr(resource='bucket') @attr(resource='bucket')
@ -493,8 +492,8 @@ def test_bucket_create_bad_authorization_empty():
headers = {'Authorization': ''} headers = {'Authorization': ''}
e = _add_header_create_bad_bucket(headers) e = _add_header_create_bad_bucket(headers)
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 403) assert status == 403
eq(error_code, 'AccessDenied') assert error_code == 'AccessDenied'
@tag('auth_common') @tag('auth_common')
@attr(resource='bucket') @attr(resource='bucket')
@ -507,8 +506,8 @@ def test_bucket_create_bad_authorization_empty():
def test_bucket_create_bad_authorization_none(): def test_bucket_create_bad_authorization_none():
e = _remove_header_create_bad_bucket('Authorization') e = _remove_header_create_bad_bucket('Authorization')
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 403) assert status == 403
eq(error_code, 'AccessDenied') assert error_code == 'AccessDenied'
@tag('auth_aws2') @tag('auth_aws2')
@attr(resource='object') @attr(resource='object')
@ -520,8 +519,8 @@ def test_object_create_bad_md5_invalid_garbage_aws2():
headers = {'Content-MD5': 'AWS HAHAHA'} headers = {'Content-MD5': 'AWS HAHAHA'}
e = _add_header_create_bad_object(headers, v2_client) e = _add_header_create_bad_object(headers, v2_client)
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 400) assert status == 400
eq(error_code, 'InvalidDigest') assert error_code == 'InvalidDigest'
@tag('auth_aws2') @tag('auth_aws2')
@attr(resource='object') @attr(resource='object')
@ -538,8 +537,8 @@ def test_object_create_bad_contentlength_mismatch_below_aws2():
headers = {'Content-Length': str(length)} headers = {'Content-Length': str(length)}
e = _add_header_create_bad_object(headers, v2_client) e = _add_header_create_bad_object(headers, v2_client)
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 400) assert status == 400
eq(error_code, 'BadDigest') assert error_code == 'BadDigest'
@tag('auth_aws2') @tag('auth_aws2')
@attr(resource='object') @attr(resource='object')
@ -554,8 +553,8 @@ def test_object_create_bad_authorization_incorrect_aws2():
headers = {'Authorization': 'AWS AKIAIGR7ZNNBHC5BKSUB:FWeDfwojDSdS2Ztmpfeubhd9isU='} headers = {'Authorization': 'AWS AKIAIGR7ZNNBHC5BKSUB:FWeDfwojDSdS2Ztmpfeubhd9isU='}
e = _add_header_create_bad_object(headers, v2_client) e = _add_header_create_bad_object(headers, v2_client)
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 403) assert status == 403
eq(error_code, 'InvalidDigest') assert error_code == 'InvalidDigest'
@tag('auth_aws2') @tag('auth_aws2')
@attr(resource='object') @attr(resource='object')
@ -570,8 +569,8 @@ def test_object_create_bad_authorization_invalid_aws2():
headers = {'Authorization': 'AWS HAHAHA'} headers = {'Authorization': 'AWS HAHAHA'}
e = _add_header_create_bad_object(headers, v2_client) e = _add_header_create_bad_object(headers, v2_client)
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 400) assert status == 400
eq(error_code, 'InvalidArgument') assert error_code == 'InvalidArgument'
@tag('auth_aws2') @tag('auth_aws2')
@attr(resource='object') @attr(resource='object')
@ -605,8 +604,8 @@ def test_object_create_bad_date_invalid_aws2():
headers = {'x-amz-date': 'Bad Date'} headers = {'x-amz-date': 'Bad Date'}
e = _add_header_create_bad_object(headers, v2_client) e = _add_header_create_bad_object(headers, v2_client)
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 403) assert status == 403
eq(error_code, 'AccessDenied') assert error_code == 'AccessDenied'
@tag('auth_aws2') @tag('auth_aws2')
@attr(resource='object') @attr(resource='object')
@ -618,8 +617,8 @@ def test_object_create_bad_date_empty_aws2():
headers = {'x-amz-date': ''} headers = {'x-amz-date': ''}
e = _add_header_create_bad_object(headers, v2_client) e = _add_header_create_bad_object(headers, v2_client)
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 403) assert status == 403
eq(error_code, 'AccessDenied') assert error_code == 'AccessDenied'
@tag('auth_aws2') @tag('auth_aws2')
@attr(resource='object') @attr(resource='object')
@ -634,8 +633,8 @@ def test_object_create_bad_date_none_aws2():
remove = 'x-amz-date' remove = 'x-amz-date'
e = _remove_header_create_bad_object(remove, v2_client) e = _remove_header_create_bad_object(remove, v2_client)
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 403) assert status == 403
eq(error_code, 'AccessDenied') assert error_code == 'AccessDenied'
@tag('auth_aws2') @tag('auth_aws2')
@attr(resource='object') @attr(resource='object')
@ -647,8 +646,8 @@ def test_object_create_bad_date_before_today_aws2():
headers = {'x-amz-date': 'Tue, 07 Jul 2010 21:53:04 GMT'} headers = {'x-amz-date': 'Tue, 07 Jul 2010 21:53:04 GMT'}
e = _add_header_create_bad_object(headers, v2_client) e = _add_header_create_bad_object(headers, v2_client)
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 403) assert status == 403
eq(error_code, 'RequestTimeTooSkewed') assert error_code == 'RequestTimeTooSkewed'
@tag('auth_aws2') @tag('auth_aws2')
@attr(resource='object') @attr(resource='object')
@ -660,8 +659,8 @@ def test_object_create_bad_date_before_epoch_aws2():
headers = {'x-amz-date': 'Tue, 07 Jul 1950 21:53:04 GMT'} headers = {'x-amz-date': 'Tue, 07 Jul 1950 21:53:04 GMT'}
e = _add_header_create_bad_object(headers, v2_client) e = _add_header_create_bad_object(headers, v2_client)
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 403) assert status == 403
eq(error_code, 'AccessDenied') assert error_code == 'AccessDenied'
@tag('auth_aws2') @tag('auth_aws2')
@attr(resource='object') @attr(resource='object')
@ -673,8 +672,8 @@ def test_object_create_bad_date_after_end_aws2():
headers = {'x-amz-date': 'Tue, 07 Jul 9999 21:53:04 GMT'} headers = {'x-amz-date': 'Tue, 07 Jul 9999 21:53:04 GMT'}
e = _add_header_create_bad_object(headers, v2_client) e = _add_header_create_bad_object(headers, v2_client)
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 403) assert status == 403
eq(error_code, 'RequestTimeTooSkewed') assert error_code == 'RequestTimeTooSkewed'
@tag('auth_aws2') @tag('auth_aws2')
@attr(resource='bucket') @attr(resource='bucket')
@ -689,8 +688,8 @@ def test_bucket_create_bad_authorization_invalid_aws2():
headers = {'Authorization': 'AWS HAHAHA'} headers = {'Authorization': 'AWS HAHAHA'}
e = _add_header_create_bad_bucket(headers, v2_client) e = _add_header_create_bad_bucket(headers, v2_client)
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 400) assert status == 400
eq(error_code, 'InvalidArgument') assert error_code == 'InvalidArgument'
@tag('auth_aws2') @tag('auth_aws2')
@attr(resource='bucket') @attr(resource='bucket')
@ -722,8 +721,8 @@ def test_bucket_create_bad_date_invalid_aws2():
headers = {'x-amz-date': 'Bad Date'} headers = {'x-amz-date': 'Bad Date'}
e = _add_header_create_bad_bucket(headers, v2_client) e = _add_header_create_bad_bucket(headers, v2_client)
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 403) assert status == 403
eq(error_code, 'AccessDenied') assert error_code == 'AccessDenied'
@tag('auth_aws2') @tag('auth_aws2')
@attr(resource='bucket') @attr(resource='bucket')
@ -735,8 +734,8 @@ def test_bucket_create_bad_date_empty_aws2():
headers = {'x-amz-date': ''} headers = {'x-amz-date': ''}
e = _add_header_create_bad_bucket(headers, v2_client) e = _add_header_create_bad_bucket(headers, v2_client)
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 403) assert status == 403
eq(error_code, 'AccessDenied') assert error_code == 'AccessDenied'
@tag('auth_aws2') @tag('auth_aws2')
@attr(resource='bucket') @attr(resource='bucket')
@ -751,8 +750,8 @@ def test_bucket_create_bad_date_none_aws2():
remove = 'x-amz-date' remove = 'x-amz-date'
e = _remove_header_create_bad_bucket(remove, v2_client) e = _remove_header_create_bad_bucket(remove, v2_client)
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 403) assert status == 403
eq(error_code, 'AccessDenied') assert error_code == 'AccessDenied'
@tag('auth_aws2') @tag('auth_aws2')
@attr(resource='bucket') @attr(resource='bucket')
@ -764,8 +763,8 @@ def test_bucket_create_bad_date_before_today_aws2():
headers = {'x-amz-date': 'Tue, 07 Jul 2010 21:53:04 GMT'} headers = {'x-amz-date': 'Tue, 07 Jul 2010 21:53:04 GMT'}
e = _add_header_create_bad_bucket(headers, v2_client) e = _add_header_create_bad_bucket(headers, v2_client)
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 403) assert status == 403
eq(error_code, 'RequestTimeTooSkewed') assert error_code == 'RequestTimeTooSkewed'
@tag('auth_aws2') @tag('auth_aws2')
@attr(resource='bucket') @attr(resource='bucket')
@ -777,8 +776,8 @@ def test_bucket_create_bad_date_after_today_aws2():
headers = {'x-amz-date': 'Tue, 07 Jul 2030 21:53:04 GMT'} headers = {'x-amz-date': 'Tue, 07 Jul 2030 21:53:04 GMT'}
e = _add_header_create_bad_bucket(headers, v2_client) e = _add_header_create_bad_bucket(headers, v2_client)
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 403) assert status == 403
eq(error_code, 'RequestTimeTooSkewed') assert error_code == 'RequestTimeTooSkewed'
@tag('auth_aws2') @tag('auth_aws2')
@attr(resource='bucket') @attr(resource='bucket')
@ -790,5 +789,5 @@ def test_bucket_create_bad_date_before_epoch_aws2():
headers = {'x-amz-date': 'Tue, 07 Jul 1950 21:53:04 GMT'} headers = {'x-amz-date': 'Tue, 07 Jul 1950 21:53:04 GMT'}
e = _add_header_create_bad_bucket(headers, v2_client) e = _add_header_create_bad_bucket(headers, v2_client)
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 403) assert status == 403
eq(error_code, 'AccessDenied') assert error_code == 'AccessDenied'

View file

@ -2,7 +2,6 @@ import json
from botocore.exceptions import ClientError from botocore.exceptions import ClientError
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
from nose.tools import eq_ as eq
import pytest import pytest
from s3tests_boto3.functional.utils import assert_raises from s3tests_boto3.functional.utils import assert_raises
@ -40,10 +39,10 @@ def test_put_user_policy():
) )
response = client.put_user_policy(PolicyDocument=policy_document, PolicyName='AllAccessPolicy', response = client.put_user_policy(PolicyDocument=policy_document, PolicyName='AllAccessPolicy',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
response = client.delete_user_policy(PolicyName='AllAccessPolicy', response = client.delete_user_policy(PolicyName='AllAccessPolicy',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
@attr(resource='user-policy') @attr(resource='user-policy')
@ -67,7 +66,7 @@ def test_put_user_policy_invalid_user():
e = assert_raises(ClientError, client.put_user_policy, PolicyDocument=policy_document, e = assert_raises(ClientError, client.put_user_policy, PolicyDocument=policy_document,
PolicyName='AllAccessPolicy', UserName="some-non-existing-user-id") PolicyName='AllAccessPolicy', UserName="some-non-existing-user-id")
status = _get_status(e.response) status = _get_status(e.response)
eq(status, 404) assert status == 404
@attr(resource='user-policy') @attr(resource='user-policy')
@ -92,7 +91,7 @@ def test_put_user_policy_parameter_limit():
e = assert_raises(ClientError, client.put_user_policy, PolicyDocument=policy_document, e = assert_raises(ClientError, client.put_user_policy, PolicyDocument=policy_document,
PolicyName='AllAccessPolicy' * 10, UserName=get_alt_user_id()) PolicyName='AllAccessPolicy' * 10, UserName=get_alt_user_id())
status = _get_status(e.response) status = _get_status(e.response)
eq(status, 400) assert status == 400
@attr(resource='user-policy') @attr(resource='user-policy')
@ -120,7 +119,7 @@ def test_put_user_policy_invalid_element():
e = assert_raises(ClientError, client.put_user_policy, PolicyDocument=policy_document, e = assert_raises(ClientError, client.put_user_policy, PolicyDocument=policy_document,
PolicyName='AllAccessPolicy', UserName=get_alt_user_id()) PolicyName='AllAccessPolicy', UserName=get_alt_user_id())
status = _get_status(e.response) status = _get_status(e.response)
eq(status, 400) assert status == 400
# With no Statement # With no Statement
policy_document = json.dumps( policy_document = json.dumps(
@ -131,7 +130,7 @@ def test_put_user_policy_invalid_element():
e = assert_raises(ClientError, client.put_user_policy, PolicyDocument=policy_document, e = assert_raises(ClientError, client.put_user_policy, PolicyDocument=policy_document,
PolicyName='AllAccessPolicy', UserName=get_alt_user_id()) PolicyName='AllAccessPolicy', UserName=get_alt_user_id())
status = _get_status(e.response) status = _get_status(e.response)
eq(status, 400) assert status == 400
# with same Sid for 2 statements # with same Sid for 2 statements
policy_document = json.dumps( policy_document = json.dumps(
@ -150,7 +149,7 @@ def test_put_user_policy_invalid_element():
e = assert_raises(ClientError, client.put_user_policy, PolicyDocument=policy_document, e = assert_raises(ClientError, client.put_user_policy, PolicyDocument=policy_document,
PolicyName='AllAccessPolicy', UserName=get_alt_user_id()) PolicyName='AllAccessPolicy', UserName=get_alt_user_id())
status = _get_status(e.response) status = _get_status(e.response)
eq(status, 400) assert status == 400
# with Principal # with Principal
policy_document = json.dumps( policy_document = json.dumps(
@ -165,7 +164,7 @@ def test_put_user_policy_invalid_element():
e = assert_raises(ClientError, client.put_user_policy, PolicyDocument=policy_document, e = assert_raises(ClientError, client.put_user_policy, PolicyDocument=policy_document,
PolicyName='AllAccessPolicy', UserName=get_alt_user_id()) PolicyName='AllAccessPolicy', UserName=get_alt_user_id())
status = _get_status(e.response) status = _get_status(e.response)
eq(status, 400) assert status == 400
@attr(resource='user-policy') @attr(resource='user-policy')
@ -189,7 +188,7 @@ def test_put_existing_user_policy():
) )
response = client.put_user_policy(PolicyDocument=policy_document, PolicyName='AllAccessPolicy', response = client.put_user_policy(PolicyDocument=policy_document, PolicyName='AllAccessPolicy',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
client.put_user_policy(PolicyDocument=policy_document, PolicyName='AllAccessPolicy', client.put_user_policy(PolicyDocument=policy_document, PolicyName='AllAccessPolicy',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
client.delete_user_policy(PolicyName='AllAccessPolicy', UserName=get_alt_user_id()) client.delete_user_policy(PolicyName='AllAccessPolicy', UserName=get_alt_user_id())
@ -216,9 +215,9 @@ def test_list_user_policy():
) )
response = client.put_user_policy(PolicyDocument=policy_document, PolicyName='AllAccessPolicy', response = client.put_user_policy(PolicyDocument=policy_document, PolicyName='AllAccessPolicy',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
response = client.list_user_policies(UserName=get_alt_user_id()) response = client.list_user_policies(UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
client.delete_user_policy(PolicyName='AllAccessPolicy', UserName=get_alt_user_id()) client.delete_user_policy(PolicyName='AllAccessPolicy', UserName=get_alt_user_id())
@ -234,7 +233,7 @@ def test_list_user_policy_invalid_user():
client = get_iam_client() client = get_iam_client()
e = assert_raises(ClientError, client.list_user_policies, UserName="some-non-existing-user-id") e = assert_raises(ClientError, client.list_user_policies, UserName="some-non-existing-user-id")
status = _get_status(e.response) status = _get_status(e.response)
eq(status, 404) assert status == 404
@attr(resource='user-policy') @attr(resource='user-policy')
@ -257,13 +256,13 @@ def test_get_user_policy():
) )
response = client.put_user_policy(PolicyDocument=policy_document, PolicyName='AllAccessPolicy', response = client.put_user_policy(PolicyDocument=policy_document, PolicyName='AllAccessPolicy',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
response = client.get_user_policy(PolicyName='AllAccessPolicy', UserName=get_alt_user_id()) response = client.get_user_policy(PolicyName='AllAccessPolicy', UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
response = client.delete_user_policy(PolicyName='AllAccessPolicy', response = client.delete_user_policy(PolicyName='AllAccessPolicy',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
@attr(resource='user-policy') @attr(resource='user-policy')
@ -286,11 +285,11 @@ def test_get_user_policy_invalid_user():
) )
response = client.put_user_policy(PolicyDocument=policy_document, PolicyName='AllAccessPolicy', response = client.put_user_policy(PolicyDocument=policy_document, PolicyName='AllAccessPolicy',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
e = assert_raises(ClientError, client.get_user_policy, PolicyName='AllAccessPolicy', e = assert_raises(ClientError, client.get_user_policy, PolicyName='AllAccessPolicy',
UserName="some-non-existing-user-id") UserName="some-non-existing-user-id")
status = _get_status(e.response) status = _get_status(e.response)
eq(status, 404) assert status == 404
client.delete_user_policy(PolicyName='AllAccessPolicy', UserName=get_alt_user_id()) client.delete_user_policy(PolicyName='AllAccessPolicy', UserName=get_alt_user_id())
@ -319,7 +318,7 @@ def test_get_user_policy_invalid_policy_name():
e = assert_raises(ClientError, client.get_user_policy, PolicyName='non-existing-policy-name', e = assert_raises(ClientError, client.get_user_policy, PolicyName='non-existing-policy-name',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
status = _get_status(e.response) status = _get_status(e.response)
eq(status, 404) assert status == 404
client.delete_user_policy(PolicyName='AllAccessPolicy', UserName=get_alt_user_id()) client.delete_user_policy(PolicyName='AllAccessPolicy', UserName=get_alt_user_id())
@ -349,7 +348,7 @@ def test_get_deleted_user_policy():
e = assert_raises(ClientError, client.get_user_policy, PolicyName='AllAccessPolicy', e = assert_raises(ClientError, client.get_user_policy, PolicyName='AllAccessPolicy',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
status = _get_status(e.response) status = _get_status(e.response)
eq(status, 404) assert status == 404
@attr(resource='user-policy') @attr(resource='user-policy')
@ -374,21 +373,21 @@ def test_get_user_policy_from_multiple_policies():
response = client.put_user_policy(PolicyDocument=policy_document_allow, response = client.put_user_policy(PolicyDocument=policy_document_allow,
PolicyName='AllowAccessPolicy1', PolicyName='AllowAccessPolicy1',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
response = client.put_user_policy(PolicyDocument=policy_document_allow, response = client.put_user_policy(PolicyDocument=policy_document_allow,
PolicyName='AllowAccessPolicy2', PolicyName='AllowAccessPolicy2',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
response = client.get_user_policy(PolicyName='AllowAccessPolicy2', response = client.get_user_policy(PolicyName='AllowAccessPolicy2',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
response = client.delete_user_policy(PolicyName='AllowAccessPolicy1', response = client.delete_user_policy(PolicyName='AllowAccessPolicy1',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
response = client.delete_user_policy(PolicyName='AllowAccessPolicy2', response = client.delete_user_policy(PolicyName='AllowAccessPolicy2',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
@attr(resource='user-policy') @attr(resource='user-policy')
@ -413,10 +412,10 @@ def test_delete_user_policy():
response = client.put_user_policy(PolicyDocument=policy_document_allow, response = client.put_user_policy(PolicyDocument=policy_document_allow,
PolicyName='AllowAccessPolicy', PolicyName='AllowAccessPolicy',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
response = client.delete_user_policy(PolicyName='AllowAccessPolicy', response = client.delete_user_policy(PolicyName='AllowAccessPolicy',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
@attr(resource='user-policy') @attr(resource='user-policy')
@ -441,14 +440,14 @@ def test_delete_user_policy_invalid_user():
response = client.put_user_policy(PolicyDocument=policy_document_allow, response = client.put_user_policy(PolicyDocument=policy_document_allow,
PolicyName='AllowAccessPolicy', PolicyName='AllowAccessPolicy',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
e = assert_raises(ClientError, client.delete_user_policy, PolicyName='AllAccessPolicy', e = assert_raises(ClientError, client.delete_user_policy, PolicyName='AllAccessPolicy',
UserName="some-non-existing-user-id") UserName="some-non-existing-user-id")
status = _get_status(e.response) status = _get_status(e.response)
eq(status, 404) assert status == 404
response = client.delete_user_policy(PolicyName='AllowAccessPolicy', response = client.delete_user_policy(PolicyName='AllowAccessPolicy',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
@attr(resource='user-policy') @attr(resource='user-policy')
@ -473,14 +472,14 @@ def test_delete_user_policy_invalid_policy_name():
response = client.put_user_policy(PolicyDocument=policy_document_allow, response = client.put_user_policy(PolicyDocument=policy_document_allow,
PolicyName='AllowAccessPolicy', PolicyName='AllowAccessPolicy',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
e = assert_raises(ClientError, client.delete_user_policy, PolicyName='non-existing-policy-name', e = assert_raises(ClientError, client.delete_user_policy, PolicyName='non-existing-policy-name',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
status = _get_status(e.response) status = _get_status(e.response)
eq(status, 404) assert status == 404
response = client.delete_user_policy(PolicyName='AllowAccessPolicy', response = client.delete_user_policy(PolicyName='AllowAccessPolicy',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
@attr(resource='user-policy') @attr(resource='user-policy')
@ -505,28 +504,28 @@ def test_delete_user_policy_from_multiple_policies():
response = client.put_user_policy(PolicyDocument=policy_document_allow, response = client.put_user_policy(PolicyDocument=policy_document_allow,
PolicyName='AllowAccessPolicy1', PolicyName='AllowAccessPolicy1',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
response = client.put_user_policy(PolicyDocument=policy_document_allow, response = client.put_user_policy(PolicyDocument=policy_document_allow,
PolicyName='AllowAccessPolicy2', PolicyName='AllowAccessPolicy2',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
response = client.put_user_policy(PolicyDocument=policy_document_allow, response = client.put_user_policy(PolicyDocument=policy_document_allow,
PolicyName='AllowAccessPolicy3', PolicyName='AllowAccessPolicy3',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
response = client.delete_user_policy(PolicyName='AllowAccessPolicy1', response = client.delete_user_policy(PolicyName='AllowAccessPolicy1',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
response = client.delete_user_policy(PolicyName='AllowAccessPolicy2', response = client.delete_user_policy(PolicyName='AllowAccessPolicy2',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
response = client.get_user_policy(PolicyName='AllowAccessPolicy3', response = client.get_user_policy(PolicyName='AllowAccessPolicy3',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
response = client.delete_user_policy(PolicyName='AllowAccessPolicy3', response = client.delete_user_policy(PolicyName='AllowAccessPolicy3',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
@attr(resource='user-policy') @attr(resource='user-policy')
@ -555,7 +554,7 @@ def test_allow_bucket_actions_in_user_policy():
response = client.put_user_policy(PolicyDocument=policy_document_allow, response = client.put_user_policy(PolicyDocument=policy_document_allow,
PolicyName='AllowAccessPolicy', UserName=get_alt_user_id()) PolicyName='AllowAccessPolicy', UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
response = s3_client_alt.list_objects(Bucket=bucket) response = s3_client_alt.list_objects(Bucket=bucket)
object_found = False object_found = False
@ -567,10 +566,10 @@ def test_allow_bucket_actions_in_user_policy():
raise AssertionError("Object is not listed") raise AssertionError("Object is not listed")
response = s3_client_iam.delete_object(Bucket=bucket, Key='foo') response = s3_client_iam.delete_object(Bucket=bucket, Key='foo')
eq(response['ResponseMetadata']['HTTPStatusCode'], 204) assert response['ResponseMetadata']['HTTPStatusCode'] == 204
response = s3_client_alt.delete_bucket(Bucket=bucket) response = s3_client_alt.delete_bucket(Bucket=bucket)
eq(response['ResponseMetadata']['HTTPStatusCode'], 204) assert response['ResponseMetadata']['HTTPStatusCode'] == 204
response = s3_client_iam.list_buckets() response = s3_client_iam.list_buckets()
for bucket in response['Buckets']: for bucket in response['Buckets']:
@ -579,7 +578,7 @@ def test_allow_bucket_actions_in_user_policy():
response = client.delete_user_policy(PolicyName='AllowAccessPolicy', response = client.delete_user_policy(PolicyName='AllowAccessPolicy',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
@attr(resource='user-policy') @attr(resource='user-policy')
@ -607,21 +606,21 @@ def test_deny_bucket_actions_in_user_policy():
response = client.put_user_policy(PolicyDocument=policy_document_deny, response = client.put_user_policy(PolicyDocument=policy_document_deny,
PolicyName='DenyAccessPolicy', PolicyName='DenyAccessPolicy',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
e = assert_raises(ClientError, s3_client.list_buckets, Bucket=bucket) e = assert_raises(ClientError, s3_client.list_buckets, Bucket=bucket)
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 403) assert status == 403
eq(error_code, 'AccessDenied') assert error_code == 'AccessDenied'
e = assert_raises(ClientError, s3_client.delete_bucket, Bucket=bucket) e = assert_raises(ClientError, s3_client.delete_bucket, Bucket=bucket)
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 403) assert status == 403
eq(error_code, 'AccessDenied') assert error_code == 'AccessDenied'
response = client.delete_user_policy(PolicyName='DenyAccessPolicy', response = client.delete_user_policy(PolicyName='DenyAccessPolicy',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
response = s3_client.delete_bucket(Bucket=bucket) response = s3_client.delete_bucket(Bucket=bucket)
eq(response['ResponseMetadata']['HTTPStatusCode'], 204) assert response['ResponseMetadata']['HTTPStatusCode'] == 204
@attr(resource='user-policy') @attr(resource='user-policy')
@ -647,26 +646,26 @@ def test_allow_object_actions_in_user_policy():
) )
response = client.put_user_policy(PolicyDocument=policy_document_allow, response = client.put_user_policy(PolicyDocument=policy_document_allow,
PolicyName='AllowAccessPolicy', UserName=get_alt_user_id()) PolicyName='AllowAccessPolicy', UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
s3_client_alt.put_object(Bucket=bucket, Key='foo', Body='bar') s3_client_alt.put_object(Bucket=bucket, Key='foo', Body='bar')
response = s3_client_alt.get_object(Bucket=bucket, Key='foo') response = s3_client_alt.get_object(Bucket=bucket, Key='foo')
body = response['Body'].read() body = response['Body'].read()
if type(body) is bytes: if type(body) is bytes:
body = body.decode() body = body.decode()
eq(body, "bar") assert body == "bar"
response = s3_client_alt.delete_object(Bucket=bucket, Key='foo') response = s3_client_alt.delete_object(Bucket=bucket, Key='foo')
eq(response['ResponseMetadata']['HTTPStatusCode'], 204) assert response['ResponseMetadata']['HTTPStatusCode'] == 204
e = assert_raises(ClientError, s3_client_iam.get_object, Bucket=bucket, Key='foo') e = assert_raises(ClientError, s3_client_iam.get_object, Bucket=bucket, Key='foo')
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 404) assert status == 404
eq(error_code, 'NoSuchKey') assert error_code == 'NoSuchKey'
response = s3_client_iam.delete_bucket(Bucket=bucket) response = s3_client_iam.delete_bucket(Bucket=bucket)
eq(response['ResponseMetadata']['HTTPStatusCode'], 204) assert response['ResponseMetadata']['HTTPStatusCode'] == 204
response = client.delete_user_policy(PolicyName='AllowAccessPolicy', response = client.delete_user_policy(PolicyName='AllowAccessPolicy',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
@attr(resource='user-policy') @attr(resource='user-policy')
@ -699,20 +698,20 @@ def test_deny_object_actions_in_user_policy():
e = assert_raises(ClientError, s3_client_alt.put_object, Bucket=bucket, Key='foo') e = assert_raises(ClientError, s3_client_alt.put_object, Bucket=bucket, Key='foo')
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 403) assert status == 403
eq(error_code, 'AccessDenied') assert error_code == 'AccessDenied'
e = assert_raises(ClientError, s3_client_alt.get_object, Bucket=bucket, Key='foo') e = assert_raises(ClientError, s3_client_alt.get_object, Bucket=bucket, Key='foo')
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 403) assert status == 403
eq(error_code, 'AccessDenied') assert error_code == 'AccessDenied'
e = assert_raises(ClientError, s3_client_alt.delete_object, Bucket=bucket, Key='foo') e = assert_raises(ClientError, s3_client_alt.delete_object, Bucket=bucket, Key='foo')
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 403) assert status == 403
eq(error_code, 'AccessDenied') assert error_code == 'AccessDenied'
response = client.delete_user_policy(PolicyName='DenyAccessPolicy', response = client.delete_user_policy(PolicyName='DenyAccessPolicy',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
@attr(resource='user-policy') @attr(resource='user-policy')
@ -738,22 +737,22 @@ def test_allow_multipart_actions_in_user_policy():
) )
response = client.put_user_policy(PolicyDocument=policy_document_allow, response = client.put_user_policy(PolicyDocument=policy_document_allow,
PolicyName='AllowAccessPolicy', UserName=get_alt_user_id()) PolicyName='AllowAccessPolicy', UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
key = "mymultipart" key = "mymultipart"
mb = 1024 * 1024 mb = 1024 * 1024
(upload_id, _, _) = _multipart_upload(client=s3_client_iam, bucket_name=bucket, key=key, (upload_id, _, _) = _multipart_upload(client=s3_client_iam, bucket_name=bucket, key=key,
size=5 * mb) size=5 * mb)
response = s3_client_alt.list_multipart_uploads(Bucket=bucket) response = s3_client_alt.list_multipart_uploads(Bucket=bucket)
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
response = s3_client_alt.abort_multipart_upload(Bucket=bucket, Key=key, UploadId=upload_id) response = s3_client_alt.abort_multipart_upload(Bucket=bucket, Key=key, UploadId=upload_id)
eq(response['ResponseMetadata']['HTTPStatusCode'], 204) assert response['ResponseMetadata']['HTTPStatusCode'] == 204
response = s3_client_iam.delete_bucket(Bucket=bucket) response = s3_client_iam.delete_bucket(Bucket=bucket)
eq(response['ResponseMetadata']['HTTPStatusCode'], 204) assert response['ResponseMetadata']['HTTPStatusCode'] == 204
response = client.delete_user_policy(PolicyName='AllowAccessPolicy', response = client.delete_user_policy(PolicyName='AllowAccessPolicy',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
@attr(resource='user-policy') @attr(resource='user-policy')
@ -780,7 +779,7 @@ def test_deny_multipart_actions_in_user_policy():
response = client.put_user_policy(PolicyDocument=policy_document_deny, response = client.put_user_policy(PolicyDocument=policy_document_deny,
PolicyName='DenyAccessPolicy', PolicyName='DenyAccessPolicy',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
key = "mymultipart" key = "mymultipart"
mb = 1024 * 1024 mb = 1024 * 1024
@ -789,20 +788,20 @@ def test_deny_multipart_actions_in_user_policy():
e = assert_raises(ClientError, s3_client.list_multipart_uploads, Bucket=bucket) e = assert_raises(ClientError, s3_client.list_multipart_uploads, Bucket=bucket)
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 403) assert status == 403
eq(error_code, 'AccessDenied') assert error_code == 'AccessDenied'
e = assert_raises(ClientError, s3_client.abort_multipart_upload, Bucket=bucket, e = assert_raises(ClientError, s3_client.abort_multipart_upload, Bucket=bucket,
Key=key, UploadId=upload_id) Key=key, UploadId=upload_id)
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 403) assert status == 403
eq(error_code, 'AccessDenied') assert error_code == 'AccessDenied'
response = s3_client.delete_bucket(Bucket=bucket) response = s3_client.delete_bucket(Bucket=bucket)
eq(response['ResponseMetadata']['HTTPStatusCode'], 204) assert response['ResponseMetadata']['HTTPStatusCode'] == 204
response = client.delete_user_policy(PolicyName='DenyAccessPolicy', response = client.delete_user_policy(PolicyName='DenyAccessPolicy',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
@attr(resource='user-policy') @attr(resource='user-policy')
@ -833,28 +832,28 @@ def test_allow_tagging_actions_in_user_policy():
tags = {'TagSet': [{'Key': 'Hello', 'Value': 'World'}, ]} tags = {'TagSet': [{'Key': 'Hello', 'Value': 'World'}, ]}
response = s3_client_alt.put_bucket_tagging(Bucket=bucket, Tagging=tags) response = s3_client_alt.put_bucket_tagging(Bucket=bucket, Tagging=tags)
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
response = s3_client_alt.get_bucket_tagging(Bucket=bucket) response = s3_client_alt.get_bucket_tagging(Bucket=bucket)
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
eq(response['TagSet'][0]['Key'], 'Hello') assert response['TagSet'][0]['Key'] == 'Hello'
eq(response['TagSet'][0]['Value'], 'World') assert response['TagSet'][0]['Value'] == 'World'
obj_key = 'obj' obj_key = 'obj'
response = s3_client_iam.put_object(Bucket=bucket, Key=obj_key, Body='obj_body') response = s3_client_iam.put_object(Bucket=bucket, Key=obj_key, Body='obj_body')
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
response = s3_client_alt.put_object_tagging(Bucket=bucket, Key=obj_key, Tagging=tags) response = s3_client_alt.put_object_tagging(Bucket=bucket, Key=obj_key, Tagging=tags)
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
response = s3_client_alt.get_object_tagging(Bucket=bucket, Key=obj_key) response = s3_client_alt.get_object_tagging(Bucket=bucket, Key=obj_key)
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
eq(response['TagSet'], tags['TagSet']) assert response['TagSet'] == tags['TagSet']
response = s3_client_iam.delete_object(Bucket=bucket, Key=obj_key) response = s3_client_iam.delete_object(Bucket=bucket, Key=obj_key)
eq(response['ResponseMetadata']['HTTPStatusCode'], 204) assert response['ResponseMetadata']['HTTPStatusCode'] == 204
response = s3_client_iam.delete_bucket(Bucket=bucket) response = s3_client_iam.delete_bucket(Bucket=bucket)
eq(response['ResponseMetadata']['HTTPStatusCode'], 204) assert response['ResponseMetadata']['HTTPStatusCode'] == 204
response = client.delete_user_policy(PolicyName='AllowAccessPolicy', response = client.delete_user_policy(PolicyName='AllowAccessPolicy',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
@attr(resource='user-policy') @attr(resource='user-policy')
@ -885,34 +884,34 @@ def test_deny_tagging_actions_in_user_policy():
e = assert_raises(ClientError, s3_client.put_bucket_tagging, Bucket=bucket, Tagging=tags) e = assert_raises(ClientError, s3_client.put_bucket_tagging, Bucket=bucket, Tagging=tags)
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 403) assert status == 403
eq(error_code, 'AccessDenied') assert error_code == 'AccessDenied'
e = assert_raises(ClientError, s3_client.get_bucket_tagging, Bucket=bucket) e = assert_raises(ClientError, s3_client.get_bucket_tagging, Bucket=bucket)
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 403) assert status == 403
eq(error_code, 'AccessDenied') assert error_code == 'AccessDenied'
obj_key = 'obj' obj_key = 'obj'
response = s3_client.put_object(Bucket=bucket, Key=obj_key, Body='obj_body') response = s3_client.put_object(Bucket=bucket, Key=obj_key, Body='obj_body')
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
e = assert_raises(ClientError, s3_client.put_object_tagging, Bucket=bucket, Key=obj_key, e = assert_raises(ClientError, s3_client.put_object_tagging, Bucket=bucket, Key=obj_key,
Tagging=tags) Tagging=tags)
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 403) assert status == 403
eq(error_code, 'AccessDenied') assert error_code == 'AccessDenied'
e = assert_raises(ClientError, s3_client.delete_object_tagging, Bucket=bucket, Key=obj_key) e = assert_raises(ClientError, s3_client.delete_object_tagging, Bucket=bucket, Key=obj_key)
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 403) assert status == 403
eq(error_code, 'AccessDenied') assert error_code == 'AccessDenied'
response = s3_client.delete_object(Bucket=bucket, Key=obj_key) response = s3_client.delete_object(Bucket=bucket, Key=obj_key)
eq(response['ResponseMetadata']['HTTPStatusCode'], 204) assert response['ResponseMetadata']['HTTPStatusCode'] == 204
response = s3_client.delete_bucket(Bucket=bucket) response = s3_client.delete_bucket(Bucket=bucket)
eq(response['ResponseMetadata']['HTTPStatusCode'], 204) assert response['ResponseMetadata']['HTTPStatusCode'] == 204
response = client.delete_user_policy(PolicyName='DenyAccessPolicy', response = client.delete_user_policy(PolicyName='DenyAccessPolicy',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
@attr(resource='user-policy') @attr(resource='user-policy')
@ -943,14 +942,14 @@ def test_verify_conflicting_user_policy_statements():
client = get_iam_client() client = get_iam_client()
response = client.put_user_policy(PolicyDocument=policy_document, PolicyName='DenyAccessPolicy', response = client.put_user_policy(PolicyDocument=policy_document, PolicyName='DenyAccessPolicy',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
e = assert_raises(ClientError, s3client.list_objects, Bucket=bucket) e = assert_raises(ClientError, s3client.list_objects, Bucket=bucket)
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 403) assert status == 403
eq(error_code, 'AccessDenied') assert error_code == 'AccessDenied'
response = client.delete_user_policy(PolicyName='DenyAccessPolicy', response = client.delete_user_policy(PolicyName='DenyAccessPolicy',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
@attr(resource='user-policy') @attr(resource='user-policy')
@ -982,20 +981,20 @@ def test_verify_conflicting_user_policies():
client = get_iam_client() client = get_iam_client()
response = client.put_user_policy(PolicyDocument=policy_allow, PolicyName='AllowAccessPolicy', response = client.put_user_policy(PolicyDocument=policy_allow, PolicyName='AllowAccessPolicy',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
response = client.put_user_policy(PolicyDocument=policy_deny, PolicyName='DenyAccessPolicy', response = client.put_user_policy(PolicyDocument=policy_deny, PolicyName='DenyAccessPolicy',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
e = assert_raises(ClientError, s3client.list_objects, Bucket=bucket) e = assert_raises(ClientError, s3client.list_objects, Bucket=bucket)
status, error_code = _get_status_and_error_code(e.response) status, error_code = _get_status_and_error_code(e.response)
eq(status, 403) assert status == 403
eq(error_code, 'AccessDenied') assert error_code == 'AccessDenied'
response = client.delete_user_policy(PolicyName='AllowAccessPolicy', response = client.delete_user_policy(PolicyName='AllowAccessPolicy',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
response = client.delete_user_policy(PolicyName='DenyAccessPolicy', response = client.delete_user_policy(PolicyName='DenyAccessPolicy',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
@attr(resource='user-policy') @attr(resource='user-policy')
@ -1019,12 +1018,12 @@ def test_verify_allow_iam_actions():
response = client1.put_user_policy(PolicyDocument=policy1, PolicyName='AllowAccessPolicy', response = client1.put_user_policy(PolicyDocument=policy1, PolicyName='AllowAccessPolicy',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
response = iam_client_alt.get_user_policy(PolicyName='AllowAccessPolicy', response = iam_client_alt.get_user_policy(PolicyName='AllowAccessPolicy',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
response = iam_client_alt.list_user_policies(UserName=get_alt_user_id()) response = iam_client_alt.list_user_policies(UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200
response = iam_client_alt.delete_user_policy(PolicyName='AllowAccessPolicy', response = iam_client_alt.delete_user_policy(PolicyName='AllowAccessPolicy',
UserName=get_alt_user_id()) UserName=get_alt_user_id())
eq(response['ResponseMetadata']['HTTPStatusCode'], 200) assert response['ResponseMetadata']['HTTPStatusCode'] == 200

File diff suppressed because it is too large Load diff

View file

@ -7,7 +7,6 @@ from nose.plugins.attrib import attr
from botocore.exceptions import ClientError from botocore.exceptions import ClientError
import uuid import uuid
from nose.tools import eq_ as eq
from . import ( from . import (
configfile, configfile,
@ -120,8 +119,7 @@ def s3select_assert_result(a,b):
else: else:
assert a != "" assert a != ""
assert b != "" assert b != ""
assert a == b
nose.tools.assert_equal(a,b)
def create_csv_object_for_datetime(rows,columns): def create_csv_object_for_datetime(rows,columns):
result = "" result = ""
@ -225,7 +223,7 @@ def upload_csv_object(bucket_name,new_key,obj):
# validate uploaded object # validate uploaded object
c2 = get_client() c2 = get_client()
response = c2.get_object(Bucket=bucket_name, Key=new_key) response = c2.get_object(Bucket=bucket_name, Key=new_key)
eq(response['Body'].read().decode('utf-8'), obj, 's3select error[ downloaded object not equal to uploaded objecy') assert response['Body'].read().decode('utf-8') == obj, 's3select error[ downloaded object not equal to uploaded objecy'
def run_s3select(bucket,key,query,column_delim=",",row_delim="\n",quot_char='"',esc_char='\\',csv_header_info="NONE", progress = False): def run_s3select(bucket,key,query,column_delim=",",row_delim="\n",quot_char='"',esc_char='\\',csv_header_info="NONE", progress = False):
@ -297,7 +295,7 @@ def remove_xml_tags_from_result(obj):
x = bool(re.search("^failure.*$", result_strip)) x = bool(re.search("^failure.*$", result_strip))
if x: if x:
logging.info(result) logging.info(result)
nose.tools.assert_equal(x, False) assert x == False
return result return result
@ -782,19 +780,19 @@ def test_nullif_expressions():
res_s3select = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,"select count(0) from stdin where _1 = _2 ;") ).replace("\n","") res_s3select = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,"select count(0) from stdin where _1 = _2 ;") ).replace("\n","")
nose.tools.assert_equal( res_s3select_nullif, res_s3select) assert res_s3select_nullif == res_s3select
res_s3select_nullif = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,"select count(0) from stdin where not nullif(_1,_2) is null ;") ).replace("\n","") res_s3select_nullif = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,"select count(0) from stdin where not nullif(_1,_2) is null ;") ).replace("\n","")
res_s3select = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,"select count(0) from stdin where _1 != _2 ;") ).replace("\n","") res_s3select = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,"select count(0) from stdin where _1 != _2 ;") ).replace("\n","")
nose.tools.assert_equal( res_s3select_nullif, res_s3select) assert res_s3select_nullif == res_s3select
res_s3select_nullif = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,"select count(0) from stdin where nullif(_1,_2) = _1 ;") ).replace("\n","") res_s3select_nullif = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,"select count(0) from stdin where nullif(_1,_2) = _1 ;") ).replace("\n","")
res_s3select = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,"select count(0) from stdin where _1 != _2 ;") ).replace("\n","") res_s3select = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,"select count(0) from stdin where _1 != _2 ;") ).replace("\n","")
nose.tools.assert_equal( res_s3select_nullif, res_s3select) assert res_s3select_nullif == res_s3select
@attr('s3select') @attr('s3select')
@pytest.mark.s3select @pytest.mark.s3select
@ -808,11 +806,11 @@ def test_lowerupper_expressions():
res_s3select = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,'select lower("AB12cd$$") from stdin ;') ).replace("\n","") res_s3select = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,'select lower("AB12cd$$") from stdin ;') ).replace("\n","")
nose.tools.assert_equal( res_s3select, "ab12cd$$") assert res_s3select == "ab12cd$$"
res_s3select = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,'select upper("ab12CD$$") from stdin ;') ).replace("\n","") res_s3select = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,'select upper("ab12CD$$") from stdin ;') ).replace("\n","")
nose.tools.assert_equal( res_s3select, "AB12CD$$") assert res_s3select == "AB12CD$$"
@attr('s3select') @attr('s3select')
@pytest.mark.s3select @pytest.mark.s3select
@ -829,31 +827,31 @@ def test_in_expressions():
res_s3select = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,'select int(_1) from stdin where int(_1) = 1;')).replace("\n","") res_s3select = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,'select int(_1) from stdin where int(_1) = 1;')).replace("\n","")
nose.tools.assert_equal( res_s3select_in, res_s3select ) assert res_s3select_in == res_s3select
res_s3select_in = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,'select int(_1) from stdin where int(_1) in(1,0);')).replace("\n","") res_s3select_in = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,'select int(_1) from stdin where int(_1) in(1,0);')).replace("\n","")
res_s3select = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,'select int(_1) from stdin where int(_1) = 1 or int(_1) = 0;')).replace("\n","") res_s3select = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,'select int(_1) from stdin where int(_1) = 1 or int(_1) = 0;')).replace("\n","")
nose.tools.assert_equal( res_s3select_in, res_s3select ) assert res_s3select_in == res_s3select
res_s3select_in = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,'select int(_2) from stdin where int(_2) in(1,0,2);')).replace("\n","") res_s3select_in = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,'select int(_2) from stdin where int(_2) in(1,0,2);')).replace("\n","")
res_s3select = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,'select int(_2) from stdin where int(_2) = 1 or int(_2) = 0 or int(_2) = 2;')).replace("\n","") res_s3select = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,'select int(_2) from stdin where int(_2) = 1 or int(_2) = 0 or int(_2) = 2;')).replace("\n","")
nose.tools.assert_equal( res_s3select_in, res_s3select ) assert res_s3select_in == res_s3select
res_s3select_in = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,'select int(_2) from stdin where int(_2)*2 in(int(_3)*2,int(_4)*3,int(_5)*5);')).replace("\n","") res_s3select_in = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,'select int(_2) from stdin where int(_2)*2 in(int(_3)*2,int(_4)*3,int(_5)*5);')).replace("\n","")
res_s3select = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,'select int(_2) from stdin where int(_2)*2 = int(_3)*2 or int(_2)*2 = int(_4)*3 or int(_2)*2 = int(_5)*5;')).replace("\n","") res_s3select = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,'select int(_2) from stdin where int(_2)*2 = int(_3)*2 or int(_2)*2 = int(_4)*3 or int(_2)*2 = int(_5)*5;')).replace("\n","")
nose.tools.assert_equal( res_s3select_in, res_s3select ) assert res_s3select_in == res_s3select
res_s3select_in = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,'select int(_1) from stdin where character_length(_1) = 2 and substring(_1,2,1) in ("3");')).replace("\n","") res_s3select_in = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,'select int(_1) from stdin where character_length(_1) = 2 and substring(_1,2,1) in ("3");')).replace("\n","")
res_s3select = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,'select int(_1) from stdin where _1 like "_3";')).replace("\n","") res_s3select = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,'select int(_1) from stdin where _1 like "_3";')).replace("\n","")
nose.tools.assert_equal( res_s3select_in, res_s3select ) assert res_s3select_in == res_s3select
@attr('s3select') @attr('s3select')
@pytest.mark.s3select @pytest.mark.s3select
@ -869,37 +867,37 @@ def test_like_expressions():
res_s3select = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name, 'select count(*) from stdin where substring(_1,11,4) = "aeio" ;')).replace("\n","") res_s3select = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name, 'select count(*) from stdin where substring(_1,11,4) = "aeio" ;')).replace("\n","")
nose.tools.assert_equal( res_s3select_in, res_s3select ) assert res_s3select_in == res_s3select
res_s3select_in = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,'select count(*) from stdin where _1 like "cbcd%";')).replace("\n","") res_s3select_in = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,'select count(*) from stdin where _1 like "cbcd%";')).replace("\n","")
res_s3select = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name, 'select count(*) from stdin where substring(_1,1,4) = "cbcd";')).replace("\n","") res_s3select = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name, 'select count(*) from stdin where substring(_1,1,4) = "cbcd";')).replace("\n","")
nose.tools.assert_equal( res_s3select_in, res_s3select ) assert res_s3select_in == res_s3select
res_s3select_in = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,'select count(*) from stdin where _3 like "%y[y-z]";')).replace("\n","") res_s3select_in = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,'select count(*) from stdin where _3 like "%y[y-z]";')).replace("\n","")
res_s3select = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name, 'select count(*) from stdin where substring(_3,character_length(_3),1) between "y" and "z" and substring(_3,character_length(_3)-1,1) = "y";')).replace("\n","") res_s3select = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name, 'select count(*) from stdin where substring(_3,character_length(_3),1) between "y" and "z" and substring(_3,character_length(_3)-1,1) = "y";')).replace("\n","")
nose.tools.assert_equal( res_s3select_in, res_s3select ) assert res_s3select_in == res_s3select
res_s3select_in = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,'select count(*) from stdin where _2 like "%yz";')).replace("\n","") res_s3select_in = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,'select count(*) from stdin where _2 like "%yz";')).replace("\n","")
res_s3select = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name, 'select count(*) from stdin where substring(_2,character_length(_2),1) = "z" and substring(_2,character_length(_2)-1,1) = "y";')).replace("\n","") res_s3select = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name, 'select count(*) from stdin where substring(_2,character_length(_2),1) = "z" and substring(_2,character_length(_2)-1,1) = "y";')).replace("\n","")
nose.tools.assert_equal( res_s3select_in, res_s3select ) assert res_s3select_in == res_s3select
res_s3select_in = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,'select count(*) from stdin where _3 like "c%z";')).replace("\n","") res_s3select_in = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,'select count(*) from stdin where _3 like "c%z";')).replace("\n","")
res_s3select = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name, 'select count(*) from stdin where substring(_3,character_length(_3),1) = "z" and substring(_3,1,1) = "c";')).replace("\n","") res_s3select = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name, 'select count(*) from stdin where substring(_3,character_length(_3),1) = "z" and substring(_3,1,1) = "c";')).replace("\n","")
nose.tools.assert_equal( res_s3select_in, res_s3select ) assert res_s3select_in == res_s3select
res_s3select_in = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,'select count(*) from stdin where _2 like "%xy_";')).replace("\n","") res_s3select_in = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name,'select count(*) from stdin where _2 like "%xy_";')).replace("\n","")
res_s3select = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name, 'select count(*) from stdin where substring(_2,character_length(_2)-1,1) = "y" and substring(_2,character_length(_2)-2,1) = "x";')).replace("\n","") res_s3select = remove_xml_tags_from_result( run_s3select(bucket_name,csv_obj_name, 'select count(*) from stdin where substring(_2,character_length(_2)-1,1) = "y" and substring(_2,character_length(_2)-2,1) = "x";')).replace("\n","")
nose.tools.assert_equal( res_s3select_in, res_s3select ) assert res_s3select_in == res_s3select
@attr('s3select') @attr('s3select')

File diff suppressed because it is too large Load diff

View file

@ -1,11 +1,9 @@
from nose.tools import eq_ as eq
from . import utils from . import utils
def test_generate(): def test_generate():
FIVE_MB = 5 * 1024 * 1024 FIVE_MB = 5 * 1024 * 1024
eq(len(''.join(utils.generate_random(0))), 0) assert len(''.join(utils.generate_random(0))) == 0
eq(len(''.join(utils.generate_random(1))), 1) assert len(''.join(utils.generate_random(1))) == 1
eq(len(''.join(utils.generate_random(FIVE_MB - 1))), FIVE_MB - 1) assert len(''.join(utils.generate_random(FIVE_MB - 1))) == FIVE_MB - 1
eq(len(''.join(utils.generate_random(FIVE_MB))), FIVE_MB) assert len(''.join(utils.generate_random(FIVE_MB))) == FIVE_MB
eq(len(''.join(utils.generate_random(FIVE_MB + 1))), FIVE_MB + 1) assert len(''.join(utils.generate_random(FIVE_MB + 1))) == FIVE_MB + 1

View file

@ -3,8 +3,6 @@ import requests
import string import string
import time import time
from nose.tools import eq_ as eq
def assert_raises(excClass, callableObj, *args, **kwargs): def assert_raises(excClass, callableObj, *args, **kwargs):
""" """
Like unittest.TestCase.assertRaises, but returns the exception. Like unittest.TestCase.assertRaises, but returns the exception.