From 2d98a9caefba9175088e67f92f47ece31b3af306 Mon Sep 17 00:00:00 2001 From: Steve Pulec Date: Mon, 11 Mar 2013 00:12:22 -0400 Subject: [PATCH] some more tests to bump coverage --- moto/dynamodb/urls.py | 27 ---------------------- moto/ec2/responses/amis.py | 8 +++++-- moto/ec2/responses/elastic_block_store.py | 2 ++ moto/s3/responses.py | 2 -- tests/test_ec2/test_amis.py | 2 ++ tests/test_ec2/test_elastic_block_store.py | 6 +++++ 6 files changed, 16 insertions(+), 31 deletions(-) diff --git a/moto/dynamodb/urls.py b/moto/dynamodb/urls.py index 61346a49b..a02808ea6 100644 --- a/moto/dynamodb/urls.py +++ b/moto/dynamodb/urls.py @@ -1,37 +1,10 @@ from .responses import handler -def sts_handler(uri, body, headers): - return GET_SESSION_TOKEN_RESULT - url_bases = [ "https?://dynamodb.us-east-1.amazonaws.com", - "https?://sts.amazonaws.com", ] url_paths = { "{0}/": handler, } - - -GET_SESSION_TOKEN_RESULT = """ - - - - - AQoEXAMPLEH4aoAH0gNCAPyJxz4BlCFFxWNE1OPTgk5TthT+FvwqnKwRcOIfrRh3c/L - To6UDdyJwOOvEVPvLXCrrrUtdnniCEXAMPLE/IvU1dYUg2RVAJBanLiHb4IgRmpRV3z - rkuWJOgQs8IZZaIv2BXIa2R4OlgkBN9bkUDNCJiBeb/AXlzBBko7b15fjrBs2+cTQtp - Z3CYWFXG8C5zqx37wnOE49mRl/+OtkIKGO7fAE - - - wJalrXUtnFEMI/K7MDENG/bPxRfiCYzEXAMPLEKEY - - 2011-07-11T19:55:29.611Z - AKIAIOSFODNN7EXAMPLE - - - - 58c5dbae-abef-11e0-8cfe-09039844ac7d - -""" diff --git a/moto/ec2/responses/amis.py b/moto/ec2/responses/amis.py index 24cf9e94b..afce0bbb5 100644 --- a/moto/ec2/responses/amis.py +++ b/moto/ec2/responses/amis.py @@ -22,8 +22,12 @@ class AmisResponse(object): def deregister_image(self): ami_id = self.querystring.get('ImageId')[0] success = ec2_backend.deregister_image(ami_id) - template = Template(DESCRIBE_IMAGES_RESPONSE) - return template.render(success=str(success).lower()) + template = Template(DEREGISTER_IMAGE_RESPONSE) + rendered = template.render(success=str(success).lower()) + if success: + return rendered + else: + return rendered, dict(status=404) def describe_image_attribute(self): raise NotImplementedError('AMIs.describe_image_attribute is not yet implemented') diff --git a/moto/ec2/responses/elastic_block_store.py b/moto/ec2/responses/elastic_block_store.py index 47d64b912..bdea18188 100644 --- a/moto/ec2/responses/elastic_block_store.py +++ b/moto/ec2/responses/elastic_block_store.py @@ -13,6 +13,8 @@ class ElasticBlockStore(object): device_path = self.querystring.get('Device')[0] attachment = ec2_backend.attach_volume(volume_id, instance_id, device_path) + if not attachment: + return "", dict(status=404) template = Template(ATTACHED_VOLUME_RESPONSE) return template.render(attachment=attachment) diff --git a/moto/s3/responses.py b/moto/s3/responses.py index cfd9a4211..939c0c881 100644 --- a/moto/s3/responses.py +++ b/moto/s3/responses.py @@ -89,8 +89,6 @@ def key_response(uri_info, body, headers): key = s3_backend.get_key(bucket_name, key_name) if key: return "", dict(etag=key.etag) - else: - return "" elif method == 'HEAD': key = s3_backend.get_key(bucket_name, key_name) if key: diff --git a/tests/test_ec2/test_amis.py b/tests/test_ec2/test_amis.py index 53a4e3b20..aaf63409c 100644 --- a/tests/test_ec2/test_amis.py +++ b/tests/test_ec2/test_amis.py @@ -19,6 +19,8 @@ def test_ami_create_and_delete(): success = conn.deregister_image(image) success.should.be.true + success = conn.deregister_image.when.called_with(image).should.throw(EC2ResponseError) + @mock_ec2 def test_ami_create_from_missing_instance(): diff --git a/tests/test_ec2/test_elastic_block_store.py b/tests/test_ec2/test_elastic_block_store.py index 43dfcaff8..f6afa13c3 100644 --- a/tests/test_ec2/test_elastic_block_store.py +++ b/tests/test_ec2/test_elastic_block_store.py @@ -46,9 +46,15 @@ def test_volume_attach_and_detach(): volume.update() volume.volume_state().should.equal('available') + volume.attach.when.called_with( + 'i-1234abcd', "/dev/sdh").should.throw(EC2ResponseError) + conn.detach_volume.when.called_with( volume.id, instance.id, "/dev/sdh").should.throw(EC2ResponseError) + conn.detach_volume.when.called_with( + volume.id, 'i-1234abcd', "/dev/sdh").should.throw(EC2ResponseError) + @mock_ec2 def test_create_snapshot():