Patchwork tests: Add tests for explicit delegate and state requests

login
register
mail settings
Submitter Dirk Wallenstein
Date April 27, 2012, 3:43 p.m.
Message ID <20120427154301.GA29856@bottich>
Download mbox | patch
Permalink /patch/155529/
State Superseded
Headers show

Comments

Dirk Wallenstein - April 27, 2012, 3:43 p.m.
Signed-off-by: Dirk Wallenstein <halsmit@t-online.de>
---
These tests succeed against master.  I'd say it works. 

 apps/patchwork/tests/patchparser.py |   83 ++++++++++++++++++++++++++++++++++-
 1 files changed, 81 insertions(+), 2 deletions(-)
Dirk Wallenstein - April 29, 2012, 12:51 p.m.
On Fri, Apr 27, 2012 at 05:43:01PM +0200, Dirk Wallenstein wrote:
> Signed-off-by: Dirk Wallenstein <halsmit@t-online.de>
> ---
> These tests succeed against master.  I'd say it works. 
> 
>  apps/patchwork/tests/patchparser.py |   83 ++++++++++++++++++++++++++++++++++-
>  1 files changed, 81 insertions(+), 2 deletions(-)

Will send a new version in a series.

Patch

diff --git a/apps/patchwork/tests/patchparser.py b/apps/patchwork/tests/patchparser.py
index 06b4e54..8a47ff5 100644
--- a/apps/patchwork/tests/patchparser.py
+++ b/apps/patchwork/tests/patchparser.py
@@ -20,8 +20,8 @@ 
 import unittest
 import os
 from email import message_from_string
-from patchwork.models import Project, Person, Patch, Comment
-from patchwork.tests.utils import read_patch, read_mail, create_email, defaults
+from patchwork.models import Project, Person, Patch, Comment, State
+from patchwork.tests.utils import read_patch, read_mail, create_email, defaults, create_user
 
 try:
     from email.mime.text import MIMEText
@@ -398,3 +398,82 @@  class CVSFormatPatchTest(MBoxPatchTest):
         self.assertTrue(patch is not None)
         self.assertTrue(comment is not None)
         self.assertTrue(patch.content.startswith('Index'))
+
+class DelegationTest(unittest.TestCase):
+    patch_filename = '0001-add-line.patch'
+    msgid = '<1@example.com>'
+
+    def setUp(self):
+        self.patch = read_patch(self.patch_filename)
+        self.user = create_user()
+        self.p1 = Project(linkname = 'test-project-1', name = 'Project 1',
+                listid = '1.example.com', listemail='1@example.com')
+        self.p1.save()
+
+    def get_email(self):
+        email = create_email(self.patch)
+        del email['List-ID']
+        email['List-ID'] = '<' + self.p1.listid + '>'
+        email['Message-Id'] = self.msgid
+        return email
+
+    def testDelegate(self):
+        email = self.get_email()
+        email['X-Patchwork-Delegate'] = self.user.email
+        parse_mail(email)
+        self.assertEquals(Patch.objects.filter(project=self.p1).count(), 1)
+        self.assertEquals(Patch.objects.get(pk=1).delegate, self.user)
+
+    def testNoDelegate(self):
+        email = self.get_email()
+        parse_mail(email)
+        self.assertEquals(Patch.objects.filter(project=self.p1).count(), 1)
+        self.assertEquals(Patch.objects.get(pk=1).delegate, None)
+
+    def tearDown(self):
+        self.p1.delete()
+        self.user.delete()
+
+class StateTest(unittest.TestCase):
+    patch_filename = '0001-add-line.patch'
+    msgid = '<1@example.com>'
+
+    def setUp(self):
+        self.patch = read_patch(self.patch_filename)
+        self.user = create_user()
+        self.p1 = Project(linkname = 'test-project-1', name = 'Project 1',
+                listid = '1.example.com', listemail='1@example.com')
+        self.p1.save()
+        self.default_state = State.objects.get(pk=1)
+        self.nondefault_state = State.objects.get(pk=2)
+
+    def get_email(self):
+        email = create_email(self.patch)
+        del email['List-ID']
+        email['List-ID'] = '<' + self.p1.listid + '>'
+        email['Message-Id'] = self.msgid
+        return email
+
+    def testExplicitNonDefaultStateRequest(self):
+        email = self.get_email()
+        email['X-Patchwork-State'] = self.nondefault_state.name
+        parse_mail(email)
+        self.assertEquals(Patch.objects.filter(project=self.p1).count(), 1)
+        self.assertEquals(Patch.objects.get(pk=1).state, self.nondefault_state)
+
+    def testExplicitDefaultStateRequest(self):
+        email = self.get_email()
+        email['X-Patchwork-State'] = self.default_state.name
+        parse_mail(email)
+        self.assertEquals(Patch.objects.filter(project=self.p1).count(), 1)
+        self.assertEquals(Patch.objects.get(pk=1).state, self.default_state)
+
+    def testImplicitDefaultStateRequest(self):
+        email = self.get_email()
+        parse_mail(email)
+        self.assertEquals(Patch.objects.filter(project=self.p1).count(), 1)
+        self.assertEquals(Patch.objects.get(pk=1).state, self.default_state)
+
+    def tearDown(self):
+        self.p1.delete()
+        self.user.delete()