def test_get_past_benchmarks(self): doc, doc2, doc3, doc4 = self.make_benchmarks() bundle = Bundle(doc3) past_tests = list(bundle.get_past_tests()) past_ben = bundle.get_past_benchmarks( provider_name='AWS', past_results=past_tests) self.assertEqual(past_ben, [1])
def test_generate_chart_data(self): doc, doc2, doc3, doc4 = self.make_benchmarks() bundle = Bundle(doc3) chart = bundle.generate_chart_data() expected = json.dumps( { "labels": ["33", "44"], "datasets": [ { "borderColor": "#4B98D9", "lineTension": 0.1, "label": "AWS (2.00 avg 1.00 sd)", "borderWidth": 2, "backgroundColor": "#4B98D9", "data": [1.0, 3.0], "fill": False, }, { "borderColor": "#56CE65", "lineTension": 0.1, "label": "Azure (2.00 avg 0.00 sd)", "borderWidth": 2, "backgroundColor": "#56CE65", "data": [2, None], "fill": False, } ], "title": "Terasort Benchmark Chart (Units: secs " "Direction: asc)" }) self.assertEqual(chart, expected)
def test_get_past_benchmarks(self): doc, doc2, doc3, doc4 = self.make_benchmarks() bundle = Bundle(doc3) past_tests = list(bundle.get_past_tests()) past_ben = bundle.get_past_benchmarks(provider_name='AWS', past_results=past_tests) self.assertEqual(past_ben, [1, 2])
def test_generate_chart_data(self): doc, doc2, doc3, doc4 = self.make_benchmarks() bundle = Bundle(doc3) chart = bundle.generate_chart_data() expected = ('{"series": [{"data": [1, 2, 3], "name": "AWS"}], ' '"yaxis_title": "secs", "title": "terasort"}') print chart self.assertEqual(chart, expected)
def test_result(self): doc = make_doc() bundle = Bundle(bundle=doc) results = self.make_results(1) doc['test'] = {'results': results} bundle.add_test_result(doc) test = bundle.test_result() self.assertEqual(test, doc['test'])
def test_get_past_test(self): doc = make_doc(count=1) update_data(self.ds, doc) doc2 = copy.deepcopy(doc) doc2['_id'] = 'foo' doc2['date'] = '2' update_data(self.ds, doc2) bundle = Bundle(bundle=doc2) past_test = list(bundle.get_past_tests()) self.assertEqual(past_test, [doc])
def test_get_dataset(self): provider_names = ['AWS', "GCE"] datasets = Bundle._create_initial_datasets(provider_names) dataset = Bundle._get_dataset(datasets, 'AWS') expected = { 'borderColor': '#4B98D9', 'lineTension': 0.1, 'label': 'AWS', 'borderWidth': 2, 'backgroundColor': '#4B98D9', 'data': [], 'fill': False } self.assertEqual(dataset, expected)
def bundle_view(key=None): if not key: return render_template('404.html', e='Bundle not found.'), 404 ds = Datastore() cwr_result = ds.get_one({'_id': key}) if not cwr_result: return render_template('404.html', e='Bundle not found.'), 404 bundle = Bundle(cwr_result) svg_path = bundle.svg_path() bundle_name = bundle.name results = bundle.test_result() history = None chart_data = bundle.generate_chart_data() return render_template( 'bundle.html', bundle_name=bundle_name, results=results, svg_path=svg_path, history=history, chart_data=chart_data)
def test_create_intial_datasets(self): provider_names = ['AWS', "GCE"] datasets = Bundle._create_initial_datasets(provider_names) expected = [ { 'borderColor': '#4B98D9', 'lineTension': 0.1, 'label': 'AWS', 'borderWidth': 2, 'backgroundColor': '#4B98D9', 'data': [], 'fill': False }, { 'borderColor': '#56CE65', 'lineTension': 0.1, 'label': 'GCE', 'borderWidth': 2, 'backgroundColor': '#56CE65', 'data': [], 'fill': False }] self.assertEqual(datasets, expected)
def result_by_test_id(key=None): if not key: return render_template('404.html', e='Bundle not found.'), 404 test_id = {} test_id['_id'] = key cwr_result = get_results_by_test_id(test_id) if not cwr_result: return render_template('404.html', e='Bundle not found.'), 404 bundle = Bundle(cwr_result[0]) for result in cwr_result: bundle.add_test_result(result) svg_path = bundle.svg_path() bundle_name = bundle.name results = bundle.test_result() history = None chart_data = bundle.generate_chart_data() return render_template( 'bundle.html', bundle_name=bundle_name, results=results, svg_path=svg_path, history=history, chart_data=chart_data)
def test_result(self): doc = make_doc() doc['test'] = 'foo' bundle = Bundle(bundle=doc) test = bundle.test_result() self.assertEqual(test, doc['test'])
def test_svg_path(self): doc = make_doc() doc['svg_path'] = 'foo.svg' bundle = Bundle(bundle=doc) svg_path = bundle.svg_path() self.assertEqual(svg_path, 'http://data.vapour.ws/cwr/foo.svg')
def test_svg_path_none(self): doc = make_doc() bundle = Bundle(bundle=doc) svg_path = bundle.svg_path() self.assertEqual(svg_path, 'No Image')