def test_on_content_type():
 formatter = hug.output_format.on_content_type({'application/json': hug.output_format.json, 'text/plain': hug.output_format.text})
 class FakeRequest(object, ):
  content_type = 'application/json'
 request = FakeRequest()
 response = FakeRequest()
 converted = hug.input_format.json(formatter(BytesIO(hug.output_format.json({'name': 'name'})), request, response))
 assert (converted == {'name': 'name'})
 request.content_type = 'text/plain'
 assert (formatter('hi', request, response) == 'hi')
 with pytest.raises(hug.HTTPNotAcceptable):
  request.content_type = 'undefined; always'
  formatter('hi', request, response)

def test_on_content_type ( ) : formatter = hug . output_format . on_content_type ( { 'application/json' : hug . output_format . json , 'text/plain' : hug . output_format . text } ) class FakeRequest ( object , ) : content_type = 'application/json' request = FakeRequest ( ) response = FakeRequest ( ) converted = hug . input_format . json ( formatter ( BytesIO ( hug . output_format . json ( { 'name' : 'name' } ) ) , request , response ) ) assert ( converted == { 'name' : 'name' } ) request . content_type = 'text/plain' assert ( formatter ( 'hi' , request , response ) == 'hi' ) with pytest . raises ( hug . HTTPNotAcceptable ) : request . content_type = 'undefined; always' formatter ( 'hi' , request , response )
ensure that its possible to route the output type format by the requested content-type .