From 8de3e85466899d83adca7bafe9057a821458c5b4 Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Thu, 12 Feb 2009 22:01:09 +1100 Subject: [PATCH] [mbox] Put ACKs before '---' updates Update the Patch's mbox() function to split into '--- update' sections, allowing us to add Acks and Signoffs in the right place Add tests too. Signed-off-by: Jeremy Kerr --- apps/patchwork/models.py | 13 +++++ apps/patchwork/tests/__init__.py | 4 +- apps/patchwork/tests/mboxviews.py | 79 +++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 apps/patchwork/tests/mboxviews.py diff --git a/apps/patchwork/models.py b/apps/patchwork/models.py index a672f9a..cfc875f 100644 --- a/apps/patchwork/models.py +++ b/apps/patchwork/models.py @@ -227,6 +227,8 @@ class Patch(models.Model): return str.strip('-') + '.patch' def mbox(self): + postscript_re = re.compile('\n-{2,3} ?\n') + comment = None try: comment = Comment.objects.get(patch = self, msgid = self.msgid) @@ -237,6 +239,14 @@ class Patch(models.Model): if comment: body = comment.content.strip() + "\n" + parts = postscript_re.split(body, 1) + if len(parts) == 2: + (body, postscript) = parts + body = body.strip() + "\n" + postscript = postscript.strip() + "\n" + else: + postscript = '' + responses = False for comment in Comment.objects.filter(patch = self) \ .exclude(msgid = self.msgid): @@ -245,6 +255,9 @@ class Patch(models.Model): if body: body += '\n' + if postscript: + body += '---\n' + postscript.strip() + '\n' + body += self.content mail = PatchMbox(body) diff --git a/apps/patchwork/tests/__init__.py b/apps/patchwork/tests/__init__.py index 94d629b..044c8ba 100644 --- a/apps/patchwork/tests/__init__.py +++ b/apps/patchwork/tests/__init__.py @@ -18,9 +18,9 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import unittest -from patchwork.tests import patchparser, encodings, bundles +from patchwork.tests import patchparser, encodings, bundles, mboxviews -modules = [patchparser, encodings, bundles] +modules = [patchparser, encodings, bundles, mboxviews] def suite(): suite = unittest.TestSuite() diff --git a/apps/patchwork/tests/mboxviews.py b/apps/patchwork/tests/mboxviews.py new file mode 100644 index 0000000..a7729d8 --- /dev/null +++ b/apps/patchwork/tests/mboxviews.py @@ -0,0 +1,79 @@ +# Patchwork - automated patch tracking system +# Copyright (C) 2009 Jeremy Kerr +# +# This file is part of the Patchwork package. +# +# Patchwork is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# Patchwork is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Patchwork; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +import unittest +from django.test import TestCase +from django.test.client import Client +from patchwork.models import Patch, Comment, Person +from patchwork.tests.utils import defaults, create_user, find_in_context + +class MboxPatchResponseTest(TestCase): + """ Test that the mbox view appends the Acked-by from a patch comment """ + def setUp(self): + defaults.project.save() + + self.person = defaults.patch_author_person + self.person.save() + + self.patch = Patch(project = defaults.project, + msgid = 'p1', name = 'testpatch', + submitter = self.person, content = '') + self.patch.save() + comment = Comment(patch = self.patch, msgid = 'p1', + submitter = self.person, + content = 'comment 1 text\nAcked-by: 1\n') + comment.save() + + comment = Comment(patch = self.patch, msgid = 'p2', + submitter = self.person, + content = 'comment 2 text\nAcked-by: 2\n') + comment.save() + + def testPatchResponse(self): + response = self.client.get('/patch/%d/mbox/' % self.patch.id) + self.assertContains(response, + 'Acked-by: 1\nAcked-by: 2\n') + +class MboxPatchSplitResponseTest(TestCase): + """ Test that the mbox view appends the Acked-by from a patch comment, + and places it before an '---' update line. """ + def setUp(self): + defaults.project.save() + + self.person = defaults.patch_author_person + self.person.save() + + self.patch = Patch(project = defaults.project, + msgid = 'p1', name = 'testpatch', + submitter = self.person, content = '') + self.patch.save() + comment = Comment(patch = self.patch, msgid = 'p1', + submitter = self.person, + content = 'comment 1 text\nAcked-by: 1\n---\nupdate\n') + comment.save() + + comment = Comment(patch = self.patch, msgid = 'p2', + submitter = self.person, + content = 'comment 2 text\nAcked-by: 2\n') + comment.save() + + def testPatchResponse(self): + response = self.client.get('/patch/%d/mbox/' % self.patch.id) + self.assertContains(response, + 'Acked-by: 1\nAcked-by: 2\n') -- 2.39.2