diff options
| author | Cerberus <matt.dietz@rackspace.com> | 2010-09-27 17:01:59 -0500 |
|---|---|---|
| committer | Cerberus <matt.dietz@rackspace.com> | 2010-09-27 17:01:59 -0500 |
| commit | f32e7054052f9daca7dcb92b0fb0ff0525c073be (patch) | |
| tree | 02b0b2e4bf7d2cb5921d21b4627d5729094b288d /nova/tests | |
| parent | 0e6c3b6034ef4927e381b231bf120a4980512c4e (diff) | |
| parent | 70516be4ff02cd82dce82ac1950fc55e87bab9ec (diff) | |
| download | nova-f32e7054052f9daca7dcb92b0fb0ff0525c073be.tar.gz nova-f32e7054052f9daca7dcb92b0fb0ff0525c073be.tar.xz nova-f32e7054052f9daca7dcb92b0fb0ff0525c073be.zip | |
Merge from lp:~gundlach/nova/servers_api
Diffstat (limited to 'nova/tests')
| -rw-r--r-- | nova/tests/api/wsgi_test.py | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/nova/tests/api/wsgi_test.py b/nova/tests/api/wsgi_test.py index 786dc1bce..145b1bfee 100644 --- a/nova/tests/api/wsgi_test.py +++ b/nova/tests/api/wsgi_test.py @@ -91,6 +91,33 @@ class Test(unittest.TestCase): result = webob.Request.blank('/test/123').get_response(Router()) self.assertNotEqual(result.body, "123") - def test_serializer(self): - # TODO(eday): Placeholder for serializer testing. - pass + +class SerializerTest(unittest.TestCase): + + def match(self, url, accept, expect): + input_dict = dict(servers=dict(a=(2,3))) + expected_xml = '<servers><a>(2,3)</a></servers>' + expected_json = '{"servers":{"a":[2,3]}}' + req = webob.Request.blank(url, headers=dict(Accept=accept)) + result = wsgi.Serializer(req.environ).to_content_type(input_dict) + result = result.replace('\n', '').replace(' ', '') + if expect == 'xml': + self.assertEqual(result, expected_xml) + elif expect == 'json': + self.assertEqual(result, expected_json) + else: + raise "Bad expect value" + + def test_basic(self): + self.match('/servers/4.json', None, expect='json') + self.match('/servers/4', 'application/json', expect='json') + self.match('/servers/4', 'application/xml', expect='xml') + self.match('/servers/4.xml', None, expect='xml') + + def test_defaults_to_json(self): + self.match('/servers/4', None, expect='json') + self.match('/servers/4', 'text/html', expect='json') + + def test_suffix_takes_precedence_over_accept_header(self): + self.match('/servers/4.xml', 'application/json', expect='xml') + self.match('/servers/4.xml.', 'application/json', expect='json') |
