def test_default_content_type(self): """ If the Content-Type response header is not already set, set it based on the defaults """ request = DummyRequest() resource = Resource() resource.DEFAULT_CONTENT_TYPE = frozenset(["application/pyfarm"]) resource.render_tuple(request, ("body", OK, {})) self.assertEqual( request.responseHeaders.getRawHeaders("Content-Type"), ["application/pyfarm"] )
def test_content_type_already_set(self): """ If the Content-Type response header is already set, do not set it again. """ request = DummyRequest() resource = Resource() resource.DEFAULT_CONTENT_TYPE = frozenset(["application/foobar"]) resource.render_tuple( request, ("body", OK, {"Content-Type": ["application/pyfarm"]}) ) self.assertEqual( request.responseHeaders.getRawHeaders("Content-Type"), ["application/pyfarm"] )
def test_default_content_type(self): """ If the Content-Type response header is not already set, set it based on the defaults """ request = DummyRequest() resource = Resource() request.requestHeaders.setRawHeaders("Accept", ["application/json"]) resource.ALLOWED_ACCEPT = frozenset(["application/json"]) resource.ALLOWED_CONTENT_TYPE = frozenset(["application/json"]) resource.DEFAULT_CONTENT_TYPE = frozenset(["application/pyfarm"]) resource.get = lambda *_, **__: "" resource.render(request) self.assertEqual( request.responseHeaders.getRawHeaders("Content-Type"), ["application/pyfarm"] )
def test_default_content_type(self): """ If the Content-Type response header is not already set, set it based on the defaults """ request = DummyRequest() resource = Resource() resource.DEFAULT_CONTENT_TYPE = frozenset(["application/pyfarm"]) @inlineCallbacks def render(): yield succeed(None) returnValue(("body", OK)) yield resource.render_deferred(request, render()) self.assertEqual( request.responseHeaders.getRawHeaders("Content-Type"), ["application/pyfarm"] )