def test_http_header_encoding():
 mocked_socket = mock.MagicMock()
 mocked_socket.sendall = mock.MagicMock()
 mocked_request = mock.MagicMock()
 response = Response(mocked_request, mocked_socket, None)
 response.headers.append(('foo', u'h\xe4der'))
 with pytest.raises(UnicodeEncodeError):
  response.send_headers()
 tosend = response.default_headers()
 tosend.extend([('%s: %s\r\n' % (k, v)) for (k, v) in response.headers])
 header_str = ('%s\r\n' % ''.join(tosend))
 with pytest.raises(UnicodeEncodeError):
  mocked_socket.sendall(util.to_bytestring(header_str, 'ascii'))

def test_http_header_encoding ( ) : mocked_socket = mock . MagicMock ( ) mocked_socket . sendall = mock . MagicMock ( ) mocked_request = mock . MagicMock ( ) response = Response ( mocked_request , mocked_socket , None ) response . headers . append ( ( 'foo' , u'h\xe4der' ) ) with pytest . raises ( UnicodeEncodeError ) : response . send_headers ( ) tosend = response . default_headers ( ) tosend . extend ( [ ( '%s: %s\r\n' % ( k , v ) ) for ( k , v ) in response . headers ] ) header_str = ( '%s\r\n' % '' . join ( tosend ) ) with pytest . raises ( UnicodeEncodeError ) : mocked_socket . sendall ( util . to_bytestring ( header_str , 'ascii' ) )
tests whether http response headers are usascii encoded .