diff --git a/tests/conftest.py b/tests/conftest.py index 650f3c127..ffb9ce0e5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -579,3 +579,27 @@ def text_summary_lines(jm, failure_lines, test_repository, artifacts): summary_lines.append(summary_line) return summary_lines + + +@pytest.fixture +def test_perf_alert_summary(test_repository, test_perf_signature): + from treeherder.perf.models import PerformanceAlertSummary + return PerformanceAlertSummary.objects.create( + repository=test_repository, + prev_result_set_id=0, + result_set_id=1, + last_updated=datetime.datetime.now()) + + +@pytest.fixture +def test_perf_alert(test_perf_signature, test_perf_alert_summary): + from treeherder.perf.models import PerformanceAlert + return PerformanceAlert.objects.create( + summary=test_perf_alert_summary, + series_signature=test_perf_signature, + is_regression=True, + amount_pct=0.5, + amount_abs=50.0, + prev_value=100.0, + new_value=150.0, + t_value=20.0) diff --git a/tests/perfalert/test_alert_modification.py b/tests/perfalert/test_alert_modification.py index c1989febf..d62121339 100644 --- a/tests/perfalert/test_alert_modification.py +++ b/tests/perfalert/test_alert_modification.py @@ -7,64 +7,36 @@ from treeherder.perf.models import (PerformanceAlert, PerformanceAlertSummary) -def test_summary_modification(test_repository, test_perf_signature): - s = PerformanceAlertSummary.objects.create( - id=1, - repository=test_repository, - prev_result_set_id=0, - result_set_id=1, - last_updated=datetime.datetime.now()) - p = PerformanceAlert.objects.create( - id=1, - summary=s, - series_signature=test_perf_signature, - is_regression=True, - amount_pct=0.5, - amount_abs=50.0, - prev_value=100.0, - new_value=150.0, - t_value=20.0) +def test_summary_modification(test_repository, test_perf_signature, + test_perf_alert_summary, test_perf_alert): + (s, a) = (test_perf_alert_summary, test_perf_alert) assert s.bug_number is None assert s.status == PerformanceAlertSummary.UNTRIAGED # acknowledge alert, make sure summary status is updated - p.status = PerformanceAlert.ACKNOWLEDGED - p.save() + a.status = PerformanceAlert.ACKNOWLEDGED + a.save() s = PerformanceAlertSummary.objects.get(id=1) assert s.status == PerformanceAlertSummary.INVESTIGATING # reset alert to untriaged, likewise make sure summary status # gets updated - p.status = PerformanceAlert.UNTRIAGED - p.save() + a.status = PerformanceAlert.UNTRIAGED + a.save() s = PerformanceAlertSummary.objects.get(id=1) assert s.status == PerformanceAlertSummary.UNTRIAGED -def test_alert_modification(test_repository, test_perf_signature): - s = PerformanceAlertSummary.objects.create( - id=1, - repository=test_repository, - prev_result_set_id=0, - result_set_id=1, - last_updated=datetime.datetime.now()) +def test_alert_modification(test_repository, test_perf_signature, + test_perf_alert_summary, test_perf_alert): + p = test_perf_alert s2 = PerformanceAlertSummary.objects.create( id=2, repository=test_repository, prev_result_set_id=1, result_set_id=2, last_updated=datetime.datetime.now()) - p = PerformanceAlert.objects.create( - id=1, - summary=s, - series_signature=test_perf_signature, - is_regression=True, - amount_pct=0.5, - amount_abs=50.0, - prev_value=100.0, - new_value=150.0, - t_value=20.0) assert p.related_summary is None assert p.status == PerformanceAlert.UNTRIAGED diff --git a/tests/webapp/api/test_performance_alerts_api.py b/tests/webapp/api/test_performance_alerts_api.py index 1d7afffa2..d9493eeb4 100644 --- a/tests/webapp/api/test_performance_alerts_api.py +++ b/tests/webapp/api/test_performance_alerts_api.py @@ -7,25 +7,7 @@ from treeherder.perf.models import (PerformanceAlert, PerformanceAlertSummary) -def test_alerts(webapp, test_repository, test_perf_signature, test_user, - test_sheriff): - s = PerformanceAlertSummary.objects.create( - id=1, - repository=test_repository, - prev_result_set_id=0, - result_set_id=1, - last_updated=datetime.datetime.now()) - PerformanceAlert.objects.create( - id=1, - summary=s, - series_signature=test_perf_signature, - is_regression=True, - amount_pct=0.5, - amount_abs=50.0, - prev_value=100.0, - new_value=150.0, - t_value=20.0) - +def test_alerts_get(webapp, test_repository, test_perf_alert): resp = webapp.get(reverse('performance-alerts-list')) assert resp.status_int == 200 @@ -48,7 +30,11 @@ def test_alerts(webapp, test_repository, test_perf_signature, test_user, ]) assert resp.json['results'][0]['related_summary_id'] is None - # create a new summary and reassign the alert to it + +def test_alerts_put(webapp, test_repository, test_perf_alert, test_user, + test_sheriff): + # create a new summary and try to reassign the alert to it with varying + # levels of permission, then verify the return value changes accordingly PerformanceAlertSummary.objects.create( id=2, repository=test_repository, @@ -56,6 +42,10 @@ def test_alerts(webapp, test_repository, test_perf_signature, test_user, result_set_id=2, last_updated=datetime.datetime.now()) + resp = webapp.get(reverse('performance-alerts-list')) + assert resp.status_int == 200 + assert resp.json['results'][0]['related_summary_id'] is None + # verify that we fail if not authenticated webapp.put_json(reverse('performance-alerts-list') + '1/', { 'related_summary_id': 2, diff --git a/tests/webapp/api/test_performance_alertsummary_api.py b/tests/webapp/api/test_performance_alertsummary_api.py index 344cef293..03f51c74f 100644 --- a/tests/webapp/api/test_performance_alertsummary_api.py +++ b/tests/webapp/api/test_performance_alertsummary_api.py @@ -1,35 +1,51 @@ -import datetime - +from django.contrib.auth.models import User from django.core.urlresolvers import reverse from rest_framework.test import APIClient -from treeherder.perf.models import (PerformanceAlert, - PerformanceAlertSummary) +from treeherder.perf.models import PerformanceAlertSummary -def test_alert_summaries(webapp, test_repository, test_perf_signature, - test_user, test_sheriff): - s = PerformanceAlertSummary.objects.create( - id=1, - repository=test_repository, - prev_result_set_id=0, - result_set_id=1, - last_updated=datetime.datetime.now()) - PerformanceAlert.objects.create( - id=1, - summary=s, - series_signature=test_perf_signature, - is_regression=True, - amount_pct=0.5, - amount_abs=50.0, - prev_value=100.0, - new_value=150.0, - t_value=20.0) - +def test_alert_summaries_get(webapp, test_perf_alert_summary, + test_perf_alert): # verify that we get the performance summary + alert on GET resp = webapp.get(reverse('performance-alert-summaries-list')) assert resp.status_int == 200 + # should just have the one alert summary (with one alert) + assert resp.json['next'] is None + assert resp.json['previous'] is None + assert len(resp.json['results']) == 1 + assert set(resp.json['results'][0].keys()) == set([ + 'alerts', + 'bug_number', + 'framework', + 'id', + 'last_updated', + 'prev_result_set_id', + 'related_alerts', + 'repository', + 'result_set_id', + 'status', + ]) + assert len(resp.json['results'][0]['alerts']) == 1 + assert set(resp.json['results'][0]['alerts'][0].keys()) == set([ + 'id', + 'status', + 'series_signature', + 'is_regression', + 'prev_value', + 'new_value', + 't_value', + 'amount_abs', + 'amount_pct', + 'summary_id', + 'related_summary_id' + ]) + assert len(resp.json['results'][0]['related_alerts']) == 0 + + +def test_alert_summaries_put(webapp, test_repository, test_perf_signature, + test_perf_alert_summary, test_user, test_sheriff): # verify that we fail if not authenticated webapp.put_json(reverse('performance-alert-summaries-list') + '1/', { 'status': 1