1
import unittest2 as unittest
2
from keystone.test.functional import common
5
class TestUrlHandling(common.KeystoneTestCase):
6
"""Tests API's global URL handling behaviors"""
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())
15
class TestContentTypes(common.KeystoneTestCase):
16
"""Tests API's Content-Type handling"""
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'))
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'))
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'))
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'))
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'))
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'))
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'))
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'})
60
self.assertTrue('application/xml' in r.getheader('Content-Type'))
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'})
67
self.assertTrue('application/json' in r.getheader('Content-Type'))
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'},
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'))
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'},
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'))
90
if __name__ == '__main__':