def test_dashboard_create(): chart1 = TimeSeriesChart() chart1.with_name('chart1') chart1.with_program("data('requests.min').publish()") chart1.with_default_plot_type(PlotType.area_chart) chart2 = TimeSeriesChart() chart2.with_name('chart2') chart2.with_program("data('requests.min').publish()") chart2.with_default_plot_type(PlotType.line_chart) dashboard_name = 'removeme111' dashboard = Dashboard() dashboard.with_charts(chart1, chart2) dashboard.with_name(dashboard_name) f = StringIO() with stdout_redirected(f): dashboard.create(dry_run=True) response = f.getvalue() result_string = response[response.find('{'):]\ .replace('\'', '\"')\ .replace('("', '(\\"')\ .replace('")', '\\")') result = json.loads(result_string) assert 'charts' in result assert 'name' in result assert len(result['charts']) == 2 assert result['name'] == dashboard_name assert result['charts'][0]['options']['defaultPlotType'] \ == PlotType.area_chart.value assert result['charts'][1]['options']['defaultPlotType'] \ == PlotType.line_chart.value
def test_dashboard_update_success(sfx_recorder, session, chart): with sfx_recorder.use_cassette('dashboard_update_success', serialize_with='prettyjson'): dashboard = Dashboard(session=session) \ .with_name('testy mctesterson') \ .with_api_token('foo') \ .with_charts(chart('lol')) dashboard.create() dashboard.update(name='updated_dashboard_name', description='updated_dashboard_description')
def test_dashboard_update_failure(sfx_recorder, session, chart): chart = chart('lol') dashboard = Dashboard(session=session) \ .with_name('testy mctesterson') \ .with_api_token('foo') \ .with_charts(chart) with sfx_recorder.use_cassette('dashboard_update_failure', serialize_with='prettyjson'): # Just to make sure there are multiple dashboards exists, create a new # dashboard with the same name dashboard.create(force=True) dashboard.create(force=True) with pytest.raises(SignalAnalogError): # Verify that we can't update when multiple dashboards exist dashboard.update(name='updated_dashboard_name', description='updated_dashboard_description')
def test_dashboard_create_child_chart(sfx_recorder, session, chart): chart1 = chart('rawr') chart2 = chart('roar') dashboard = Dashboard(session=session)\ .with_name('bariumfoo')\ .with_api_token('foo')\ .with_charts(chart1) with sfx_recorder.use_cassette('dashboard_create_child_chart', serialize_with='prettyjson'): resp = dashboard.create() assert len(resp['charts']) == 1 # Simulate updating a configuration file. dashboard.options['charts'].append(chart2) resp_update = dashboard.update() assert len(resp_update['charts']) == 2
def test_dashboard_create_interactive_failure(confirm, sfx_recorder, session, chart): confirm.__getitem__.return_value = 'n' dashboard = Dashboard(session=session) \ .with_name('testy mctesterson') \ .with_api_token('foo') \ .with_charts(chart('lol')) with sfx_recorder.use_cassette('dashboard_create_failure_interactive', serialize_with='prettyjson'): # Create our first dashboard dashboard.create() with pytest.raises(SignalAnalogError): # Verify that we can't create it again dashboard.create() dashboard.create(interactive=True)
def test_dashboard_create_force_success(sfx_recorder, session, chart): dashboard = Dashboard(session=session)\ .with_name('testy mctesterson')\ .with_api_token('foo')\ .with_charts(chart('lol')) with sfx_recorder.use_cassette('dashboard_create_success_force', serialize_with='prettyjson'): # Create our first dashboard dashboard.create() with pytest.raises(SignalAnalogError): # Verify that we can't create it again dashboard.create() # Force the dashboard to create itself again dashboard.create(force=True)
def test_dashboard_create_interactive_success(confirm): confirm.__getitem__.return_value = 'y' dashboard = Dashboard(session=global_session) \ .with_name('testy mctesterson') \ .with_api_token('foo') \ .with_charts(mk_chart('lol')) with global_recorder.use_cassette('dashboard_create_success_interactive', serialize_with='prettyjson'): # Create our first dashboard dashboard.create() with pytest.raises(SignalAnalogError): # Verify that we can't create it again dashboard.create() # Force the dashboard to create itself again dashboard.create(interactive=True)
def test_dashboard_delete_child_chart(sfx_recorder, session, chart): chart1 = chart('rawr') chart2 = chart('roar') dashboard = Dashboard(session=session)\ .with_name('isley brothers')\ .with_api_token('foo')\ .with_charts(chart1, chart2) with sfx_recorder.use_cassette('dashboard_delete_child_chart', serialize_with='prettyjson'): resp = dashboard.create() assert len(resp['charts']) == 2 # Simulate removing a chart from a user's config. dashboard.options['charts'] = list(filter( lambda x: x.options != chart2.options, dashboard.options['charts'])) resp_delete = dashboard.update() # We should only have one chart assert len(resp_delete['charts']) == 1