Port test suite from nose to pytest.
This just eliminates all errors on the tests collection. Elimination of failures is left to the next commit.
This commit is contained in:
parent
47dbad291e
commit
77dc60ea97
146 changed files with 1172 additions and 1277 deletions
|
|
@ -4,9 +4,7 @@ import boto3
|
|||
import sure # noqa
|
||||
from botocore.exceptions import ClientError
|
||||
|
||||
# Ensure 'assert_raises' context manager support for Python 2.6
|
||||
import tests.backport_assert_raises
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
from moto import mock_iam, mock_ec2, mock_s3, mock_sts, mock_elbv2, mock_rds2
|
||||
from moto.core import set_initial_no_auth_action_count
|
||||
|
|
@ -179,7 +177,7 @@ def test_invalid_client_token_id():
|
|||
aws_access_key_id="invalid",
|
||||
aws_secret_access_key="invalid",
|
||||
)
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.get_user()
|
||||
ex.exception.response["Error"]["Code"].should.equal("InvalidClientTokenId")
|
||||
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
|
||||
|
|
@ -197,7 +195,7 @@ def test_auth_failure():
|
|||
aws_access_key_id="invalid",
|
||||
aws_secret_access_key="invalid",
|
||||
)
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.describe_instances()
|
||||
ex.exception.response["Error"]["Code"].should.equal("AuthFailure")
|
||||
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(401)
|
||||
|
|
@ -216,7 +214,7 @@ def test_signature_does_not_match():
|
|||
aws_access_key_id=access_key["AccessKeyId"],
|
||||
aws_secret_access_key="invalid",
|
||||
)
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.get_user()
|
||||
ex.exception.response["Error"]["Code"].should.equal("SignatureDoesNotMatch")
|
||||
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
|
||||
|
|
@ -235,7 +233,7 @@ def test_auth_failure_with_valid_access_key_id():
|
|||
aws_access_key_id=access_key["AccessKeyId"],
|
||||
aws_secret_access_key="invalid",
|
||||
)
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.describe_instances()
|
||||
ex.exception.response["Error"]["Code"].should.equal("AuthFailure")
|
||||
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(401)
|
||||
|
|
@ -255,7 +253,7 @@ def test_access_denied_with_no_policy():
|
|||
aws_access_key_id=access_key["AccessKeyId"],
|
||||
aws_secret_access_key=access_key["SecretAccessKey"],
|
||||
)
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.describe_instances()
|
||||
ex.exception.response["Error"]["Code"].should.equal("AccessDenied")
|
||||
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
|
||||
|
|
@ -321,7 +319,7 @@ def test_access_denied_for_run_instances():
|
|||
aws_access_key_id=access_key["AccessKeyId"],
|
||||
aws_secret_access_key=access_key["SecretAccessKey"],
|
||||
)
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.run_instances(MaxCount=1, MinCount=1)
|
||||
ex.exception.response["Error"]["Code"].should.equal("AccessDenied")
|
||||
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
|
||||
|
|
@ -352,7 +350,7 @@ def test_access_denied_with_denying_policy():
|
|||
aws_access_key_id=access_key["AccessKeyId"],
|
||||
aws_secret_access_key=access_key["SecretAccessKey"],
|
||||
)
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.create_vpc(CidrBlock="10.0.0.0/16")
|
||||
ex.exception.response["Error"]["Code"].should.equal("AccessDenied")
|
||||
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
|
||||
|
|
@ -452,7 +450,7 @@ def test_s3_access_denied_with_denying_attached_group_policy():
|
|||
aws_access_key_id=access_key["AccessKeyId"],
|
||||
aws_secret_access_key=access_key["SecretAccessKey"],
|
||||
)
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.list_buckets()
|
||||
ex.exception.response["Error"]["Code"].should.equal("AccessDenied")
|
||||
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
|
||||
|
|
@ -486,7 +484,7 @@ def test_s3_access_denied_with_denying_inline_group_policy():
|
|||
aws_secret_access_key=access_key["SecretAccessKey"],
|
||||
)
|
||||
client.create_bucket(Bucket=bucket_name)
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.get_object(Bucket=bucket_name, Key="sdfsdf")
|
||||
ex.exception.response["Error"]["Code"].should.equal("AccessDenied")
|
||||
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
|
||||
|
|
@ -532,7 +530,7 @@ def test_access_denied_with_many_irrelevant_policies():
|
|||
aws_access_key_id=access_key["AccessKeyId"],
|
||||
aws_secret_access_key=access_key["SecretAccessKey"],
|
||||
)
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.create_key_pair(KeyName="TestKey")
|
||||
ex.exception.response["Error"]["Code"].should.equal("AccessDenied")
|
||||
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
|
||||
|
|
@ -631,7 +629,7 @@ def test_access_denied_with_temporary_credentials():
|
|||
aws_secret_access_key=credentials["SecretAccessKey"],
|
||||
aws_session_token=credentials["SessionToken"],
|
||||
)
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.create_db_instance(
|
||||
DBInstanceIdentifier="test-db-instance",
|
||||
DBInstanceClass="db.t3",
|
||||
|
|
@ -678,7 +676,7 @@ def test_s3_invalid_access_key_id():
|
|||
aws_access_key_id="invalid",
|
||||
aws_secret_access_key="invalid",
|
||||
)
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.list_buckets()
|
||||
ex.exception.response["Error"]["Code"].should.equal("InvalidAccessKeyId")
|
||||
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
|
||||
|
|
@ -700,7 +698,7 @@ def test_s3_signature_does_not_match():
|
|||
aws_secret_access_key="invalid",
|
||||
)
|
||||
client.create_bucket(Bucket=bucket_name)
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.put_object(Bucket=bucket_name, Key="abc")
|
||||
ex.exception.response["Error"]["Code"].should.equal("SignatureDoesNotMatch")
|
||||
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
|
||||
|
|
@ -736,7 +734,7 @@ def test_s3_access_denied_not_action():
|
|||
aws_secret_access_key=access_key["SecretAccessKey"],
|
||||
)
|
||||
client.create_bucket(Bucket=bucket_name)
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.delete_object(Bucket=bucket_name, Key="sdfsdf")
|
||||
ex.exception.response["Error"]["Code"].should.equal("AccessDenied")
|
||||
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
|
||||
|
|
@ -776,7 +774,7 @@ def test_s3_invalid_token_with_temporary_credentials():
|
|||
aws_session_token="invalid",
|
||||
)
|
||||
client.create_bucket(Bucket=bucket_name)
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.list_bucket_metrics_configurations(Bucket=bucket_name)
|
||||
ex.exception.response["Error"]["Code"].should.equal("InvalidToken")
|
||||
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue