diff mbox

[6/7] series: Add a 'new-series-revision' event

Message ID 1445380847-22838-7-git-send-email-damien.lespiau@intel.com
State Rejected
Headers show

Commit Message

Damien Lespiau Oct. 20, 2015, 10:40 p.m. UTC
We create a new log entry when a new series revision appears.

The series_revision_complete event only fires when the series/revision
is fully complete, eg., the git send-email series has been fully
processed. That behaviour is tested, making sure an incomplete series
doesn't appear in the SeriesLog table.

v2: Rebase on top of SERIES_DEFAULT_NAME changes

Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
---
 patchwork/fixtures/default_events.xml |  6 +++++
 patchwork/models.py                   |  8 ++++++
 patchwork/tests/test_bundles.py       |  2 +-
 patchwork/tests/test_encodings.py     |  4 +--
 patchwork/tests/test_expiry.py        |  2 +-
 patchwork/tests/test_list.py          |  2 +-
 patchwork/tests/test_mboxviews.py     | 12 ++++-----
 patchwork/tests/test_notifications.py |  4 +--
 patchwork/tests/test_patchparser.py   | 10 +++----
 patchwork/tests/test_series.py        | 51 ++++++++++++++++++++++++++++++++---
 patchwork/tests/test_tags.py          |  4 +--
 patchwork/tests/test_updates.py       |  2 +-
 patchwork/tests/test_xmlrpc.py        |  2 +-
 13 files changed, 83 insertions(+), 26 deletions(-)
 create mode 100644 patchwork/fixtures/default_events.xml
diff mbox

Patch

diff --git a/patchwork/fixtures/default_events.xml b/patchwork/fixtures/default_events.xml
new file mode 100644
index 0000000..c23ce3b
--- /dev/null
+++ b/patchwork/fixtures/default_events.xml
@@ -0,0 +1,6 @@ 
+<?xml version="1.0" encoding="utf-8"?>
+<django-objects version="1.0">
+  <object pk="1" model="patchwork.event">
+    <field type="CharField" name="name">series-new-revision</field>
+  </object>
+</django-objects>
diff --git a/patchwork/models.py b/patchwork/models.py
index 28e28bb..31026ff 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -632,3 +632,11 @@  def _patch_change_callback(sender, instance, **kwargs):
     notification.save()
 
 models.signals.pre_save.connect(_patch_change_callback, sender = Patch)
+
+def _on_revision_complete(sender, revision, **kwargs):
+    new_revision = Event.objects.get(name='series-new-revision')
+    log = EventLog(event=new_revision, series=revision.series,
+                   user=revision.series.submitter.user)
+    log.save()
+
+series_revision_complete.connect(_on_revision_complete)
diff --git a/patchwork/tests/test_bundles.py b/patchwork/tests/test_bundles.py
index a9ee8dd..9d08be5 100644
--- a/patchwork/tests/test_bundles.py
+++ b/patchwork/tests/test_bundles.py
@@ -54,7 +54,7 @@  class BundleListTest(TestCase):
         self.user.delete()
 
 class BundleTestBase(TestCase):
-    fixtures = ['default_states']
+    fixtures = ['default_states', 'default_events']
     def setUp(self, patch_count=3):
         patch_names = ['testpatch%d' % (i) for i in range(1, patch_count+1)]
         self.user = create_user()
diff --git a/patchwork/tests/test_encodings.py b/patchwork/tests/test_encodings.py
index b639078..d12c6e3 100644
--- a/patchwork/tests/test_encodings.py
+++ b/patchwork/tests/test_encodings.py
@@ -26,7 +26,7 @@  from django.test import TestCase
 from django.test.client import Client
 
 class UTF8PatchViewTest(TestCase):
-    fixtures = ['default_states']
+    fixtures = ['default_states', 'default_events']
     patch_filename = '0002-utf-8.patch'
     patch_encoding = 'utf-8'
 
@@ -64,7 +64,7 @@  class UTF8PatchViewTest(TestCase):
         defaults.project.delete()
 
 class UTF8HeaderPatchViewTest(UTF8PatchViewTest):
-    fixtures = ['default_states']
+    fixtures = ['default_states', 'default_events']
     patch_filename = '0002-utf-8.patch'
     patch_encoding = 'utf-8'
     patch_author_name = u'P\xe4tch Author'
diff --git a/patchwork/tests/test_expiry.py b/patchwork/tests/test_expiry.py
index ca22970..0fdc77b 100644
--- a/patchwork/tests/test_expiry.py
+++ b/patchwork/tests/test_expiry.py
@@ -26,7 +26,7 @@  from patchwork.tests.utils import create_user, defaults
 from patchwork.utils import do_expiry
 
 class TestRegistrationExpiry(TestCase):
-    fixtures = ['default_states']
+    fixtures = ['default_states', 'default_events']
 
     def register(self, date):
         user = create_user()
diff --git a/patchwork/tests/test_list.py b/patchwork/tests/test_list.py
index f440e3e..7a9f88b 100644
--- a/patchwork/tests/test_list.py
+++ b/patchwork/tests/test_list.py
@@ -42,7 +42,7 @@  class EmptyPatchListTest(TestCase):
         self.assertNotContains(response, 'tbody')
 
 class PatchOrderTest(TestCase):
-    fixtures = ['default_states']
+    fixtures = ['default_states', 'default_events']
 
     d = datetime.datetime
     patchmeta = [
diff --git a/patchwork/tests/test_mboxviews.py b/patchwork/tests/test_mboxviews.py
index fbea322..e390cb6 100644
--- a/patchwork/tests/test_mboxviews.py
+++ b/patchwork/tests/test_mboxviews.py
@@ -29,7 +29,7 @@  from patchwork.models import Patch, Comment, Person
 from patchwork.tests.utils import defaults, create_user, find_in_context
 
 class MboxPatchResponseTest(TestCase):
-    fixtures = ['default_states']
+    fixtures = ['default_states', 'default_events']
 
     """ Test that the mbox view appends the Acked-by from a patch comment """
     def setUp(self):
@@ -58,7 +58,7 @@  class MboxPatchResponseTest(TestCase):
                 'Acked-by: 1\nAcked-by: 2\n')
 
 class MboxPatchSplitResponseTest(TestCase):
-    fixtures = ['default_states']
+    fixtures = ['default_states', 'default_events']
 
     """ Test that the mbox view appends the Acked-by from a patch comment,
         and places it before an '---' update line. """
@@ -88,7 +88,7 @@  class MboxPatchSplitResponseTest(TestCase):
                 'Acked-by: 1\nAcked-by: 2\n')
 
 class MboxPassThroughHeaderTest(TestCase):
-    fixtures = ['default_states']
+    fixtures = ['default_states', 'default_events']
 
     """ Test that we see 'Cc' and 'To' headers passed through from original
         message to mbox view """
@@ -128,7 +128,7 @@  class MboxPassThroughHeaderTest(TestCase):
         self.assertContains(response, self.date_header)
 
 class MboxBrokenFromHeaderTest(TestCase):
-    fixtures = ['default_states']
+    fixtures = ['default_states', 'default_events']
 
     """ Test that a person with characters outside ASCII in his name do
         produce correct From header. As RFC 2822 state we must retain the
@@ -153,7 +153,7 @@  class MboxBrokenFromHeaderTest(TestCase):
         self.assertContains(response, from_email)
 
 class MboxDateHeaderTest(TestCase):
-    fixtures = ['default_states']
+    fixtures = ['default_states', 'default_events']
 
     """ Test that the date provided in the patch mail view is correct """
 
@@ -191,7 +191,7 @@  class MboxDateHeaderTest(TestCase):
         self.assertEqual(mail_date, date)
 
 class MboxCommentPostcriptUnchangedTest(TestCase):
-    fixtures = ['default_states']
+    fixtures = ['default_states', 'default_events']
 
     """ Test that the mbox view doesn't change the postscript part of a mail.
         There where always a missing blank right after the postscript
diff --git a/patchwork/tests/test_notifications.py b/patchwork/tests/test_notifications.py
index 37adb8d..cbc43f9 100644
--- a/patchwork/tests/test_notifications.py
+++ b/patchwork/tests/test_notifications.py
@@ -26,7 +26,7 @@  from patchwork.tests.utils import defaults
 from patchwork.utils import send_notifications
 
 class PatchNotificationModelTest(TestCase):
-    fixtures = ['default_states']
+    fixtures = ['default_states', 'default_events']
 
     """Tests for the creation & update of the PatchChangeNotification model"""
 
@@ -120,7 +120,7 @@  class PatchNotificationModelTest(TestCase):
         self.assertEqual(PatchChangeNotification.objects.count(), 0)
 
 class PatchNotificationEmailTest(TestCase):
-    fixtures = ['default_states']
+    fixtures = ['default_states', 'default_events']
 
     def setUp(self):
         self.project = defaults.project
diff --git a/patchwork/tests/test_patchparser.py b/patchwork/tests/test_patchparser.py
index 61fdd5a..f266627 100644
--- a/patchwork/tests/test_patchparser.py
+++ b/patchwork/tests/test_patchparser.py
@@ -29,7 +29,7 @@  from patchwork.tests.utils import read_patch, read_mail, create_email, \
 from email.mime.text import MIMEText
 
 class PatchTest(TestCase):
-    fixtures = ['default_states']
+    fixtures = ['default_states', 'default_events']
     default_sender = defaults.sender
     default_subject = defaults.subject
     project = defaults.project
@@ -262,7 +262,7 @@  class MultipleProjectPatchTest(TestCase):
     """ Test that patches sent to multiple patchwork projects are
         handled correctly """
 
-    fixtures = ['default_states']
+    fixtures = ['default_states', 'default_events']
     test_comment = 'Test Comment'
     patch_filename = '0001-add-line.patch'
     msgid = '<1@example.com>'
@@ -484,7 +484,7 @@  class NoNewlineAtEndOfFilePatchTest(MBoxPatchTest):
         self.assertEqual(2, patch.content.count('\ No newline at end of file'))
 
 class DelegateRequestTest(TestCase):
-    fixtures = ['default_states']
+    fixtures = ['default_states', 'default_events']
     patch_filename = '0001-add-line.patch'
     msgid = '<1@example.com>'
     invalid_delegate_email = "nobody"
@@ -530,7 +530,7 @@  class DelegateRequestTest(TestCase):
         self.user.delete()
 
 class MailFromPatchTest(TestCase):
-    fixtures = ['default_states']
+    fixtures = ['default_states', 'default_events']
     patch_filename = '0001-add-line.patch'
     msgid = '<1@example.com>'
 
@@ -638,7 +638,7 @@  class ParseInitialTagsTest(PatchTest):
     test_comment = ('test comment\n\n' +
         'Tested-by: Test User <test@example.com>\n' +
         'Reviewed-by: Test User <test@example.com>\n')
-    fixtures = ['default_tags', 'default_states']
+    fixtures = ['default_tags', 'default_states', 'default_events']
 
     def setUp(self):
         project = defaults.project
diff --git a/patchwork/tests/test_series.py b/patchwork/tests/test_series.py
index 373ef1b..2cb4c02 100644
--- a/patchwork/tests/test_series.py
+++ b/patchwork/tests/test_series.py
@@ -21,7 +21,7 @@  import os
 
 from django.test import TestCase
 from patchwork.models import Patch, Series, SeriesRevision, Project, \
-                             SERIES_DEFAULT_NAME
+                             SERIES_DEFAULT_NAME, EventLog, User, Person
 from patchwork.tests.utils import read_mail
 from patchwork.tests.utils import defaults, read_mail, TestSeries
 
@@ -29,7 +29,7 @@  from patchwork.bin.parsemail import parse_mail, build_references_list, \
                                     clean_series_name
 
 class SeriesTest(TestCase):
-    fixtures = ['default_states']
+    fixtures = ['default_states', 'default_events']
 
     def setUp(self):
         self.assertTrue(self.project is not None)
@@ -75,6 +75,11 @@  class SeriesTest(TestCase):
         patches = Patch.objects.all()
         self.assertEquals(patches.count(), self.n_patches)
 
+        # We are inserting a single series, so the logs should only have one
+        # entry
+        logs = EventLog.objects.all()
+        self.assertEquals(logs.count(), 1)
+
 class GeneratedSeriesTest(SeriesTest):
     project = defaults.project
 
@@ -119,6 +124,7 @@  class SingleMailSeries(IntelGfxTest):
     root_msgid = '<1400748280-26449-1-git-send-email-chris@chris-wilson.co.uk>'
     cover_letter = None
 
+class Series0010(SingleMailSeries):
     def testInsertion(self):
         """A single patch is a series of 1 patch"""
 
@@ -203,7 +209,7 @@  class MultipleMailNoCoverLetterSeries(Series0020):
         self.commonInsertionChecks()
 
 class ReferencesListTest(TestCase):
-    fixtures = ['default_states']
+    fixtures = ['default_states', 'default_events']
 
     def testSingleMail(self):
         series = TestSeries(1, has_cover_letter=False)
