def test_init(self): c = bsc.ApplicationContext("app", io_loop="ioloop") assert c.io_loop == "ioloop" assert c.application == "app" assert c.url is None c = bsc.ApplicationContext("app", io_loop="ioloop", url="url") assert c.io_loop == "ioloop" assert c.application == "app" assert c.url == "url"
async def test_create_session_if_needed_logout_url(self) -> None: app = Application() c = bsc.ApplicationContext(app, io_loop="ioloop", logout_url="/logout") s = await c.create_session_if_needed("foo") session = c.get_session("foo") assert session == s assert c._session_contexts[session.id].logout_url == "/logout"
async def test_create_session_if_needed_bad_sessionid(self) -> None: app = Application() c = bsc.ApplicationContext(app, io_loop="ioloop") r = c.create_session_if_needed("") with pytest.raises(bsc.ProtocolError) as e: await r assert str(e.value).endswith("Session ID must not be empty")
def test_init(self): ac = bsc.ApplicationContext("app", io_loop="ioloop") sc = bsc.BokehServerContext(ac) c = bsc.BokehSessionContext("id", sc, "doc") assert c.session is None assert c.request is None assert not c.destroyed
def test_logout_url(self): ac = bsc.ApplicationContext("app", io_loop="ioloop") sc = bsc.BokehServerContext(ac) c = bsc.BokehSessionContext("id", sc, "doc", logout_url="/logout") assert c.session is None assert c.request is None assert not c.destroyed assert c.logout_url == "/logout"
async def test_create_session_if_needed_new(self): app = Application() c = bsc.ApplicationContext(app, io_loop="ioloop") class FakeRequest(object): arguments = dict(foo=10) req = FakeRequest() s = await c.create_session_if_needed("foo", request=req) assert c.get_session("foo") == s
async def test_create_session_if_needed_exists(self) -> None: app = Application() c = bsc.ApplicationContext(app, io_loop="ioloop") class FakeRequest(object): arguments = dict(foo=10) req = FakeRequest() s1 = await c.create_session_if_needed("foo", request=req) s2 = await c.create_session_if_needed("foo", request=req) assert s1 == s2
async def test_create_session_if_needed_logout_url(self): app = Application() c = bsc.ApplicationContext(app, io_loop="ioloop", logout_url="/logout") class FakeRequest(object): arguments = dict(foo=10) req = FakeRequest() s = await c.create_session_if_needed("foo", request=req) session = c.get_session("foo") assert session == s assert c._session_contexts[session.id].logout_url == "/logout"
async def test_create_session_if_needed_bad_sessionid(self): app = Application() c = bsc.ApplicationContext(app, io_loop="ioloop") class FakeRequest(object): arguments = dict(foo=10) req = FakeRequest() r = c.create_session_if_needed("", request=req) with pytest.raises(bsc.ProtocolError) as e: await r assert str(e.value).endswith("Session ID must not be empty")
def test_destroyed(self): class FakeSession(object): destroyed = False ac = bsc.ApplicationContext("app", io_loop="ioloop") sc = bsc.BokehServerContext(ac) c = bsc.BokehSessionContext("id", sc, "doc") sess = FakeSession() c._session = sess assert not c.destroyed sess.destroyed = True assert c.destroyed
async def test_async_next_tick_callback_is_called(self) -> None: app = Application() c = bsc.ApplicationContext(app, io_loop=IOLoop.current()) s = await c.create_session_if_needed("foo") latch_f = asyncio.Future() result_f = asyncio.Future() async def cb(): m = await latch_f result_f.set_result(m) s.document.add_next_tick_callback(cb) message = 'Done' latch_f.set_result(message) result = await asyncio.wait_for(result_f, 1) assert result == message
def test_get_session_success(self): c = bsc.ApplicationContext("app", io_loop="ioloop") c._sessions = dict(foo=1, bar=2) assert c.get_session("foo") == 1
def test_sessions(self): c = bsc.ApplicationContext("app", io_loop="ioloop") c._sessions = dict(foo=1, bar=2) assert set(c.sessions) == set([1,2])
async def test_create_session_if_needed_new(self) -> None: app = Application() c = bsc.ApplicationContext(app, io_loop="ioloop") s = await c.create_session_if_needed("foo") assert c.get_session("foo") == s
async def test_create_session_if_needed_exists(self) -> None: app = Application() c = bsc.ApplicationContext(app, io_loop="ioloop") s1 = await c.create_session_if_needed("foo") s2 = await c.create_session_if_needed("foo") assert s1 == s2
def test_sessions(self): ac = bsc.ApplicationContext("app", io_loop="ioloop") ac._sessions = dict(foo=1, bar=2) c = bsc.BokehServerContext(ac) assert set(c.sessions) == set([1,2])
def test_init(self): ac = bsc.ApplicationContext("app", io_loop="ioloop") c = bsc.BokehServerContext(ac) assert c.application_context == ac
def test_init(self) -> None: ac = bsc.ApplicationContext("app", io_loop="ioloop") c = bsc.BokehServerContext(ac) assert c.application_context == ac assert len(gc.get_referrers(ac)) == 0
def test_get_session_failure(self): c = bsc.ApplicationContext("app", io_loop="ioloop") c._sessions = dict(foo=1, bar=2) with pytest.raises(bsc.ProtocolError) as e: c.get_session("bax") assert str(e.value).endswith("No such session bax")