Commit 08281810 authored by Arkadiusz Hiler's avatar Arkadiusz Hiler

events: Add new-test-result event

The event is logged when patchwork receives new test result for series
revision or for a patch.
Signed-off-by: default avatarArkadiusz Hiler <arkadiusz.hiler@intel.com>
parent bfcf21a3
Pipeline #95766 passed with stage
in 1 minute and 54 seconds
......@@ -258,6 +258,12 @@ two events are possible:
patch state change, either automatic or manually performed by an authorized
user, who will be identified by its patchwork-user id.
- **new-test-result**: This event corresponds to patchwork receiving a new test
result. ``parameters`` contain test result ``state`` and ``test`` name. Then,
the rest depends whether the result belongs to a patch or a series revision.
For patch it has ``patch_date``, and for series ``revision`` and
``revision_completed`` date.
Series
~~~~~~
......
......@@ -9,4 +9,7 @@
<object pk="3" model="patchwork.event">
<field type="CharField" name="name">pull-request-new</field>
</object>
<object pk="4" model="patchwork.event">
<field type="CharField" name="name">new-test-result</field>
</object>
</django-objects>
......@@ -494,6 +494,11 @@ class TestState:
s2i = {s: i for i, s in cls.STATE_CHOICES}
return s2i[s]
@classmethod
def to_string(cls, i):
i2s = {i: s for i, s in cls.STATE_CHOICES}
return i2s[i]
# This Model represents the "top level" Series, an object that doesn't change
# with the various versions of patches sent to the mailing list.
......@@ -811,6 +816,9 @@ class Test(models.Model):
return self.name
new_test_result = django.dispatch.Signal(providing_args=["result"])
class TestResult(models.Model):
test = models.ForeignKey(Test, on_delete=models.CASCADE)
......@@ -830,6 +838,10 @@ class TestResult(models.Model):
class Meta:
unique_together = [('test', 'revision'), ('test', 'patch')]
def save(self, *args, **kwargs):
new_test_result.send(sender=self.__class__, result=self)
super(TestResult, self).save(*args, **kwargs)
class EmailConfirmation(models.Model):
validity = datetime.timedelta(days=settings.CONFIRMATION_VALIDITY_DAYS)
......@@ -1060,4 +1072,31 @@ def _on_revision_complete(sender, revision, **kwargs):
log.save()
def _on_test_result(sender, result, **kwargs):
revision = result.revision
patch = result.patch
if revision:
series = revision.series
user = series.submitter.user
params = {'revision': revision.version,
'revision_completed': revision.completed.isoformat()}
else:
series = None
user = patch.submitter.user
params = {'patch_date': patch.date.isoformat()}
params['state'] = TestState.to_string(result.state)
params['test'] = result.test.name
new_result = Event.objects.get(name='new-test-result')
log = EventLog(event=new_result,
series=series,
patch=patch,
user=user,
parameters=params)
log.save()
series_revision_complete.connect(_on_revision_complete)
new_test_result.connect(_on_test_result)
......@@ -35,7 +35,7 @@ from patchwork.tests.test_user import TestUser
from patchwork.tests.utils import TestSeries, read_mail
from patchwork.models import (
Series, Patch, SeriesRevision, Test, TestResult, TestState, State,
Project, Person
Project, Person, EventLog
)
from patchwork.serializers import SeriesSerializer
......@@ -537,6 +537,62 @@ class MsgidsLookupTest(APITestBase):
self.assertEqual(results[0]['revision_ids'], [self.revision.version])
class TestResultEvent(APITestBase):
result_url = 'http://example.org/logs/foo.txt'
result_summary = 'This contains a summary of the test results'
def testPatchResultCreatesEvent(self):
patch_url = '/patches/%(patch_id)s/test-results/'
events_pre = set(EventLog.objects.all())
(r, _) = self.post_json(patch_url, data={
'test_name': 'test/bar',
'state': 'pending',
}, user=self.maintainer)
self.assertEqual(r.status_code, 201)
events_post = set(EventLog.objects.all())
events_new = events_post - events_pre
self.assertEqual(len(events_new), 1)
event = events_new.pop()
patch_date = dateutil.parser.parse(event.parameters['patch_date'])
self.assertEquals(event.series, None)
self.assertEquals(event.user, self.patch.submitter.user)
self.assertEquals(event.parameters['test'], 'test/bar')
self.assertEquals(event.parameters['state'], 'pending')
self.assertEquals(event.patch, self.patch)
self.assertEquals(patch_date, self.patch.date)
def testRevisionResultCreatesEvent(self):
rev_url = '/series/%(series_id)s/revisions/%(version)s/test-results/'
events_pre = set(EventLog.objects.all())
(r, _) = self.post_json(rev_url, data={
'test_name': 'test/bar',
'state': 'pending',
}, user=self.maintainer)
self.assertEqual(r.status_code, 201)
events_post = set(EventLog.objects.all())
events_new = events_post - events_pre
self.assertEqual(len(events_new), 1)
event = events_new.pop()
revision = self.series.latest_revision()
revision_completed = dateutil.parser.parse(
event.parameters['revision_completed'])
self.assertEquals(event.series, self.series)
self.assertEquals(event.user, self.series.submitter.user)
self.assertEquals(event.parameters['test'], 'test/bar')
self.assertEquals(event.parameters['state'], 'pending')
self.assertEquals(event.parameters['revision'], revision.version)
self.assertEquals(revision_completed, revision.completed)
class TestResultTest(APITestBase):
rev_url = '/series/%(series_id)s/revisions/%(version)s/test-results/'
patch_url = '/patches/%(patch_id)s/test-results/'
......
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