Finish porting from nose to pytest.
This commit is contained in:
parent
77dc60ea97
commit
ea489bce6c
72 changed files with 1289 additions and 1280 deletions
|
|
@ -1,6 +1,6 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
# Ensure 'assert_raises' context manager support for Python 2.6
|
||||
# Ensure 'pytest.raises' context manager support for Python 2.6
|
||||
from botocore.exceptions import ClientError
|
||||
|
||||
import pytest
|
||||
|
|
@ -53,9 +53,9 @@ def test_instance_launch_and_terminate():
|
|||
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
reservation = conn.run_instances("ami-1234abcd", dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
ex.exception.message.should.equal(
|
||||
ex.value.error_code.should.equal("DryRunOperation")
|
||||
ex.value.status.should.equal(400)
|
||||
ex.value.message.should.equal(
|
||||
"An error occurred (DryRunOperation) when calling the RunInstance operation: Request would have succeeded, but DryRun flag is set"
|
||||
)
|
||||
|
||||
|
|
@ -88,9 +88,9 @@ def test_instance_launch_and_terminate():
|
|||
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
conn.terminate_instances([instance.id], dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
ex.exception.message.should.equal(
|
||||
ex.value.error_code.should.equal("DryRunOperation")
|
||||
ex.value.status.should.equal(400)
|
||||
ex.value.message.should.equal(
|
||||
"An error occurred (DryRunOperation) when calling the TerminateInstance operation: Request would have succeeded, but DryRun flag is set"
|
||||
)
|
||||
|
||||
|
|
@ -215,14 +215,14 @@ def test_instance_detach_volume_wrong_path():
|
|||
)
|
||||
instance = result[0]
|
||||
for volume in instance.volumes.all():
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
instance.detach_volume(VolumeId=volume.volume_id, Device="/dev/sdf")
|
||||
|
||||
ex.exception.response["Error"]["Code"].should.equal(
|
||||
ex.value.response["Error"]["Code"].should.equal(
|
||||
"InvalidAttachment.NotFound"
|
||||
)
|
||||
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
||||
ex.exception.response["Error"]["Message"].should.equal(
|
||||
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
||||
ex.value.response["Error"]["Message"].should.equal(
|
||||
"The volume {0} is not attached to instance {1} as device {2}".format(
|
||||
volume.volume_id, instance.instance_id, "/dev/sdf"
|
||||
)
|
||||
|
|
@ -291,9 +291,9 @@ def test_get_instances_by_id():
|
|||
# Call get_all_instances with a bad id should raise an error
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.get_all_instances(instance_ids=[instance1.id, "i-1234abcd"])
|
||||
cm.exception.code.should.equal("InvalidInstanceID.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
cm.exception.request_id.should_not.be.none
|
||||
cm.value.code.should.equal("InvalidInstanceID.NotFound")
|
||||
cm.value.status.should.equal(400)
|
||||
cm.value.request_id.should_not.be.none
|
||||
|
||||
|
||||
@mock_ec2
|
||||
|
|
@ -744,9 +744,9 @@ def test_instance_start_and_stop():
|
|||
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
stopped_instances = conn.stop_instances(instance_ids, dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
ex.exception.message.should.equal(
|
||||
ex.value.error_code.should.equal("DryRunOperation")
|
||||
ex.value.status.should.equal(400)
|
||||
ex.value.message.should.equal(
|
||||
"An error occurred (DryRunOperation) when calling the StopInstance operation: Request would have succeeded, but DryRun flag is set"
|
||||
)
|
||||
|
||||
|
|
@ -757,9 +757,9 @@ def test_instance_start_and_stop():
|
|||
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
started_instances = conn.start_instances([instances[0].id], dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
ex.exception.message.should.equal(
|
||||
ex.value.error_code.should.equal("DryRunOperation")
|
||||
ex.value.status.should.equal(400)
|
||||
ex.value.message.should.equal(
|
||||
"An error occurred (DryRunOperation) when calling the StartInstance operation: Request would have succeeded, but DryRun flag is set"
|
||||
)
|
||||
|
||||
|
|
@ -775,9 +775,9 @@ def test_instance_reboot():
|
|||
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
instance.reboot(dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
ex.exception.message.should.equal(
|
||||
ex.value.error_code.should.equal("DryRunOperation")
|
||||
ex.value.status.should.equal(400)
|
||||
ex.value.message.should.equal(
|
||||
"An error occurred (DryRunOperation) when calling the RebootInstance operation: Request would have succeeded, but DryRun flag is set"
|
||||
)
|
||||
|
||||
|
|
@ -793,9 +793,9 @@ def test_instance_attribute_instance_type():
|
|||
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
instance.modify_attribute("instanceType", "m1.small", dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
ex.exception.message.should.equal(
|
||||
ex.value.error_code.should.equal("DryRunOperation")
|
||||
ex.value.status.should.equal(400)
|
||||
ex.value.message.should.equal(
|
||||
"An error occurred (DryRunOperation) when calling the ModifyInstanceType operation: Request would have succeeded, but DryRun flag is set"
|
||||
)
|
||||
|
||||
|
|
@ -821,9 +821,9 @@ def test_modify_instance_attribute_security_groups():
|
|||
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
instance.modify_attribute("groupSet", [sg_id, sg_id2], dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
ex.exception.message.should.equal(
|
||||
ex.value.error_code.should.equal("DryRunOperation")
|
||||
ex.value.status.should.equal(400)
|
||||
ex.value.message.should.equal(
|
||||
"An error occurred (DryRunOperation) when calling the ModifyInstanceSecurityGroups operation: Request would have succeeded, but DryRun flag is set"
|
||||
)
|
||||
|
||||
|
|
@ -844,9 +844,9 @@ def test_instance_attribute_user_data():
|
|||
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
instance.modify_attribute("userData", "this is my user data", dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
ex.exception.message.should.equal(
|
||||
ex.value.error_code.should.equal("DryRunOperation")
|
||||
ex.value.status.should.equal(400)
|
||||
ex.value.message.should.equal(
|
||||
"An error occurred (DryRunOperation) when calling the ModifyUserData operation: Request would have succeeded, but DryRun flag is set"
|
||||
)
|
||||
|
||||
|
|
@ -874,9 +874,9 @@ def test_instance_attribute_source_dest_check():
|
|||
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
instance.modify_attribute("sourceDestCheck", False, dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
ex.exception.message.should.equal(
|
||||
ex.value.error_code.should.equal("DryRunOperation")
|
||||
ex.value.status.should.equal(400)
|
||||
ex.value.message.should.equal(
|
||||
"An error occurred (DryRunOperation) when calling the ModifySourceDestCheck operation: Request would have succeeded, but DryRun flag is set"
|
||||
)
|
||||
|
||||
|
|
@ -920,9 +920,9 @@ def test_run_instance_with_security_group_name():
|
|||
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
group = conn.create_security_group("group1", "some description", dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
ex.exception.message.should.equal(
|
||||
ex.value.error_code.should.equal("DryRunOperation")
|
||||
ex.value.status.should.equal(400)
|
||||
ex.value.message.should.equal(
|
||||
"An error occurred (DryRunOperation) when calling the CreateSecurityGroup operation: Request would have succeeded, but DryRun flag is set"
|
||||
)
|
||||
|
||||
|
|
@ -1197,9 +1197,9 @@ def test_instance_with_nic_attach_detach():
|
|||
# Attach
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
conn.attach_network_interface(eni.id, instance.id, device_index=1, dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
ex.exception.message.should.equal(
|
||||
ex.value.error_code.should.equal("DryRunOperation")
|
||||
ex.value.status.should.equal(400)
|
||||
ex.value.message.should.equal(
|
||||
"An error occurred (DryRunOperation) when calling the AttachNetworkInterface operation: Request would have succeeded, but DryRun flag is set"
|
||||
)
|
||||
|
||||
|
|
@ -1224,9 +1224,9 @@ def test_instance_with_nic_attach_detach():
|
|||
# Detach
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
conn.detach_network_interface(instance_eni.attachment.id, dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
ex.exception.message.should.equal(
|
||||
ex.value.error_code.should.equal("DryRunOperation")
|
||||
ex.value.status.should.equal(400)
|
||||
ex.value.message.should.equal(
|
||||
"An error occurred (DryRunOperation) when calling the DetachNetworkInterface operation: Request would have succeeded, but DryRun flag is set"
|
||||
)
|
||||
|
||||
|
|
@ -1243,9 +1243,9 @@ def test_instance_with_nic_attach_detach():
|
|||
# Detach with invalid attachment ID
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.detach_network_interface("eni-attach-1234abcd")
|
||||
cm.exception.code.should.equal("InvalidAttachmentID.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
cm.exception.request_id.should_not.be.none
|
||||
cm.value.code.should.equal("InvalidAttachmentID.NotFound")
|
||||
cm.value.status.should.equal(400)
|
||||
cm.value.request_id.should_not.be.none
|
||||
|
||||
|
||||
@mock_ec2_deprecated
|
||||
|
|
@ -1306,12 +1306,12 @@ def test_run_instance_with_block_device_mappings_missing_ebs():
|
|||
"InstanceType": "t1.micro",
|
||||
"BlockDeviceMappings": [{"DeviceName": "/dev/sda2"}],
|
||||
}
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
ec2_client.run_instances(**kwargs)
|
||||
|
||||
ex.exception.response["Error"]["Code"].should.equal("MissingParameter")
|
||||
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
||||
ex.exception.response["Error"]["Message"].should.equal(
|
||||
ex.value.response["Error"]["Code"].should.equal("MissingParameter")
|
||||
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
||||
ex.value.response["Error"]["Message"].should.equal(
|
||||
"The request must contain the parameter ebs"
|
||||
)
|
||||
|
||||
|
|
@ -1330,12 +1330,12 @@ def test_run_instance_with_block_device_mappings_missing_size():
|
|||
{"DeviceName": "/dev/sda2", "Ebs": {"VolumeType": "standard"}}
|
||||
],
|
||||
}
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
ec2_client.run_instances(**kwargs)
|
||||
|
||||
ex.exception.response["Error"]["Code"].should.equal("MissingParameter")
|
||||
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
||||
ex.exception.response["Error"]["Message"].should.equal(
|
||||
ex.value.response["Error"]["Code"].should.equal("MissingParameter")
|
||||
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
||||
ex.value.response["Error"]["Message"].should.equal(
|
||||
"The request must contain the parameter size or snapshotId"
|
||||
)
|
||||
|
||||
|
|
@ -1411,9 +1411,9 @@ def test_describe_instance_status_with_instance_filter_deprecated():
|
|||
# Call get_all_instance_status with a bad id should raise an error
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.get_all_instance_status(instance_ids=[instance.id, "i-1234abcd"])
|
||||
cm.exception.code.should.equal("InvalidInstanceID.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
cm.exception.request_id.should_not.be.none
|
||||
cm.value.code.should.equal("InvalidInstanceID.NotFound")
|
||||
cm.value.status.should.equal(400)
|
||||
cm.value.request_id.should_not.be.none
|
||||
|
||||
|
||||
@mock_ec2
|
||||
|
|
@ -1540,9 +1540,9 @@ def test_get_instance_by_security_group():
|
|||
conn.modify_instance_attribute(
|
||||
instance.id, "groupSet", [security_group.id], dry_run=True
|
||||
)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
ex.exception.message.should.equal(
|
||||
ex.value.error_code.should.equal("DryRunOperation")
|
||||
ex.value.status.should.equal(400)
|
||||
ex.value.message.should.equal(
|
||||
"An error occurred (DryRunOperation) when calling the ModifyInstanceSecurityGroups operation: Request would have succeeded, but DryRun flag is set"
|
||||
)
|
||||
|
||||
|
|
@ -1664,9 +1664,9 @@ def test_describe_instance_attribute():
|
|||
client.describe_instance_attribute(
|
||||
InstanceId=instance_id, Attribute=invalid_instance_attribute
|
||||
)
|
||||
ex.exception.response["Error"]["Code"].should.equal("InvalidParameterValue")
|
||||
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
||||
ex.value.response["Error"]["Code"].should.equal("InvalidParameterValue")
|
||||
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
||||
message = "Value ({invalid_instance_attribute}) for parameter attribute is invalid. Unknown attribute.".format(
|
||||
invalid_instance_attribute=invalid_instance_attribute
|
||||
)
|
||||
ex.exception.response["Error"]["Message"].should.equal(message)
|
||||
ex.value.response["Error"]["Message"].should.equal(message)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue