def test_missing_session(self, mock_warn): io._state.session = None io.push() self.assertTrue(mock_warn.called) self.assertEqual(mock_warn.call_args[0], ("push() called but no session was supplied and output_server(...) " "was never called, nothing pushed",)) self.assertEqual(mock_warn.call_args[1], {})
def test_missing_session(self, mock_warn): io._state.session = None io.push() self.assertTrue(mock_warn.called) self.assertEqual(mock_warn.call_args[0], ( 'push() called but no session was supplied and output_server(...) was never called, nothing pushed', )) self.assertEqual(mock_warn.call_args[1], {})
def test_noargs(self, mock_push_to_server): # this simulates having called output_server with these params io._state.session_id = "fakesessionid" io._state.server_url = "https://example.com/" io.push() self._check_func_called(mock_push_to_server, (), dict(websocket_url="wss://example.com/ws", document=io._state.document, session_id="fakesessionid", io_loop=None))
def test_session_arg(self, mock_push_to_server): # this simulates never calling output_server io._state.server_enabled = False io.push(session_id="somesession") self._check_func_called(mock_push_to_server, (), dict(url=io._state.url, app_path=io._state.app_path, document=io._state.document, session_id="somesession", io_loop=None))
def test_url_arg(self, mock_push_to_server): # this simulates never calling output_server io._state.server_enabled = False io.push(url="http://example.com/") self._check_func_called(mock_push_to_server, (), dict(url="http://example.com/", app_path=io._state.app_path, session_id=io._state.session_id_allowing_none, document=io._state.document, io_loop=None))
def test_session_arg(self, mock_push_to_server): # this simulates never calling output_server io._state.server_enabled = False io.push(session_id="somesession") self._check_func_called( mock_push_to_server, (), dict(url=io._state.url, app_path=io._state.app_path, document=io._state.document, session_id="somesession", io_loop=None))
def test_session_arg(self, mock_push_to_server): # set to None rather than mock objects, # this simulates never calling output_server io._state.session_id = None io._state.server_url = None io.push(session_id="somesession") self._check_func_called(mock_push_to_server, (), dict(websocket_url="ws://localhost:5006/ws", document=io._state.document, session_id="somesession", io_loop=None))
def test_url_arg(self, mock_push_to_server): # set to None rather than mock objects, # this simulates never calling output_server io._state.session_id = None io._state.server_url = None io.push(url="http://example.com/") self._check_func_called(mock_push_to_server, (), dict(websocket_url="ws://example.com/ws", document=io._state.document, session_id="default", io_loop=None))
def test_url_arg(self, mock_push_to_server): # this simulates never calling output_server io._state.server_enabled = False io.push(url="http://example.com/") self._check_func_called( mock_push_to_server, (), dict(url="http://example.com/", app_path=io._state.app_path, session_id=io._state.session_id_allowing_none, document=io._state.document, io_loop=None))
def test_document_arg(self, mock_push_to_server): # this simulates never calling output_server io._state.server_enabled = False d = Document() io.push(document=d) self._check_func_called(mock_push_to_server, (), dict(url=io._state.url, app_path=io._state.app_path, session_id=io._state.session_id_allowing_none, document=d, io_loop=None))
def test_document_arg(self, mock_push_to_server): # this simulates never calling output_server io._state.server_enabled = False d = Document() io.push(document=d) self._check_func_called( mock_push_to_server, (), dict(url=io._state.url, app_path=io._state.app_path, session_id=io._state.session_id_allowing_none, document=d, io_loop=None))
def test_missing_output_server(self, mock_push_to_server): # never calling output_server should pull session coords # off the io._state object io._state.server_enabled = False io._state.document = Document() io.push() self._check_func_called(mock_push_to_server, (), dict(url=io._state.url, app_path=io._state.app_path, session_id=io._state.session_id_allowing_none, document=io._state.document, io_loop=None))
def test_all_args(self, mock_push_to_server): d = Document() url = "https://example.com/foo" session_id = "all_args_session" # state should get ignored since we specified everything otherwise state = Mock() io_loop = Mock() io.push(document=d, url=url, state=state, session_id=session_id, io_loop=io_loop) self._check_func_called(mock_push_to_server, (), dict(websocket_url="wss://example.com/foo/ws", document=d, session_id="all_args_session", io_loop=io_loop))
def test_missing_output_server(self, mock_push_to_server): # never calling output_server should pull session coords # off the io._state object io._state.server_enabled = False io._state.document = Document() io.push() self._check_func_called( mock_push_to_server, (), dict(url=io._state.url, app_path=io._state.app_path, session_id=io._state.session_id_allowing_none, document=io._state.document, io_loop=None))
def test_noargs(self, mock_push_to_server): # if we had called output_server, the state object would be set # up like this io._state.session_id_allowing_none = "fakesessionid" io._state.url = "http://example.com/" io._state.app_path = "/bar" io._state.server_enabled = True io.push() self._check_func_called(mock_push_to_server, (), dict(url="http://example.com/", document=io._state.document, session_id="fakesessionid", app_path="/bar", io_loop=None))
def test_state_arg(self, mock_push_to_server): d = Document() url = "https://example.com/state" session_id = "state_arg_session" # state should get ignored since we specified everything otherwise state = Mock() state.document = d state.server_url = url state.session_id = session_id io.push(state=state) self._check_func_called(mock_push_to_server, (), dict(websocket_url="wss://example.com/state/ws", document=d, session_id="state_arg_session", io_loop=None))
def test_noargs(self, mock_push_to_server): # if we had called output_server, the state object would be set # up like this io._state.session_id_allowing_none = "fakesessionid" io._state.url = "http://example.com/" io._state.app_path = "/bar" io._state.server_enabled = True io.push() self._check_func_called( mock_push_to_server, (), dict(url="http://example.com/", document=io._state.document, session_id="fakesessionid", app_path="/bar", io_loop=None))
def test_io_push_to_server(self): from bokeh.io import output_server, push, curdoc, reset_output application = Application() with ManagedServerLoop(application) as server: reset_output() doc = curdoc() doc.clear() client_root = SomeModelInTestClientServer(foo=42) session_id = 'test_io_push_to_server' output_server(session_id=session_id, url=("http://localhost:%d/" % server.port)) doc.add_root(client_root) push(io_loop=server.io_loop) server_session = server.get_session('/', session_id) print(repr(server_session.document.roots)) assert len(server_session.document.roots) == 1 server_root = next(iter(server_session.document.roots)) assert client_root.foo == 42 assert server_root.foo == 42 # Now modify the client document and push client_root.foo = 57 push(io_loop=server.io_loop) server_root = next(iter(server_session.document.roots)) assert server_root.foo == 57 # Remove a root and push doc.remove_root(client_root) push(io_loop=server.io_loop) assert len(server_session.document.roots) == 0 # Clean up global IO state reset_output()
def test_session_document_args(self): sess = Mock() io.push(document="foo", session=sess) self._check_doc_store(sess, "foo")
def test_session_arg(self): sess = Mock() io.push(session=sess) self._check_doc_store(sess, io._state.document)
def test_document_arg(self): io.push(document="foo") self._check_doc_store(io._state.session, "foo")
def test_noargs(self): io.push() self._check_doc_store(io._state.session, io._state.document)