Improved describe instance types + tests

This commit is contained in:
Nuwan Goonasekera 2020-11-22 21:14:01 +05:30
commit 114a8efac8
No known key found for this signature in database
GPG key ID: 4C28B687668239D8
4 changed files with 43 additions and 10 deletions

View file

@ -2,6 +2,9 @@ from __future__ import unicode_literals
import boto3
import sure # noqa
import pytest
from botocore.exceptions import ClientError
from moto import mock_ec2
@ -16,3 +19,28 @@ def test_describe_instance_types():
instance_types["InstanceTypes"][0].should.have.key("InstanceType")
instance_types["InstanceTypes"][0].should.have.key("MemoryInfo")
instance_types["InstanceTypes"][0]["MemoryInfo"].should.have.key("SizeInMiB")
@mock_ec2
def test_describe_instance_types_filter_by_type():
client = boto3.client("ec2", "us-east-1")
instance_types = client.describe_instance_types(InstanceTypes=['t1.micro', 't2.nano'])
instance_types.should.have.key("InstanceTypes")
instance_types["InstanceTypes"].should_not.be.empty
instance_types["InstanceTypes"].should.have.length_of(2)
instance_types["InstanceTypes"][0]['InstanceType'].should.equal('t1.micro')
instance_types["InstanceTypes"][1]['InstanceType'].should.equal('t2.nano')
@mock_ec2
def test_describe_instance_types_unknown_type():
client = boto3.client("ec2", "us-east-1")
with pytest.raises(ClientError) as err:
client.describe_instance_types(InstanceTypes=['t1.non_existent'])
err.response["Error"]["Code"].should.equal("ValidationException")
err.response["Error"]["Message"].split(":")[0].should.look_like(
"The instance type '{'t1.non_existent'}' does not exist"
)
err.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)