[PATCH] tests: Add tests for explicit delegate and state requests
Dirk Wallenstein
halsmit at t-online.de
Sat Apr 28 01:43:01 EST 2012
Signed-off-by: Dirk Wallenstein <halsmit at 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(-)
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 at 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 at 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 at 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 at 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()
--
1.7.5.4
More information about the Patchwork
mailing list