@@ -384,7 +390,7 @@  class SinglePatchUpdateTest(GeneratedSeriesTest):
         self._test_internal(3, 3, has_cover_letter=False)
 
 class SinglePatchUpdatesVariousCornerCasesTest(TestCase):
-    fixtures = ['default_states']
+    fixtures = ['default_states', 'default_events']
 
     def testSinglePatchUpdatesNotSerialized(self):
         """ + patch v1
@@ -528,3 +534,40 @@  class FullSeriesUpdateTest(GeneratedSeriesTest):
 
     def testNewSeriesIgnoreCase(self):
         self._test_internal(3, ('Awesome series', 'awesome series (V4)'))
+
+#
+# series-new-revision event tests
+#
+
+class EventLogTest(SingleMailSeries):
+    def setUp(self):
+        # Create a 'chris' User and Person
+        mail = 'chris@chris-wilson.co.uk'
+        self.user = User.objects.create_user('chris', mail, 'securepass')
+        person = Person(email=mail)
+        person.link_to_user(self.user)
+        person.save()
+
+        super(EventLogTest, self).setUp()
+
+    def testNewSeriesSeries(self):
+        entry = EventLog.objects.all()[0]
+        series = Series.objects.all()[0]
+        self.assertEquals(entry.series, series)
+
+    def testNewSeriesUser(self):
+        entry = EventLog.objects.all()[0]
+        self.assertEquals(self.user, entry.user)
+
+class MultipleMailCoverLetterSeriesIncomplete(Series0010):
+    mails = (
+        '0010-multiple-mails-cover-letter.mbox',
+        '0011-multiple-mails-cover-letter.mbox',
+        '0012-multiple-mails-cover-letter.mbox',
+        '0014-multiple-mails-cover-letter.mbox',
+    )
+
+class EventLogIncompleteTest(MultipleMailCoverLetterSeriesIncomplete):
+    def testNoNewSeriesIfIncomplete(self):
+        logs = EventLog.objects.all()
+        self.assertEquals(logs.count(), 0)
diff --git a/patchwork/tests/test_tags.py b/patchwork/tests/test_tags.py
index a1e03f5..0973be6 100644
--- a/patchwork/tests/test_tags.py
+++ b/patchwork/tests/test_tags.py
@@ -31,7 +31,7 @@  class ExtractTagsTest(TestCase):
 
     email = 'test@exmaple.com'
     name_email = 'test name <' + email + '>'
-    fixtures = ['default_tags', 'default_states']
+    fixtures = ['default_tags', 'default_states', 'default_events']
 
     def assertTagsEqual(self, str, acks, reviews, tests):
         counts = extract_tags(str, Tag.objects.all())
@@ -83,7 +83,7 @@  class PatchTagsTest(TransactionTestCase):
     ACK = 1
     REVIEW = 2
     TEST = 3
-    fixtures = ['default_tags', 'default_states']
+    fixtures = ['default_tags', 'default_states', 'default_events']
 
     def assertTagsEqual(self, patch, acks, reviews, tests):
         patch = Patch.objects.get(pk=patch.pk)
diff --git a/patchwork/tests/test_updates.py b/patchwork/tests/test_updates.py
index d2f4126..f664547 100644
--- a/patchwork/tests/test_updates.py
+++ b/patchwork/tests/test_updates.py
@@ -23,7 +23,7 @@  from patchwork.models import Patch, Person, State
 from patchwork.tests.utils import defaults, create_maintainer
 
 class MultipleUpdateTest(TestCase):
-    fixtures = ['default_states']
+    fixtures = ['default_states', 'default_events']
 
     def setUp(self):
         defaults.project.save()
diff --git a/patchwork/tests/test_xmlrpc.py b/patchwork/tests/test_xmlrpc.py
index 1aef03c..9519f1b 100644
--- a/patchwork/tests/test_xmlrpc.py
+++ b/patchwork/tests/test_xmlrpc.py
@@ -28,7 +28,7 @@  from patchwork.tests.utils import defaults
 @unittest.skipUnless(settings.ENABLE_XMLRPC,
         "requires xmlrpc interface (use the ENABLE_XMLRPC setting)")
 class XMLRPCTest(LiveServerTestCase):
-    fixtures = ['default_states']
+    fixtures = ['default_states', 'default_events']
 
     def setUp(self):
         self.url = (self.live_server_url +