def test_set_400_error(self): errorsXML = "<Error><Code>1</Code><Message>2</Message></Error>" xml = "<a><Errors>%s</Errors><b /></a>" % errorsXML error = EC2Error("<dummy />", 400) error._set_400_error(XML(xml)) self.assertEquals(error.errors[0]["Code"], "1") self.assertEquals(error.errors[0]["Message"], "2")
def _invalid_id_error(): e = EC2Error("<error/>", 400) e.errors = [{ "Code": "InvalidInstanceID.NotFound", "Message": "blah i-abef014589 blah" }] return e
def get_ec2_error(self, entity_id, format="The instance ID %r does not exist", code=503): """Make a representative EC2Error for `entity_id`, eg AWS instance_id. This error is paired with `get_wrapped_ec2_text` below. The default format represents a fairly common error seen in working with EC2. There are others.""" message = format % entity_id return EC2Error( "<error><Code>1</Code><Message>%s</Message></error>" % message, code)
def test_describe_known_failure(self): self.ec2.describe_instances("i-acf059", "i-amfine", "i-920fda") error = EC2Error("<error/>", 400) error.errors = [{ "Code": "InvalidInstanceID.NotFound", "Message": "blah i-acf059, i-920fda blah" }] self.mocker.result(fail(error)) self.mocker.replay() provider = self.get_provider() d = provider.get_machines(["i-acf059", "i-amfine", "i-920fda"]) return self.assert_not_found(d, ["i-acf059", "i-920fda"])
def test_restricted_resource_access_attempt(self): error = EC2Error(payload.sample_restricted_resource_result, 400) self.assertEquals( error.get_error_messages(), "Unauthorized attempt to access restricted resource")
def test_invalid_client_token_id(self): error = EC2Error(payload.sample_invalid_client_token_result, 400) self.assertEquals( error.get_error_messages(), ("The AWS Access Key Id you provided does not exist in our " "records."))
def test_invalid_create_security_group_result(self): error = EC2Error(payload.sample_invalid_create_security_group_result, 400) self.assertEquals(error.get_error_messages(), "Specified group name is a reserved name.")
def test_dupliate_create_security_group_result(self): error = EC2Error(payload.sample_duplicate_create_security_group_result, 400) self.assertEquals(error.get_error_messages(), "The security group 'group1' already exists.")
def test_dupliate_keypair_result(self): error = EC2Error(payload.sample_duplicate_keypair_result, 400) self.assertEquals(error.get_error_messages(), "The key pair 'key1' already exists.")
def test_multiple_errors_repr(self): error = EC2Error(payload.sample_ec2_error_messages, 400) self.assertEquals(repr(error), "<EC2Error object with Error count: 2>")
def test_single_error_repr(self): error = EC2Error(payload.sample_ec2_error_message, 400) self.assertEquals(repr(error), "<EC2Error object with Error code: Error.Code>")
def test_multiple_errors_str(self): error = EC2Error(payload.sample_ec2_error_messages, 400) self.assertEquals(str(error), "Multiple EC2 Errors.")
def test_single_error_str(self): error = EC2Error(payload.sample_ec2_error_message, 400) self.assertEquals(str(error), "Error Message: Message for Error.Code")
def test_multiple_errors(self): error = EC2Error(payload.sample_ec2_error_messages, 400) self.assertEquals(len(error.errors), 2)
def test_single_error(self): error = EC2Error(payload.sample_ec2_error_message, 400) self.assertEquals(len(error.errors), 1)
def test_has_error(self): errorsXML = "<Error><Code>Code1</Code><Message>2</Message></Error>" xml = "<a><Errors>%s</Errors><b /></a>" % errorsXML error = EC2Error(xml, 400) self.assertTrue(error.has_error("Code1"))