[PATCH v3 3/9] models: Modify behavior of Series.received_all

Stephen Finucane stephen at that.guru
Wed Feb 8 09:12:38 AEDT 2017


At the moment, Series.received_all is only true is the number of patches
received exactly matches the expected number of patches. However, there
are cases where there may in fact be more patches in the final series
than expected. For example, one could send patches with a subject of
'PATCH 5/4' in-reply-to an original four patch series. The parser
handles this correctly, so the 'received_all' property should too.

We still need to support patterns like '5/n', which are in use and do
not appear to be supported since 'c21b305'. This can be done at a later
stage.

Signed-off-by: Stephen Finucane <stephen at that.guru>
---
 .gitignore                                     |   6 +-
 patchwork/models.py                            |   2 +-
 patchwork/tests/series/base-extra-patches.mbox | 182 +++++++++++++++++++++++++
 patchwork/tests/series/base-incomplete.mbox    |  70 ++++++++++
 patchwork/tests/test_series.py                 |  65 ++++++++-
 5 files changed, 320 insertions(+), 5 deletions(-)
 create mode 100644 patchwork/tests/series/base-extra-patches.mbox
 create mode 100644 patchwork/tests/series/base-incomplete.mbox

diff --git a/.gitignore b/.gitignore
index fd52c8c..d295c3c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,9 +15,9 @@ TAGS
 /series
 
 # patch files
