diff options
author | Rob Crittenden <rcritten@redhat.com> | 2012-02-29 16:12:58 -0500 |
---|---|---|
committer | Rob Crittenden <rcritten@redhat.com> | 2012-02-29 21:03:58 -0500 |
commit | 9e3dabb8a876945910b3ae58f77a7455a692a0a3 (patch) | |
tree | db807d202899c457163f5b5cea20f876d9b259e6 /tests | |
parent | 23134479f6fb5aa79486987992f8c245522feca8 (diff) | |
download | freeipa.git-9e3dabb8a876945910b3ae58f77a7455a692a0a3.tar.gz freeipa.git-9e3dabb8a876945910b3ae58f77a7455a692a0a3.tar.xz freeipa.git-9e3dabb8a876945910b3ae58f77a7455a692a0a3.zip |
subclass HTTP_Status from plugable.Plugin, fix not_found tests
HTTP_Status needs to subclass from Plugin because it does its own logging.
Add tests for other methods of HTTP_Status
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_ipaserver/test_rpcserver.py | 53 |
1 files changed, 46 insertions, 7 deletions
diff --git a/tests/test_ipaserver/test_rpcserver.py b/tests/test_ipaserver/test_rpcserver.py index 15ca9dc0..97632b05 100644 --- a/tests/test_ipaserver/test_rpcserver.py +++ b/tests/test_ipaserver/test_rpcserver.py @@ -46,28 +46,67 @@ class StartResponse(object): def test_not_found(): - f = rpcserver.not_found + f = rpcserver.HTTP_Status() t = rpcserver._not_found_template s = StartResponse() # Test with an innocent URL: - d = dict(SCRIPT_NAME='/ipa', PATH_INFO='/foo/stuff') + url = '/ipa/foo/stuff' assert_equal( - f(d, s), + f.not_found(None, s, url, None), [t % dict(url='/ipa/foo/stuff')] ) assert s.status == '404 Not Found' - assert s.headers == [('Content-Type', 'text/html')] + assert s.headers == [('Content-Type', 'text/html; charset=utf-8')] # Test when URL contains any of '<>&' s.reset() - d = dict(SCRIPT_NAME=' ', PATH_INFO='<script>do_bad_stuff();</script>') + url =' ' + '<script>do_bad_stuff();</script>' assert_equal( - f(d, s), + f.not_found(None, s, url, None), [t % dict(url='&nbsp;<script>do_bad_stuff();</script>')] ) assert s.status == '404 Not Found' - assert s.headers == [('Content-Type', 'text/html')] + assert s.headers == [('Content-Type', 'text/html; charset=utf-8')] + + +def test_bad_request(): + f = rpcserver.HTTP_Status() + t = rpcserver._bad_request_template + s = StartResponse() + + assert_equal( + f.bad_request(None, s, 'illegal request'), + [t % dict(message='illegal request')] + ) + assert s.status == '400 Bad Request' + assert s.headers == [('Content-Type', 'text/html; charset=utf-8')] + + +def test_internal_error(): + f = rpcserver.HTTP_Status() + t = rpcserver._internal_error_template + s = StartResponse() + + assert_equal( + f.internal_error(None, s, 'request failed'), + [t % dict(message='request failed')] + ) + assert s.status == '500 Internal Server Error' + assert s.headers == [('Content-Type', 'text/html; charset=utf-8')] + + +def test_internal_error(): + f = rpcserver.HTTP_Status() + t = rpcserver._unauthorized_template + s = StartResponse() + + assert_equal( + f.unauthorized(None, s, 'unauthorized'), + [t % dict(message='unauthorized')] + ) + assert s.status == '401 Unauthorized' + assert s.headers == [('Content-Type', 'text/html; charset=utf-8')] |