Commit e44ec1dc authored by Damien Lespiau's avatar Damien Lespiau
Browse files

testresult: Also allow to configure result emails on failure only


Signed-off-by: default avatarDamien Lespiau <damien.lespiau@intel.com>
parent 4e5946c0
......@@ -94,9 +94,11 @@ as well:
**always**
Always send an email, disregarding the status of the test result.
**on failure**
**on warning/failure**
Only send an email when the test has some warnings or errors.
**on failure**
Only send an email when the test has some errors.
|git-pw| helper commands
------------------------
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('patchwork', '0017_series_meta'),
]
operations = [
migrations.AlterField(
model_name='test',
name='mail_condition',
field=models.SmallIntegerField(default=0, choices=[(0, b'always'), (1, b'on warning/failure'), (2, b'on failure')]),
),
]
......@@ -707,10 +707,13 @@ class Test(models.Model):
# send result mail on any state (but pending)
CONDITION_ALWAYS = 0
# only send result on warning/failure
CONDITION_ON_FAILURE = 1
# send result mail on warning or failure
CONDITION_ON_WARNING = 1
# send result mail on error
CONDITION_ON_FAILURE = 2
CONDITION_CHOICES = (
(CONDITION_ALWAYS, 'always'),
(CONDITION_ON_WARNING, 'on warning/failure'),
(CONDITION_ON_FAILURE, 'on failure'),
)
......
......@@ -666,38 +666,30 @@ class TestResultTest(APITestBase):
for url in self.test_urls:
self.assertEqual(len(mail.outbox), 0)
self._configure_test(url, 'super test',
Test.RECIPIENT_SUBMITTER, Test.CONDITION_ALWAYS)
self._post_result(url, 'super test', 'success')
self.assertEqual(len(mail.outbox), 1)
mail.outbox = []
self._configure_test(url, 'super test',
Test.RECIPIENT_SUBMITTER, Test.CONDITION_ALWAYS)
self._post_result(url, 'super test', 'pending')
self.assertEqual(len(mail.outbox), 0)
self._configure_test(url, 'super test',
Test.RECIPIENT_SUBMITTER, Test.CONDITION_ON_FAILURE)
self._post_result(url, 'super test', 'success')
self.assertEqual(len(mail.outbox), 0)
self._configure_test(url, 'super test',
Test.RECIPIENT_SUBMITTER, Test.CONDITION_ON_FAILURE)
self._post_result(url, 'super test', 'pending')
self.assertEqual(len(mail.outbox), 0)
self._configure_test(url, 'super test',
Test.RECIPIENT_SUBMITTER, Test.CONDITION_ON_FAILURE)
self._post_result(url, 'super test', 'warning')
self.assertEqual(len(mail.outbox), 1)
mail.outbox = []
self._configure_test(url, 'super test',
Test.RECIPIENT_SUBMITTER, Test.CONDITION_ON_FAILURE)
self._post_result(url, 'super test', 'failure')
self.assertEqual(len(mail.outbox), 1)
mail.outbox = []
cases = (
# condition, test state, number of mail
(Test.CONDITION_ALWAYS, 'pending', 0),
(Test.CONDITION_ALWAYS, 'success', 1),
(Test.CONDITION_ALWAYS, 'warning', 1),
(Test.CONDITION_ALWAYS, 'failure', 1),
(Test.CONDITION_ON_WARNING, 'pending', 0),
(Test.CONDITION_ON_WARNING, 'success', 0),
(Test.CONDITION_ON_WARNING, 'warning', 1),
(Test.CONDITION_ON_WARNING, 'failure', 1),
(Test.CONDITION_ON_FAILURE, 'pending', 0),
(Test.CONDITION_ON_FAILURE, 'success', 0),
(Test.CONDITION_ON_FAILURE, 'warning', 0),
(Test.CONDITION_ON_FAILURE, 'failure', 1),
)
for case in cases:
cond, state, n = case
self._configure_test(url, 'super test',
Test.RECIPIENT_SUBMITTER, cond)
self._post_result(url, 'super test', state)
self.assertEqual(len(mail.outbox), n,
"cond %d, '%s', %d mail" % (cond, state, n))
mail.outbox = []
def testMailSubject(self):
sub_tests = [
......
......@@ -413,9 +413,14 @@ class ResultMixin(object):
if instance.state == TestState.STATE_PENDING:
to = []
if (instance.test.mail_condition == Test.CONDITION_ON_FAILURE and
instance.state not in (TestState.STATE_WARNING,
TestState.STATE_FAILURE)):
elif (instance.test.mail_condition ==
Test.CONDITION_ON_WARNING and
instance.state not in (TestState.STATE_WARNING,
TestState.STATE_FAILURE)):
to = []
elif (instance.test.mail_condition == Test.CONDITION_ON_FAILURE and
instance.state != TestState.STATE_FAILURE):
to = []
if to:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment