Finish porting from nose to pytest.

This commit is contained in:
Matěj Cepl 2020-10-06 08:04:09 +02:00
commit ea489bce6c
72 changed files with 1289 additions and 1280 deletions

View file

@ -179,9 +179,9 @@ def test_invalid_client_token_id():
)
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)
ex.exception.response["Error"]["Message"].should.equal(
ex.value.response["Error"]["Code"].should.equal("InvalidClientTokenId")
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
ex.value.response["Error"]["Message"].should.equal(
"The security token included in the request is invalid."
)
@ -197,9 +197,9 @@ def test_auth_failure():
)
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)
ex.exception.response["Error"]["Message"].should.equal(
ex.value.response["Error"]["Code"].should.equal("AuthFailure")
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(401)
ex.value.response["Error"]["Message"].should.equal(
"AWS was not able to validate the provided access credentials"
)
@ -216,9 +216,9 @@ def test_signature_does_not_match():
)
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)
ex.exception.response["Error"]["Message"].should.equal(
ex.value.response["Error"]["Code"].should.equal("SignatureDoesNotMatch")
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
ex.value.response["Error"]["Message"].should.equal(
"The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details."
)
@ -235,9 +235,9 @@ def test_auth_failure_with_valid_access_key_id():
)
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)
ex.exception.response["Error"]["Message"].should.equal(
ex.value.response["Error"]["Code"].should.equal("AuthFailure")
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(401)
ex.value.response["Error"]["Message"].should.equal(
"AWS was not able to validate the provided access credentials"
)
@ -255,9 +255,9 @@ def test_access_denied_with_no_policy():
)
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)
ex.exception.response["Error"]["Message"].should.equal(
ex.value.response["Error"]["Code"].should.equal("AccessDenied")
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
ex.value.response["Error"]["Message"].should.equal(
"User: arn:aws:iam::{account_id}:user/{user_name} is not authorized to perform: {operation}".format(
account_id=ACCOUNT_ID,
user_name=user_name,
@ -283,11 +283,11 @@ def test_access_denied_with_not_allowing_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)
ex.exception.response["Error"]["Message"].should.equal(
ex.value.response["Error"]["Code"].should.equal("AccessDenied")
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
ex.value.response["Error"]["Message"].should.equal(
"User: arn:aws:iam::{account_id}:user/{user_name} is not authorized to perform: {operation}".format(
account_id=ACCOUNT_ID,
user_name=user_name,
@ -321,9 +321,9 @@ def test_access_denied_for_run_instances():
)
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)
ex.exception.response["Error"]["Message"].should.equal(
ex.value.response["Error"]["Code"].should.equal("AccessDenied")
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
ex.value.response["Error"]["Message"].should.equal(
"User: arn:aws:iam::{account_id}:user/{user_name} is not authorized to perform: {operation}".format(
account_id=ACCOUNT_ID, user_name=user_name, operation="ec2:RunInstances",
)
@ -352,9 +352,9 @@ def test_access_denied_with_denying_policy():
)
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)
ex.exception.response["Error"]["Message"].should.equal(
ex.value.response["Error"]["Code"].should.equal("AccessDenied")
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
ex.value.response["Error"]["Message"].should.equal(
"User: arn:aws:iam::{account_id}:user/{user_name} is not authorized to perform: {operation}".format(
account_id=ACCOUNT_ID, user_name=user_name, operation="ec2:CreateVpc"
)
@ -452,9 +452,9 @@ def test_s3_access_denied_with_denying_attached_group_policy():
)
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)
ex.exception.response["Error"]["Message"].should.equal("Access Denied")
ex.value.response["Error"]["Code"].should.equal("AccessDenied")
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
ex.value.response["Error"]["Message"].should.equal("Access Denied")
@set_initial_no_auth_action_count(6)
@ -486,9 +486,9 @@ def test_s3_access_denied_with_denying_inline_group_policy():
client.create_bucket(Bucket=bucket_name)
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)
ex.exception.response["Error"]["Message"].should.equal("Access Denied")
ex.value.response["Error"]["Code"].should.equal("AccessDenied")
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
ex.value.response["Error"]["Message"].should.equal("Access Denied")
@set_initial_no_auth_action_count(10)
@ -532,9 +532,9 @@ def test_access_denied_with_many_irrelevant_policies():
)
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)
ex.exception.response["Error"]["Message"].should.equal(
ex.value.response["Error"]["Code"].should.equal("AccessDenied")
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
ex.value.response["Error"]["Message"].should.equal(
"User: arn:aws:iam::{account_id}:user/{user_name} is not authorized to perform: {operation}".format(
account_id=ACCOUNT_ID, user_name=user_name, operation="ec2:CreateKeyPair"
)
@ -635,9 +635,9 @@ def test_access_denied_with_temporary_credentials():
DBInstanceClass="db.t3",
Engine="aurora-postgresql",
)
ex.exception.response["Error"]["Code"].should.equal("AccessDenied")
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
ex.exception.response["Error"]["Message"].should.equal(
ex.value.response["Error"]["Code"].should.equal("AccessDenied")
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
ex.value.response["Error"]["Message"].should.equal(
"User: arn:aws:sts::{account_id}:assumed-role/{role_name}/{session_name} is not authorized to perform: {operation}".format(
account_id=ACCOUNT_ID,
role_name=role_name,
@ -678,9 +678,9 @@ def test_s3_invalid_access_key_id():
)
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)
ex.exception.response["Error"]["Message"].should.equal(
ex.value.response["Error"]["Code"].should.equal("InvalidAccessKeyId")
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
ex.value.response["Error"]["Message"].should.equal(
"The AWS Access Key Id you provided does not exist in our records."
)
@ -700,9 +700,9 @@ def test_s3_signature_does_not_match():
client.create_bucket(Bucket=bucket_name)
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)
ex.exception.response["Error"]["Message"].should.equal(
ex.value.response["Error"]["Code"].should.equal("SignatureDoesNotMatch")
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
ex.value.response["Error"]["Message"].should.equal(
"The request signature we calculated does not match the signature you provided. Check your key and signing method."
)
@ -736,9 +736,9 @@ def test_s3_access_denied_not_action():
client.create_bucket(Bucket=bucket_name)
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)
ex.exception.response["Error"]["Message"].should.equal("Access Denied")
ex.value.response["Error"]["Code"].should.equal("AccessDenied")
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
ex.value.response["Error"]["Message"].should.equal("Access Denied")
@set_initial_no_auth_action_count(4)
@ -776,8 +776,8 @@ def test_s3_invalid_token_with_temporary_credentials():
client.create_bucket(Bucket=bucket_name)
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)
ex.exception.response["Error"]["Message"].should.equal(
ex.value.response["Error"]["Code"].should.equal("InvalidToken")
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
ex.value.response["Error"]["Message"].should.equal(
"The provided token is malformed or otherwise invalid."
)

View file

@ -24,6 +24,7 @@ def test_basic_decorator():
list(conn.get_all_instances()).should.equal([])
@pytest.mark.network
def test_context_manager():
conn = boto.connect_ec2("the_key", "the_secret")
with pytest.raises(EC2ResponseError):
@ -38,6 +39,7 @@ def test_context_manager():
conn.get_all_instances()
@pytest.mark.network
def test_decorator_start_and_stop():
conn = boto.connect_ec2("the_key", "the_secret")
with pytest.raises(EC2ResponseError):

View file

@ -1,4 +1,5 @@
import requests
import pytest
import sure # noqa
import boto3
@ -6,6 +7,7 @@ from moto import mock_sqs, settings
@mock_sqs
@pytest.mark.network
def test_passthrough_requests():
conn = boto3.client("sqs", region_name="us-west-1")
conn.create_queue(QueueName="queue1")