1
# Copyright (c) 2009 Canonical Ltd <duncan.mcgreggor@canonical.com>
2
# Licenced under the txaws licence available at /LICENSE in the txaws source.
4
from twisted.trial.unittest import TestCase
6
from txaws.s3.exception import S3Error
7
from txaws.testing import payload
8
from txaws.util import XML
11
REQUEST_ID = "0ef9fc37-6230-4d81-b2e6-1b36277d4247"
14
class S3ErrorTestCase(TestCase):
16
def test_set_400_error(self):
17
xml = "<Error><Code>1</Code><Message>2</Message></Error>"
18
error = S3Error("<dummy />")
19
error._set_400_error(XML(xml))
20
self.assertEquals(error.errors[0]["Code"], "1")
21
self.assertEquals(error.errors[0]["Message"], "2")
23
def test_get_error_code(self):
24
error = S3Error(payload.sample_s3_invalid_access_key_result)
25
self.assertEquals(error.get_error_code(), "InvalidAccessKeyId")
27
def test_get_error_message(self):
28
error = S3Error(payload.sample_s3_invalid_access_key_result)
30
error.get_error_message(),
31
("The AWS Access Key Id you provided does not exist in our "
34
def test_error_count(self):
35
error = S3Error(payload.sample_s3_invalid_access_key_result)
36
self.assertEquals(len(error.errors), 1)
38
def test_error_repr(self):
39
error = S3Error(payload.sample_s3_invalid_access_key_result)
42
"<S3Error object with Error code: InvalidAccessKeyId>")
44
def test_signature_mismatch_result(self):
45
error = S3Error(payload.sample_s3_signature_mismatch)
47
error.get_error_messages(),
48
("The request signature we calculated does not match the "
49
"signature you provided. Check your key and signing method."))
51
def test_invalid_access_key_result(self):
52
error = S3Error(payload.sample_s3_invalid_access_key_result)
54
error.get_error_messages(),
55
("The AWS Access Key Id you provided does not exist in our "
58
def test_internal_error_result(self):
59
error = S3Error(payload.sample_server_internal_error_result)
61
error.get_error_messages(),
62
"We encountered an internal error. Please try again.")