-*.patch
-*.diff
-*.mbox
+/*.patch
+/*.diff
+/*.mbox
 
 # cscope files
 cscope.*
diff --git a/patchwork/models.py b/patchwork/models.py
index 659414a..cf363f0 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -579,7 +579,7 @@ class Series(models.Model):
 
     @property
     def received_all(self):
-        return self.total == self.received_total
+        return self.total <= self.received_total
 
     def add_cover_letter(self, cover):
         """Add a cover letter to the series.
diff --git a/patchwork/tests/series/base-extra-patches.mbox b/patchwork/tests/series/base-extra-patches.mbox
new file mode 100644
index 0000000..fd6ac1f
--- /dev/null
+++ b/patchwork/tests/series/base-extra-patches.mbox
@@ -0,0 +1,182 @@
+From stephenfinucane at gmail.com Sun Sep 11 23:22:13 2016
+Return-Path: <stephenfinucane at gmail.com>
+From: Stephen Finucane <stephenfinucane at gmail.com>
+To: stephenfinucane at hotmail.com
+Subject: [PATCH 0/2] A sample series
+Date: Sun, 11 Sep 2016 23:22:02 +0100
+Message-ID: <1473632524-8585-1-git-send-email-stephenfinucane at gmail.com>
+X-Mailer: git-send-email 2.7.4
+MIME-Version: 1.0
+Content-Type: text/plain
+Content-Length: 395
+Lines: 18
+
+From: Stephen Finucane <stephenfinucane at hotmail.com>
+
+This is a sample cover letter. It doesn't really contribute to the
+conversation, but I added it anway.
+
+Stephen Finucane (2):
+  test: Add some lorem ipsum
+  test: Convert to Markdown
+
+ test.md  | 8 ++++++++
+ test.txt | 1 -
+ 2 files changed, 8 insertions(+), 1 deletion(-)
+ create mode 100644 test.md
+ delete mode 100644 test.txt
+
+-- 
+2.7.4
+
+
+From stephenfinucane at gmail.com Sun Sep 11 23:22:13 2016
+Return-Path: <stephenfinucane at gmail.com>
+From: Stephen Finucane <stephenfinucane at gmail.com>
+To: stephenfinucane at hotmail.com
+Subject: [PATCH 1/2] test: Add some lorem ipsum
+Date: Sun, 11 Sep 2016 23:22:03 +0100
+Message-ID: <1473632524-8585-2-git-send-email-stephenfinucane at gmail.com>
+X-Mailer: git-send-email 2.7.4
+In-Reply-To: <1473632524-8585-1-git-send-email-stephenfinucane at gmail.com>
+References: <1473632524-8585-1-git-send-email-stephenfinucane at gmail.com>
+MIME-Version: 1.0
+Content-Type: text/plain
+Content-Length: 670
+Lines: 22
+
+From: Stephen Finucane <stephenfinucane at hotmail.com>
+
+---
+ test.txt | 7 +++++++
+ 1 file changed, 7 insertions(+)
+
+diff --git a/test.txt b/test.txt
+index f75ba05..a6c61c0 100644
+--- a/test.txt
++++ b/test.txt
+@@ -1 +1,8 @@
+ Hello, world.
++
++Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras eget eleifend
++augue. Nullam at metus venenatis, laoreet neque nec, convallis mauris.
++Pellentesque aliquam at nisi et laoreet. Duis non nisl venenatis, rhoncus risus
++id, elementum felis. In hac habitasse platea dictumst. Nam sit amet maximus
++eros. Nam quis ligula ut tortor egestas bibendum. Nunc sed purus sit amet
++tellus commodo bibendum ut vel dolor.
+-- 
+2.7.4
+
+
+From stephenfinucane at gmail.com Sun Sep 11 23:22:16 2016
+Return-Path: <stephenfinucane at gmail.com>
+From: Stephen Finucane <stephenfinucane at gmail.com>
+To: stephenfinucane at hotmail.com
+Subject: [PATCH 2/2] test: Convert to Markdown
+Date: Sun, 11 Sep 2016 23:22:04 +0100
+Message-ID: <1473632524-8585-3-git-send-email-stephenfinucane at gmail.com>
+X-Mailer: git-send-email 2.7.4
+In-Reply-To: <1473632524-8585-1-git-send-email-stephenfinucane at gmail.com>
+References: <1473632524-8585-1-git-send-email-stephenfinucane at gmail.com>
+MIME-Version: 1.0
+Content-Type: text/plain
+Content-Length: 1345
+Lines: 40
+
+From: Stephen Finucane <stephenfinucane at hotmail.com>
+
+---
+ test.md  | 8 ++++++++
+ test.txt | 8 --------
+ 2 files changed, 8 insertions(+), 8 deletions(-)
+ create mode 100644 test.md
+ delete mode 100644 test.txt
+
+diff --git a/test.md b/test.md
+new file mode 100644
+index 0000000..e5ff90e
+--- /dev/null
++++ b/test.md
+@@ -0,0 +1,8 @@
++# Hello, world
++
++Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras eget eleifend
++augue. Nullam at metus venenatis, laoreet neque nec, convallis mauris.
++Pellentesque aliquam at nisi et laoreet. Duis non nisl venenatis, rhoncus risus
++id, elementum felis. In hac habitasse platea dictumst. Nam sit amet maximus
++eros. Nam quis ligula ut tortor egestas bibendum. Nunc sed purus sit amet
++tellus commodo bibendum ut vel dolor.
+diff --git a/test.txt b/test.txt
+deleted file mode 100644
+index a6c61c0..0000000
+--- a/test.txt
++++ /dev/null
+@@ -1,8 +0,0 @@
+-Hello, world.
+-
+-Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras eget eleifend
+-augue. Nullam at metus venenatis, laoreet neque nec, convallis mauris.
+-Pellentesque aliquam at nisi et laoreet. Duis non nisl venenatis, rhoncus risus
+-id, elementum felis. In hac habitasse platea dictumst. Nam sit amet maximus
+-eros. Nam quis ligula ut tortor egestas bibendum. Nunc sed purus sit amet
+-tellus commodo bibendum ut vel dolor.
+-- 
+2.7.4
+
+
+From stephenfinucane at gmail.com Sun Sep 11 23:22:16 2016
+Return-Path: <stephenfinucane at gmail.com>
+From: Stephen Finucane <stephenfinucane at gmail.com>
+To: stephenfinucane at hotmail.com
+Subject: [PATCH 3/2] test: Remove Markdown formatting
+Date: Sun, 11 Sep 2016 23:22:05 +0100
+Message-ID: <1473632524-8585-4-git-send-email-stephenfinucane at gmail.com>
+X-Mailer: git-send-email 2.7.4
+In-Reply-To: <1473632524-8585-1-git-send-email-stephenfinucane at gmail.com>
+References: <1473632524-8585-1-git-send-email-stephenfinucane at gmail.com>
+MIME-Version: 1.0
+Content-Type: text/plain
+Content-Length: 1345
+Lines: 40
+
+From: Stephen Finucane <stephenfinucane at hotmail.com>
+
+---
+ test.md  | 8 --------
+ test.txt | 8 ++++++++
+ 2 files changed, 8 insertions(+), 8 deletions(-)
+ create mode 100644 test.txt
+ delete mode 100644 test.md
+
+diff --git a/test.txt b/test.txt
+new file mode 100644
+index a6c61c0..0000000
+--- /dev/null
++++ a/test.txt
+@@ -1,8 +0,0 @@
++Hello, world.
++
++Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras eget eleifend
++augue. Nullam at metus venenatis, laoreet neque nec, convallis mauris.
++Pellentesque aliquam at nisi et laoreet. Duis non nisl venenatis, rhoncus risus
++id, elementum felis. In hac habitasse platea dictumst. Nam sit amet maximus
++eros. Nam quis ligula ut tortor egestas bibendum. Nunc sed purus sit amet
++tellus commodo bibendum ut vel dolor.
+diff --git a/test.md b/test.md
+deleted file mode 100644
+index 0000000..e5ff90e
+--- a/test.md
++++ /dev/null
+@@ -0,0 +1,8 @@
+-# Hello, world
+-
+-Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras eget eleifend
+-augue. Nullam at metus venenatis, laoreet neque nec, convallis mauris.
+-Pellentesque aliquam at nisi et laoreet. Duis non nisl venenatis, rhoncus risus
+-id, elementum felis. In hac habitasse platea dictumst. Nam sit amet maximus
+-eros. Nam quis ligula ut tortor egestas bibendum. Nunc sed purus sit amet
+-tellus commodo bibendum ut vel dolor.
+-- 
+2.7.4
+
+
diff --git a/patchwork/tests/series/base-incomplete.mbox b/patchwork/tests/series/base-incomplete.mbox
new file mode 100644
index 0000000..d75bf5e
--- /dev/null
+++ b/patchwork/tests/series/base-incomplete.mbox
@@ -0,0 +1,70 @@
+From stephenfinucane at gmail.com Sun Sep 11 23:22:13 2016
+Return-Path: <stephenfinucane at gmail.com>
+From: Stephen Finucane <stephenfinucane at gmail.com>
+To: stephenfinucane at hotmail.com
+Subject: [PATCH 0/2] A sample series
+Date: Sun, 11 Sep 2016 23:22:02 +0100
+Message-ID: <1473632524-8585-1-git-send-email-stephenfinucane at gmail.com>
+X-Mailer: git-send-email 2.7.4
+MIME-Version: 1.0
+Content-Type: text/plain
+Content-Length: 395
+Lines: 18
+
+From: Stephen Finucane <stephenfinucane at hotmail.com>
+
+This is a sample cover letter. It doesn't really contribute to the
+conversation, but I added it anway.
+
+Stephen Finucane (2):
+  test: Add some lorem ipsum
+  test: Convert to Markdown
+
+ test.md  | 8 ++++++++
+ test.txt | 1 -
+ 2 files changed, 8 insertions(+), 1 deletion(-)
+ create mode 100644 test.md
+ delete mode 100644 test.txt
+
+-- 
+2.7.4
+
+
+From stephenfinucane at gmail.com Sun Sep 11 23:22:13 2016
+Return-Path: <stephenfinucane at gmail.com>
+From: Stephen Finucane <stephenfinucane at gmail.com>
+To: stephenfinucane at hotmail.com
+Subject: [PATCH 1/2] test: Add some lorem ipsum
+Date: Sun, 11 Sep 2016 23:22:03 +0100
+Message-ID: <1473632524-8585-2-git-send-email-stephenfinucane at gmail.com>
+X-Mailer: git-send-email 2.7.4
+In-Reply-To: <1473632524-8585-1-git-send-email-stephenfinucane at gmail.com>
+References: <1473632524-8585-1-git-send-email-stephenfinucane at gmail.com>
+MIME-Version: 1.0
+Content-Type: text/plain
+Content-Length: 670
+Lines: 22
+
+From: Stephen Finucane <stephenfinucane at hotmail.com>
+
+---
+ test.txt | 7 +++++++
+ 1 file changed, 7 insertions(+)
+
+diff --git a/test.txt b/test.txt
+index f75ba05..a6c61c0 100644
+--- a/test.txt
++++ b/test.txt
+@@ -1 +1,8 @@
+ Hello, world.
++
++Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras eget eleifend
++augue. Nullam at metus venenatis, laoreet neque nec, convallis mauris.
++Pellentesque aliquam at nisi et laoreet. Duis non nisl venenatis, rhoncus risus
++id, elementum felis. In hac habitasse platea dictumst. Nam sit amet maximus
++eros. Nam quis ligula ut tortor egestas bibendum. Nunc sed purus sit amet
++tellus commodo bibendum ut vel dolor.
+-- 
+2.7.4
+
+
diff --git a/patchwork/tests/test_series.py b/patchwork/tests/test_series.py
index 7377d91..d2514c6 100644
--- a/patchwork/tests/test_series.py
+++ b/patchwork/tests/test_series.py
@@ -369,12 +369,75 @@ class RevisedSeriesTest(_BaseTestCase):
                 - [PATCH v2 2/2] test: Convert to Markdown
 
         """
-        covers, patches, _ = self._parse_mbox(
+        _, patches, _ = self._parse_mbox(
             'bugs-nocover.mbox', [0, 4, 0])
 
         self.assertSerialized(patches, [2, 2])
 
 
+class SeriesTotalTest(_BaseTestCase):
+
+    def test_incomplete(self):
+        """Series received with patches missing.
+
+        Parse a series where not all patches were received.
+
+        Input:
+
+          - [PATCH 0/2] A sample series
+            - [PATCH 1/2] test: Add some lorem ipsum
+        """
+        covers, patches, _ = self._parse_mbox(
+            'base-incomplete.mbox', [1, 1, 0])
+
+        self.assertSerialized(patches, [1])
+        self.assertSerialized(covers, [1])
+
+        series = patches[0].latest_series
+        self.assertFalse(series.received_all)
+
+    def test_complete(self):
+        """Series received with expected number of patches.
+
+        Parse a series where all patches are received as expected.
+
+        Input:
+
+          - [PATCH 0/2] A sample series
+            - [PATCH 1/2] test: Add some lorem ipsum
+            - [PATCH 2/2] test: Convert to Markdown
+        """
+        covers, patches, _ = self._parse_mbox(
+            'base-cover-letter.mbox', [1, 2, 0])
+
+        self.assertSerialized(covers, [1])
+        self.assertSerialized(patches, [2])
+
+        series = patches[0].latest_series
+        self.assertTrue(series.received_all)
+
+    def test_extra_patches(self):
+        """Series received with additional patches.
+
+        Parse a series where an additional patch was later sent.
+
+        Input:
+
+          - [PATCH 0/2] A sample series
+            - [PATCH 1/2] test: Add some lorem ipsum
+            - [PATCH 2/2] test: Convert to Markdown
+            - [PATCH 3/n] test: Remove Markdown formatting
+        """
+        covers, patches, _ = self._parse_mbox(
+            'base-extra-patches.mbox', [1, 3, 0])
+
+        self.assertSerialized(covers, [1])
+        self.assertSerialized(patches, [3])
+
+        series = patches[0].latest_series
+        self.assertTrue(series.received_all)
+
+
 class SeriesNameTestCase(TestCase):
 
     def setUp(self):
-- 
2.9.3



More information about the Patchwork mailing list