def test_transfer_data(self): dispatcher = dispatch.Dispatcher(_TEST_HANDLERS_DIR, None) request = mock.MockRequest(connection=mock.MockConn('')) request.ws_resource = '/origin_check' request.ws_protocol = 'p1' dispatcher.transfer_data(request) self.assertEqual('origin_check_wsh.py is called for /origin_check, p1', request.connection.written_data()) request = mock.MockRequest(connection=mock.MockConn('')) request.ws_resource = '/sub/plain' request.ws_protocol = None dispatcher.transfer_data(request) self.assertEqual('sub/plain_wsh.py is called for /sub/plain, None', request.connection.written_data()) request = mock.MockRequest(connection=mock.MockConn('')) request.ws_resource = '/sub/plain?' request.ws_protocol = None dispatcher.transfer_data(request) self.assertEqual('sub/plain_wsh.py is called for /sub/plain?, None', request.connection.written_data()) request = mock.MockRequest(connection=mock.MockConn('')) request.ws_resource = '/sub/plain?q=v' request.ws_protocol = None dispatcher.transfer_data(request) self.assertEqual('sub/plain_wsh.py is called for /sub/plain?q=v, None', request.connection.written_data())
def _create_request(request_def): conn = mock.MockConn('') conn.local_addr = ('0.0.0.0', request_def[0]) return mock.MockRequest( uri=request_def[1], headers_in=request_def[2], connection=conn)
def test_transfer_data_handler_exception(self): dispatcher = dispatch.Dispatcher(_TEST_HANDLERS_DIR, None) request = mock.MockRequest(connection=mock.MockConn('')) request.ws_resource = '/sub/exception_in_transfer' request.ws_protocol = 'p3' try: dispatcher.transfer_data(request) self.fail() except Exception, e: self.failUnless(str(e).find('Intentional') != -1)
def test_transfer_data_no_handler(self): dispatcher = dispatch.Dispatcher(_TEST_HANDLERS_DIR, None) for resource in ['/blank', '/sub/non_callable', '/sub/no_wsh_at_the_end', '/does/not/exist']: request = mock.MockRequest(connection=mock.MockConn('')) request.ws_resource = resource request.ws_protocol = 'p2' try: dispatcher.transfer_data(request) self.fail() except dispatch.DispatchError, e: self.failUnless(str(e).find('No handler') != -1) except Exception: self.fail()
def _create_request(read_data): return mock.MockRequest(connection=mock.MockConn(read_data))
def setUp(self): self._conn = mock.MockConn('ABC\r\nDEFG\r\n\r\nHIJK')
def _create_request(request_def): conn = mock.MockConn('') return mock.MockRequest(method=request_def.method, uri=request_def.uri, headers_in=request_def.headers, connection=conn)