24
24
def test_node_to_dict(self):
25
25
xml = "<parent><child1>text1</child1><child2>text2</child2></parent>"
26
error = AWSError("<dummy />")
26
error = AWSError("<dummy />", 400)
27
27
data = error._node_to_dict(XML(xml))
28
28
self.assertEquals(data, {"child1": "text1", "child2": "text2"})
30
30
def test_set_request_id(self):
31
31
xml = "<a><b /><RequestID>%s</RequestID></a>" % REQUEST_ID
32
error = AWSError("<dummy />")
32
error = AWSError("<dummy />", 400)
33
33
error._set_request_id(XML(xml))
34
34
self.assertEquals(error.request_id, REQUEST_ID)
36
36
def test_set_host_id(self):
37
37
host_id = "ASD@#FDG$E%FG"
38
38
xml = "<a><b /><HostID>%s</HostID></a>" % host_id
39
error = AWSError("<dummy />")
39
error = AWSError("<dummy />", 400)
40
40
error._set_host_id(XML(xml))
41
41
self.assertEquals(error.host_id, host_id)
43
43
def test_set_empty_errors(self):
44
44
xml = "<a><Errors /><b /></a>"
45
error = AWSError("<dummy />")
45
error = AWSError("<dummy />", 500)
46
46
error._set_500_error(XML(xml))
47
47
self.assertEquals(error.errors, [])
49
49
def test_set_empty_error(self):
50
50
xml = "<a><Errors><Error /><Error /></Errors><b /></a>"
51
error = AWSError("<dummy />")
51
error = AWSError("<dummy />", 500)
52
52
error._set_500_error(XML(xml))
53
53
self.assertEquals(error.errors, [])
55
55
def test_parse_without_xml(self):
57
error = AWSError(xml, 400)
59
59
self.assertEquals(error.original, xml)
61
61
def test_parse_with_xml(self):
62
62
xml1 = "<dummy1 />"
63
63
xml2 = "<dummy2 />"
64
error = AWSError(xml1)
64
error = AWSError(xml1, 400)
66
66
self.assertEquals(error.original, xml2)
68
68
def test_parse_html(self):
69
69
xml = "<html><body>a page</body></html>"
70
self.assertRaises(AWSResponseParseError, AWSError, xml)
70
self.assertRaises(AWSResponseParseError, AWSError, xml, 400)
72
72
def test_empty_xml(self):
73
self.assertRaises(ValueError, AWSError, "")
73
self.assertRaises(ValueError, AWSError, "", 400)
75
75
def test_no_request_id(self):
76
76
errors = "<Errors><Error><Code /><Message /></Error></Errors>"
77
77
xml = "<Response>%s<RequestID /></Response>" % errors
78
error = AWSError(xml, 400)
79
79
self.assertEquals(error.request_id, "")
81
81
def test_no_request_id_node(self):
82
82
errors = "<Errors><Error><Code /><Message /></Error></Errors>"
83
83
xml = "<Response>%s</Response>" % errors
84
error = AWSError(xml, 400)
85
85
self.assertEquals(error.request_id, "")
87
87
def test_no_errors_node(self):
88
88
xml = "<Response><RequestID /></Response>"
89
error = AWSError(xml, 400)
90
90
self.assertEquals(error.errors, [])
92
92
def test_no_error_node(self):
93
93
xml = "<Response><Errors /><RequestID /></Response>"
94
error = AWSError(xml, 400)
95
95
self.assertEquals(error.errors, [])
97
97
def test_no_error_code_node(self):
98
98
errors = "<Errors><Error><Message /></Error></Errors>"
99
99
xml = "<Response>%s<RequestID /></Response>" % errors
100
error = AWSError(xml)
100
error = AWSError(xml, 400)
101
101
self.assertEquals(error.errors, [])
103
103
def test_no_error_message_node(self):
104
104
errors = "<Errors><Error><Code /></Error></Errors>"
105
105
xml = "<Response>%s<RequestID /></Response>" % errors
106
error = AWSError(xml)
106
error = AWSError(xml, 400)
107
107
self.assertEquals(error.errors, [])
109
109
def test_set_500_error(self):
110
110
xml = "<Error><Code>500</Code><Message>Oops</Message></Error>"
111
error = AWSError("<dummy />")
111
error = AWSError("<dummy />", 500)
112
112
error._set_500_error(XML(xml))
113
113
self.assertEquals(error.errors[0]["Code"], "500")
114
114
self.assertEquals(error.errors[0]["Message"], "Oops")