~nova-coresec/nova/ppa-lucid

« back to all changes in this revision

Viewing changes to nova/tests/api/rackspace/test_faults.py

  • Committer: Soren Hansen
  • Date: 2010-10-14 21:26:14 UTC
  • mfrom: (195.1.85 ubuntu-packaging)
  • Revision ID: soren.hansen@rackspace.com-20101014212614-ioz32fe7oleepk4j
Merge ubuntu packaging branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import unittest
 
2
import webob
 
3
import webob.dec
 
4
import webob.exc
 
5
 
 
6
from nova.api.rackspace import faults
 
7
 
 
8
class TestFaults(unittest.TestCase):
 
9
 
 
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)
 
14
 
 
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)
 
19
 
 
20
    def test_retry_header(self):
 
21
        req = webob.Request.blank('/.xml')
 
22
        exc = webob.exc.HTTPRequestEntityTooLarge(explanation='sorry', 
 
23
                                                  headers={'Retry-After': 4})
 
24
        f = faults.Fault(exc)
 
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)
 
32
 
 
33
    def test_raise(self):
 
34
        @webob.dec.wsgify
 
35
        def raiser(req):
 
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)