6
from nova.api.rackspace import faults
8
class TestFaults(unittest.TestCase):
10
def test_fault_parts(self):
11
req = webob.Request.blank('/.xml')
12
f = faults.Fault(webob.exc.HTTPBadRequest(explanation='scram'))
13
resp = req.get_response(f)
15
first_two_words = resp.body.strip().split()[:2]
16
self.assertEqual(first_two_words, ['<badRequest', 'code="400">'])
17
body_without_spaces = ''.join(resp.body.split())
18
self.assertTrue('<message>scram</message>' in body_without_spaces)
20
def test_retry_header(self):
21
req = webob.Request.blank('/.xml')
22
exc = webob.exc.HTTPRequestEntityTooLarge(explanation='sorry',
23
headers={'Retry-After': 4})
25
resp = req.get_response(f)
26
first_two_words = resp.body.strip().split()[:2]
27
self.assertEqual(first_two_words, ['<overLimit', 'code="413">'])
28
body_sans_spaces = ''.join(resp.body.split())
29
self.assertTrue('<message>sorry</message>' in body_sans_spaces)
30
self.assertTrue('<retryAfter>4</retryAfter>' in body_sans_spaces)
31
self.assertEqual(resp.headers['Retry-After'], 4)
36
raise faults.Fault(webob.exc.HTTPNotFound(explanation='whut?'))
37
req = webob.Request.blank('/.xml')
38
resp = req.get_response(raiser)
39
self.assertEqual(resp.status_int, 404)
40
self.assertTrue('whut?' in resp.body)