~ubuntu-branches/ubuntu/saucy/keystone/saucy-proposed

« back to all changes in this revision

Viewing changes to keystone/test/functional/test_request_specs.py

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2011-08-23 10:18:22 UTC
  • Revision ID: james.westby@ubuntu.com-20110823101822-enve6zceb3lqhuvj
Tags: upstream-1.0~d4~20110823.1078
ImportĀ upstreamĀ versionĀ 1.0~d4~20110823.1078

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import unittest2 as unittest
 
2
from keystone.test.functional import common
 
3
 
 
4
 
 
5
class TestUrlHandling(common.KeystoneTestCase):
 
6
    """Tests API's global URL handling behaviors"""
 
7
 
 
8
    def test_optional_trailing_slash(self):
 
9
        """Same response returned regardless of a trailing slash in the url."""
 
10
        r1 = self.service_request(path='/')
 
11
        r2 = self.service_request(path='')
 
12
        self.assertEqual(r1.read(), r2.read())
 
13
 
 
14
 
 
15
class TestContentTypes(common.KeystoneTestCase):
 
16
    """Tests API's Content-Type handling"""
 
17
 
 
18
    def test_default_content_type(self):
 
19
        """Service returns JSON without being asked to"""
 
20
        r = self.service_request()
 
21
        self.assertTrue('application/json' in r.getheader('Content-Type'))
 
22
 
 
23
    def test_xml_extension(self):
 
24
        """Service responds to .xml URL extension"""
 
25
        r = self.service_request(path='.xml')
 
26
        self.assertTrue('application/xml' in r.getheader('Content-Type'))
 
27
 
 
28
    def test_json_extension(self):
 
29
        """Service responds to .json URL extension"""
 
30
        r = self.service_request(path='.json')
 
31
        self.assertTrue('application/json' in r.getheader('Content-Type'))
 
32
 
 
33
    def test_xml_accept_header(self):
 
34
        """Service responds to xml Accept header"""
 
35
        r = self.service_request(headers={'Accept': 'application/xml'})
 
36
        self.assertTrue('application/xml' in r.getheader('Content-Type'))
 
37
 
 
38
    def test_json_accept_header(self):
 
39
        """Service responds to json Accept header"""
 
40
        r = self.service_request(headers={'Accept': 'application/json'})
 
41
        self.assertTrue('application/json' in r.getheader('Content-Type'))
 
42
 
 
43
    def test_versioned_xml_accept_header(self):
 
44
        """Service responds to versioned xml Accept header"""
 
45
        r = self.service_request(headers={
 
46
            'Accept': 'application/vnd.openstack.identity-v2.0+xml'})
 
47
        self.assertTrue('application/xml' in r.getheader('Content-Type'))
 
48
 
 
49
    def test_versioned_json_accept_header(self):
 
50
        """Service responds to versioned json Accept header"""
 
51
        r = self.service_request(headers={
 
52
            'Accept': 'application/vnd.openstack.identity-v2.0+json'})
 
53
        self.assertTrue('application/json' in r.getheader('Content-Type'))
 
54
 
 
55
    def test_xml_extension_overrides_conflicting_header(self):
 
56
        """Service returns XML when Accept header conflicts with extension"""
 
57
        r = self.service_request(path='.xml',
 
58
            headers={'Accept': 'application/json'})
 
59
 
 
60
        self.assertTrue('application/xml' in r.getheader('Content-Type'))
 
61
 
 
62
    def test_json_extension_overrides_conflicting_header(self):
 
63
        """Service returns JSON when Accept header conflicts with extension"""
 
64
        r = self.service_request(path='.json',
 
65
            headers={'Accept': 'application/xml'})
 
66
 
 
67
        self.assertTrue('application/json' in r.getheader('Content-Type'))
 
68
 
 
69
    def test_xml_content_type_on_404(self):
 
70
        """Content-Type should be honored even on 404 errors (Issue #13)"""
 
71
        r = self.service_request(path='/completely-invalid-path',
 
72
            headers={'Accept': 'application/xml'},
 
73
            assert_status=404)
 
74
 
 
75
        # Commenting this assertion out, as it currently fails
 
76
        self.assertTrue('application/xml' in r.getheader('Content-Type'),
 
77
            'application/xml not in %s' % r.getheader('Content-Type'))
 
78
 
 
79
    def test_json_content_type_on_404(self):
 
80
        """Content-Type should be honored even on 404 errors (Issue #13)"""
 
81
        r = self.service_request(path='/completely-invalid-path',
 
82
            headers={'Accept': 'application/json'},
 
83
            assert_status=404)
 
84
 
 
85
        # Commenting this assertion out, as it currently fails
 
86
        self.assertTrue('application/json' in r.getheader('Content-Type'),
 
87
            'application/json not in %s' % r.getheader('Content-Type'))
 
88
 
 
89
 
 
90
if __name__ == '__main__':
 
91
    unittest.main()