From d32af928464afa3d1c6a233efaee3131be784761 Mon Sep 17 00:00:00 2001 From: John Eo Date: Mon, 9 May 2011 11:57:33 -0500 Subject: Adding unit test for the URL extension handler --- test/unit/test_exthandler.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 test/unit/test_exthandler.py (limited to 'test') diff --git a/test/unit/test_exthandler.py b/test/unit/test_exthandler.py new file mode 100644 index 00000000..f7c32fee --- /dev/null +++ b/test/unit/test_exthandler.py @@ -0,0 +1,35 @@ +import os +import sys +# Need to access identity module +sys.path.append(os.path.abspath(os.path.join( + os.getcwd(), '..', '..', 'keystone')) +) +from queryext.exthandler import UrlExtensionFilter +import unittest + + +class MockWsgiApp(object): + + def __init__(self): + pass + + def __call__(self, env, start_response): + pass + + +class UrlExtensionFilterTest(unittest.TestCase): + + def setUp(self): + self.filter = UrlExtensionFilter(MockWsgiApp(), {}) + + def test_xml_extension(self): + def _start_response(): + pass + env = {'PATH_INFO': '/v1.0/someresource.xml'} + self.filter(env, _start_response) + self.assertEqual('/v1.0/someresource', env['PATH_INFO']) + self.assertEqual('application/xml', env['HTTP_ACCEPT']) + + +if __name__ == '__main__': + unittest.main() -- cgit From d5ce3e52fa784c7e1f2b1a6998e38546b3727e8b Mon Sep 17 00:00:00 2001 From: John Eo Date: Mon, 9 May 2011 14:10:48 -0500 Subject: Added tests for the URL extension middleware. --- test/unit/test_exthandler.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/unit/test_exthandler.py b/test/unit/test_exthandler.py index f7c32fee..003923ff 100644 --- a/test/unit/test_exthandler.py +++ b/test/unit/test_exthandler.py @@ -17,19 +17,33 @@ class MockWsgiApp(object): pass +def _start_response(): + pass + + class UrlExtensionFilterTest(unittest.TestCase): def setUp(self): self.filter = UrlExtensionFilter(MockWsgiApp(), {}) def test_xml_extension(self): - def _start_response(): - pass env = {'PATH_INFO': '/v1.0/someresource.xml'} self.filter(env, _start_response) self.assertEqual('/v1.0/someresource', env['PATH_INFO']) self.assertEqual('application/xml', env['HTTP_ACCEPT']) + def test_json_extension(self): + env = {'PATH_INFO': '/v1.0/someresource.json'} + self.filter(env, _start_response) + self.assertEqual('/v1.0/someresource', env['PATH_INFO']) + self.assertEqual('application/json', env['HTTP_ACCEPT']) + + def test_extension_overrides_header(self): + env = {'PATH_INFO': '/v1.0/someresource.json', 'HTTP_ACCEPT': 'application/xml'} + self.filter(env, _start_response) + self.assertEqual('/v1.0/someresource', env['PATH_INFO']) + self.assertEqual('application/json', env['HTTP_ACCEPT']) + if __name__ == '__main__': unittest.main() -- cgit