def test_publish_fails_for_invalid_auth(self): sess = Session(client=app.test_client()) sess.register('testuser', 'testpassword') sess.use_doc('test_cow') sess2 = Session(client=app.test_client()) sess2.register('testuser2', 'testpassword') sess2.docid = sess.docid self.assertRaises(Exception, sess2.publish)
def test_heatmap_recipe(self): ar_downsample._loadAR() reset_output() sess = Session(client=app.test_client()) output_server('Census', session=sess) source = ServerDataSource(expr={ 'op': 'Field', 'args': [':leaf', 'bivariate'] }) plot = figure(plot_width=600, plot_height=400, title="Test Title") plot.square('A', 'B', source=source) plot2 = ar_downsample.heatmap(plot, palette="Reds9", reserve_val=0, points=True, client_color=True, title="Test Title 2") source2 = self._find_source(plot2) self.assertEquals("Test Title 2", plot2.title) self.assertEquals(type(source2), ServerDataSource) transform = source2.transform self.assertEquals(type(transform['info']), ar_downsample.Const) self.assertEquals(type(transform['agg']), ar_downsample.Count) self.assertEquals(type(transform['shader']), ar_downsample.Seq) self.assertEquals(transform['shader'].out, "image")
def test_replot_property_transfer(self): ar_downsample._loadAR() sess = Session(client=app.test_client()) output_server('Census', session=sess) source = ServerDataSource( expr={'op': 'Field', 'args': [':leaf', 'bivariate']} ) plot_width = 612 plot_height = 408 plot_title = "Test title" plot = figure(plot_width=plot_width, plot_height=plot_height, title=plot_title) plot.square('A', 'B', source=source) ar_plot = ar_downsample.replot(plot) self.assertEquals(ar_plot.plot_width, plot_width, "Plot width not transfered") self.assertEquals(ar_plot.plot_height, plot_height, "Plot height not transfered") self.assertEquals(ar_plot.title, plot_title, "Plot title not transfered") plot_width = 612 plot_height = 408 plot_title = "Test title" ar_plot = ar_downsample.replot(plot, title=plot_title, plot_width=plot_width, plot_height=plot_height) self.assertEquals(ar_plot.plot_width, plot_width, "Plot width override failed") self.assertEquals(ar_plot.plot_height, plot_height, "Plot height override failed") self.assertEquals(ar_plot.title, plot_title, "Plot title override failed")
def test_replot_result_type(self): ar_downsample._loadAR() sess = Session(client=app.test_client()) output_server('Census', session=sess) source = ServerDataSource(expr={ 'op': 'Field', 'args': [':leaf', 'bivariate'] }) plot = figure() plot.square('A', 'B', source=source) expected = { "image": "Image", "image_rgb": "ImageRGBA", "multi_line": "MultiLine" } shaders = dict() for name in dir(ar_downsample): item = getattr(ar_downsample, name) if isinstance(item, ar_downsample.Shader): shaders[item] = item.out for shader_class in shaders: shader = shader_class() rslt = ar_downsample.replot(plot, shader=shader) self.assertEquals( expected[shader.out], self._glyphspec(rslt)['type'], "Error with {0}. Expected {1}, recieved {2}".format( str(shader_class), expected[shader.out], self._glyphspec(rslt)))
def test_source(self): ar_downsample._loadAR() sess = Session(client=app.test_client()) output_server('Census', session=sess) source = ServerDataSource(expr={ 'op': 'Field', 'args': [':leaf', 'bivariate'] }) plot = figure() plot.square('A', 'B', source=source) agg = ar_downsample.CountCategories() info = ar_downsample.Const(val=1) shader = ar_downsample.InterpolateColor() new_source = ar_downsample.source(plot, agg=agg, info=info, shader=shader) self.assertIsNotNone(new_source.transform) trans = new_source.transform self.assertEquals(trans['resample'], 'abstract rendering') self.assertEquals(trans['agg'], agg) self.assertEquals(trans['info'], info) self.assertEquals(trans['shader'], shader) self.assertEquals(trans['glyphspec'], plot.select({'type': GlyphRenderer})[0].glyph) self.assertEquals(trans['points'], False)
def test_source(self): ar_downsample._loadAR() sess = Session(client=app.test_client()) output_server('Census', session=sess) source = ServerDataSource( expr={'op': 'Field', 'args': [':leaf', 'bivariate']} ) plot = figure() plot.square('A', 'B', source=source) agg = ar_downsample.CountCategories() info = ar_downsample.Const(val=1) shader = ar_downsample.InterpolateColor() new_source = ar_downsample.source(plot, agg=agg, info=info, shader=shader) self.assertIsNotNone(new_source.transform) trans = new_source.transform self.assertEquals(trans['resample'], 'abstract rendering') self.assertEquals(trans['agg'], agg) self.assertEquals(trans['info'], info) self.assertEquals(trans['shader'], shader) self.assertEquals(trans['glyphspec'], plot.select({'type' : GlyphRenderer})[0].glyph) self.assertEquals(trans['points'], False)
def test_replot_result_type(self): ar_downsample._loadAR() sess = Session(client=app.test_client()) output_server('Census', session=sess) source = ServerDataSource( expr={'op': 'Field', 'args': [':leaf', 'bivariate']} ) plot = figure() plot.square('A', 'B', source=source) expected = {"image": "Image", "image_rgb": "ImageRGBA", "multi_line": "MultiLine"} shaders = dict() for name in dir(ar_downsample): item = getattr(ar_downsample, name) if isinstance(item, ar_downsample.Shader): shaders[item] = item.out for shader_class in shaders: shader = shader_class() rslt = ar_downsample.replot(plot, shader=shader) self.assertEquals(expected[shader.out], self._glyphspec(rslt)['type'], "Error with {0}. Expected {1}, recieved {2}" .format(str(shader_class), expected[shader.out], self._glyphspec(rslt)))
def test_publish(self): sess = Session(client=app.test_client()) sess.register('testuser', 'testpassword') sess.use_doc('test_cow') sess.publish() doc = Doc.load(bokeh_app.servermodel_storage, sess.docid) assert doc.title == 'test_cow' assert doc.published == True
def test_register_configuration(self): #create a dummy config file config = tempfile.mkdtemp() #create server server = Session(name="foo", client=app.test_client(), configdir=config, load_from_config=True) assert server.userapikey == "nokey" #register a user server.register("testuser", "fluffy") assert server.userapikey and server.userapikey != "nokey" server2 = Session(name="foo", client=app.test_client(), configdir=config, load_from_config=True) assert server2.userapikey == server.userapikey assert server2.root_url == server.root_url
def test_login2(self): #create a server config, register a user config1 = tempfile.mkdtemp() server = Session(name="foo", client=app.test_client(), configdir=config1, load_from_config=True) assert server.userapikey == "nokey" server.register("testuser", "fluffy") assert server.userapikey and server.userapikey != "nokey" config2 = tempfile.mkdtemp() server2 = Session(name="foo", client=app.test_client(), configdir=config2, load_from_config=True) assert server2.userapikey == "nokey" server2.login("testuser", "fluffy") #make sure the userapikeys match assert server2.userapikey == server.userapikey
def setUp(self): server_settings.reset() for k, v in self.options.items(): setattr(server_settings, k, v) server_settings.model_backend = {'type': 'memory'} configure.configure_flask() with mock.patch('bokeh.server.configure.logging'): configure.register_blueprint() #ugh..need better way to initialize this app.secret_key = server_settings.secret_key app.debug = True self.client = app.test_client()
def test_login1(self): username = "******" password = "******" user.new_user(bokeh_app.servermodel_storage, username, password) sess = Session(client=app.test_client()) #have not logged in yet, so userinfo should return http error self.assertRaises(Exception, lambda : sess.userinfo) #try logging in with wrong password, should be 403 self.assertRaises(Exception, sess.login, 'testuser2', 'wrong password') #actually login sess.login('testuser2', 'fluffy') assert sess.userinfo['username'] == 'testuser2'
def test_login1(self): username = "******" password = "******" user.new_user(bokeh_app.servermodel_storage, username, password) sess = Session(client=app.test_client()) #have not logged in yet, so userinfo should return http error self.assertRaises(Exception, lambda: sess.userinfo) #try logging in with wrong password, should be 403 self.assertRaises(Exception, sess.login, 'testuser2', 'wrong password') #actually login sess.login('testuser2', 'fluffy') assert sess.userinfo['username'] == 'testuser2'
def test_replot_remove(self): ar_downsample._loadAR() reset_output() sess = Session(client=app.test_client()) output_server('Census', session=sess) source = ServerDataSource( expr={'op': 'Field', 'args': [':leaf', 'bivariate']} ) plot = figure() plot.square('A', 'B', source=source) ar_downsample.replot(plot, remove_original=False) self.assertTrue(plot in curdoc().context.children, "Not retained") ar_downsample.replot(plot, remove_original=True) self.assertTrue(plot not in curdoc().context.children, "Not removed") try: ar_downsample.replot(plot, remove_original=True) except: self.assertTrue(False, "Error reploting plot not in curdoc")
def test_replot_remove(self): ar_downsample._loadAR() reset_output() sess = Session(client=app.test_client()) output_server('Census', session=sess) source = ServerDataSource(expr={ 'op': 'Field', 'args': [':leaf', 'bivariate'] }) plot = figure() plot.square('A', 'B', source=source) ar_downsample.replot(plot, remove_original=False) self.assertTrue(plot in curdoc().context.children, "Not retained") ar_downsample.replot(plot, remove_original=True) self.assertTrue(plot not in curdoc().context.children, "Not removed") try: ar_downsample.replot(plot, remove_original=True) except: self.assertTrue(False, "Error reploting plot not in curdoc")
def test_replot_property_transfer(self): ar_downsample._loadAR() sess = Session(client=app.test_client()) output_server('Census', session=sess) source = ServerDataSource(expr={ 'op': 'Field', 'args': [':leaf', 'bivariate'] }) plot_width = 612 plot_height = 408 plot_title = "Test title" plot = figure(plot_width=plot_width, plot_height=plot_height, title=plot_title) plot.square('A', 'B', source=source) ar_plot = ar_downsample.replot(plot) self.assertEquals(ar_plot.plot_width, plot_width, "Plot width not transfered") self.assertEquals(ar_plot.plot_height, plot_height, "Plot height not transfered") self.assertEquals(ar_plot.title, plot_title, "Plot title not transfered") plot_width = 612 plot_height = 408 plot_title = "Test title" ar_plot = ar_downsample.replot(plot, title=plot_title, plot_width=plot_width, plot_height=plot_height) self.assertEquals(ar_plot.plot_width, plot_width, "Plot width override failed") self.assertEquals(ar_plot.plot_height, plot_height, "Plot height override failed") self.assertEquals(ar_plot.title, plot_title, "Plot title override failed")
def test_contour_recipe(self): ar_downsample._loadAR() reset_output() sess = Session(client=app.test_client()) output_server('Census', session=sess) source = ServerDataSource(expr={ 'op': 'Field', 'args': [':leaf', 'bivariate'] }) plot = figure(plot_width=600, plot_height=400, title="Test Title") plot.square('A', 'B', source=source) plot2 = ar_downsample.contours(plot, title="Contour") source2 = self._find_source(plot2) self.assertEquals("Contour", plot2.title) self.assertEquals(type(source2), ServerDataSource) transform = source2.transform self.assertEquals(type(transform['info']), ar_downsample.Const) self.assertEquals(type(transform['agg']), ar_downsample.Count) self.assertEquals(type(transform['shader']), ar_downsample.Seq) self.assertEquals(transform['shader'].out, "multi_line")
def test_contour_recipe(self): ar_downsample._loadAR() reset_output() sess = Session(client=app.test_client()) output_server('Census', session=sess) source = ServerDataSource( expr={'op': 'Field', 'args': [':leaf', 'bivariate']} ) plot = figure(plot_width=600, plot_height=400, title="Test Title") plot.square('A', 'B', source=source) plot2 = ar_downsample.contours(plot, title="Contour") source2 = self._find_source(plot2) self.assertEquals("Contour", plot2.title) self.assertEquals(type(source2), ServerDataSource) transform = source2.transform self.assertEquals(type(transform['info']), ar_downsample.Const) self.assertEquals(type(transform['agg']), ar_downsample.Count) self.assertEquals(type(transform['shader']), ar_downsample.Seq) self.assertEquals(transform['shader'].out, "multi_line")
def test_heatmap_recipe(self): ar_downsample._loadAR() reset_output() sess = Session(client=app.test_client()) output_server('Census', session=sess) source = ServerDataSource( expr={'op': 'Field', 'args': [':leaf', 'bivariate']} ) plot = figure(plot_width=600, plot_height=400, title="Test Title") plot.square('A', 'B', source=source) plot2 = ar_downsample.heatmap(plot, palette="Reds9", reserve_val=0, points=True, client_color=True, title="Test Title 2") source2 = self._find_source(plot2) self.assertEquals("Test Title 2", plot2.title) self.assertEquals(type(source2), ServerDataSource) transform = source2.transform self.assertEquals(type(transform['info']), ar_downsample.Const) self.assertEquals(type(transform['agg']), ar_downsample.Count) self.assertEquals(type(transform['shader']), ar_downsample.Seq) self.assertEquals(transform['shader'].out, "image")
def test_register(self): sess = Session(client=app.test_client()) sess.register('testuser1', 'testpassword1') sess.userinfo['username'] == 'testuser1'
def test_register_twice_should_fail(self): sess = Session(client=app.test_client()) sess.register('testuser1', 'testpassword1') self.assertRaises(RuntimeError, sess.register, 'testuser1', 'testpassword1')