#NEWLINE# @ patch ( 'ws4py.client.socket' ) #NEWLINE# def test_invdalid_response_code( self , sock ) : #NEWLINE# #INDENT# s = MagicMock ( ) #NEWLINE# sock . socket . return_value = s #NEWLINE# sock . getaddrinfo . return_value = [ ( socket . AF_INET , socket . SOCK_STREAM , 0 , '' , ( '127.0.0.1' , 80 , 0 , 0 ) ) ] #NEWLINE# c = WebSocketBaseClient ( url = 'ws://127.0.0.1/?token=value' ) #NEWLINE# s . recv . return_value = b'\r\n' . join ( [ b'HTTP/1.1 200 Switching Protocols' , b'Connection: Upgrade' , b'Sec-Websocket-Version: 13' , b'Content-Type: text/plain;charset=utf-8' , ( b'Sec-Websocket-Accept: ' + b64encode ( sha1 ( ( c . key + WS_KEY ) ) . digest ( ) ) ) , b'Upgrade: websocket' , b'Date: Sun, 26 Jul 2015 12:32:55 GMT' , b'Server: ws4py/test' , b'\r\n' ] ) #NEWLINE# self . assertRaises ( HandshakeError , c . connect ) #NEWLINE# s . shutdown . assert_called_once_with ( socket . SHUT_RDWR ) #NEWLINE# s . close . assert_called_once_with ( )