implement delete_key_pair, test zero case

This commit is contained in:
Konstantinos Koukopoulos 2014-02-24 13:34:39 +02:00
parent 99c6b8acbe
commit e7d2c2687a
2 changed files with 15 additions and 2 deletions

View File

@ -18,7 +18,7 @@ class KeyPairs(BaseResponse):
return template.render(**keypair)
def delete_key_pair(self):
raise NotImplementedError('KeyPairs.delete_key_pair is not yet implemented')
return Template(DELETE_KEY_PAIR_RESPONSE).render(success="true")
def describe_key_pairs(self):
template = Template(DESCRIBE_KEY_PAIRS_RESPONSE)
@ -54,3 +54,9 @@ CREATE_KEY_PAIR_RESPONSE = """<CreateKeyPairResponse xmlns="http://ec2.amazonaws
CREATE_KEY_PAIR_INVALID_NAME = """<?xml version="1.0" encoding="UTF-8"?>
<Response><Errors><Error><Code>InvalidKeyPair.Duplicate</Code><Message>The keypair '{{ keypair_id }}' already exists.</Message></Error></Errors><RequestID>f4f76e81-8ca5-4e61-a6d5-a4a96EXAMPLE</RequestID></Response>
"""
DELETE_KEY_PAIR_RESPONSE = """<DeleteKeyPairResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-15/">
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
<return>{{ success }}</return>
</DeleteKeyPairResponse>"""

View File

@ -39,8 +39,15 @@ def test_key_pairs_create_exist():
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,
"The keypair 'foo' already exists."
)
@mock_ec2
def test_key_pairs_delete_no_exist():
conn = boto.connect_ec2('the_key', 'the_secret')
assert len(conn.get_all_key_pairs()) == 0
r = conn.delete_key_pair('foo')
r.should.be.ok