From 99c6b8acbe7725f91fdfb1e0108fa7ba92394c47 Mon Sep 17 00:00:00 2001 From: Konstantinos Koukopoulos Date: Mon, 24 Feb 2014 13:20:47 +0200 Subject: [PATCH] test DescribeKeyPairs with more than one key pair --- moto/ec2/responses/key_pairs.py | 6 ++++++ tests/test_ec2/test_key_pairs.py | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/moto/ec2/responses/key_pairs.py b/moto/ec2/responses/key_pairs.py index 9afabda80..c3072af3e 100644 --- a/moto/ec2/responses/key_pairs.py +++ b/moto/ec2/responses/key_pairs.py @@ -31,6 +31,12 @@ class KeyPairs(BaseResponse): DESCRIBE_KEY_PAIRS_RESPONSE = """ 59dbff89-35bd-4eac-99ed-be587EXAMPLE + {% for keypair in keypairs %} + + {{ keypair.name }} + {{ keypair.fingerprint }} + + {% endfor %} """ diff --git a/tests/test_ec2/test_key_pairs.py b/tests/test_ec2/test_key_pairs.py index e0cc83735..da266bd41 100644 --- a/tests/test_ec2/test_key_pairs.py +++ b/tests/test_ec2/test_key_pairs.py @@ -16,6 +16,21 @@ 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 ----') + kps = conn.get_all_key_pairs() + assert len(kps) == 1 + assert kps[0].name == 'foo' + + +@mock_ec2 +def test_key_pairs_create_two(): + conn = boto.connect_ec2('the_key', 'the_secret') + kp = conn.create_key_pair('foo') + kp = conn.create_key_pair('bar') + assert kp.material.startswith('---- BEGIN RSA PRIVATE KEY ----') + kps = conn.get_all_key_pairs() + assert len(kps) == 2 + assert kps[0].name == 'foo' + assert kps[1].name == 'bar' @mock_ec2 @@ -23,6 +38,7 @@ 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 ----') + assert len(conn.get_all_key_pairs()) == 1 # Call get_all_instances with a bad id should raise an error conn.create_key_pair.when.called_with('foo').should.throw( EC2ResponseError,