Originally, if WSME received an Accept or Content-Type header that was not aligned with what it was prepared to handle it would error out with a 500 status code. This is not good behavior for a web service. In the process of trying to fix this it was discovered that the content-negotiation code within WSME (the code that, in part, looks for a suitable protocol handler for a request) and tests of that code are incorrect, violating expected HTTP behaviors. GET requests are passing Content-Type headers to declare the desired type of representation in the response. This is what Accept is for. Unfortunately the server-side code was perfectly willing to accept this behavior. These changes correct that. Closes-Bug: 1419110 Change-Id: I2b5c0075611490c047b27b1b43b0505fc5534b3b
43 lines
1.2 KiB
Python
43 lines
1.2 KiB
Python
# encoding=utf8
|
|
|
|
import unittest
|
|
|
|
from wsme import WSRoot
|
|
from wsme.root import default_prepare_response_body
|
|
|
|
from six import b, u
|
|
|
|
|
|
class TestRoot(unittest.TestCase):
|
|
def test_default_transaction(self):
|
|
import transaction
|
|
root = WSRoot(transaction=True)
|
|
assert root._transaction is transaction
|
|
|
|
txn = root.begin()
|
|
txn.abort()
|
|
|
|
def test_default_prepare_response_body(self):
|
|
default_prepare_response_body(None, [b('a')]) == b('a')
|
|
default_prepare_response_body(None, [b('a'), b('b')]) == b('a\nb')
|
|
default_prepare_response_body(None, [u('a')]) == u('a')
|
|
default_prepare_response_body(None, [u('a'), u('b')]) == u('a\nb')
|
|
|
|
def test_protocol_selection_error(self):
|
|
import wsme.protocol
|
|
|
|
class P(wsme.protocol.Protocol):
|
|
def accept(self, r):
|
|
raise Exception('test')
|
|
|
|
root = WSRoot()
|
|
root.addprotocol(P())
|
|
|
|
from webob import Request
|
|
req = Request.blank('/test?check=a&check=b&name=Bob')
|
|
res = root._handle_request(req)
|
|
assert res.status_int == 500
|
|
assert res.content_type == 'text/plain'
|
|
assert (res.text ==
|
|
'Unexpected error while selecting protocol: test'), req.text
|