From 8b7c3a331277d9ff7f25b379976f14696417d3e2 Mon Sep 17 00:00:00 2001 From: Konstantinos Koukopoulos Date: Mon, 24 Feb 2014 13:06:53 +0200 Subject: [PATCH] add test for creating already existing keypair --- tests/test_ec2/test_key_pairs.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/test_ec2/test_key_pairs.py b/tests/test_ec2/test_key_pairs.py index 5bb26173..e0cc8373 100644 --- a/tests/test_ec2/test_key_pairs.py +++ b/tests/test_ec2/test_key_pairs.py @@ -1,6 +1,7 @@ import boto import sure # noqa +from boto.exception import EC2ResponseError from moto import mock_ec2 @@ -15,3 +16,15 @@ def test_key_pairs_create(): conn = boto.connect_ec2('the_key', 'the_secret') kp = conn.create_key_pair('foo') assert kp.material.startswith('---- BEGIN RSA PRIVATE KEY ----') + + +@mock_ec2 +def test_key_pairs_create_exist(): + conn = boto.connect_ec2('the_key', 'the_secret') + kp = conn.create_key_pair('foo') + assert kp.material.startswith('---- BEGIN RSA PRIVATE KEY ----') + # Call get_all_instances with a bad id should raise an error + conn.create_key_pair.when.called_with('foo').should.throw( + EC2ResponseError, + "The keypair 'foo' already exists." + )