From patchwork Fri Apr 27 15:43:01 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dirk Wallenstein X-Patchwork-Id: 155529 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ozlabs.org (localhost [IPv6:::1]) by ozlabs.org (Postfix) with ESMTP id 23746B6FE0 for ; Sat, 28 Apr 2012 01:43:23 +1000 (EST) Received: from mailout04.t-online.de (mailout04.t-online.de [194.25.134.18]) by ozlabs.org (Postfix) with ESMTP id A46E8B6F6E for ; Sat, 28 Apr 2012 01:43:15 +1000 (EST) Received: from fwd04.aul.t-online.de (fwd04.aul.t-online.de ) by mailout04.t-online.de with smtp id 1SNnKB-0006t9-TK; Fri, 27 Apr 2012 17:43:11 +0200 Received: from localhost (rIJFz2ZQQhvrnq3ZD6CMGjp-zzeHvNUZ+nxr1hbmUmVgsGHs+EshP4gkNPDPtEZgeX@[109.91.88.236]) by fwd04.t-online.de with esmtp id 1SNnK5-1acESG0; Fri, 27 Apr 2012 17:43:05 +0200 Date: Fri, 27 Apr 2012 17:43:01 +0200 From: Dirk Wallenstein To: Jeremy Kerr Subject: [PATCH] tests: Add tests for explicit delegate and state requests Message-ID: <20120427154301.GA29856@bottich> References: <1296046625-25263-1-git-send-email-halsmit@t-online.de> <1296054749-13453-1-git-send-email-halsmit@t-online.de> <20120424063329.D101E20024F@gemini.denx.de> <20120424111515.GA17273@bottich> <20120426124905.722C8200246@gemini.denx.de> <20120426125351.GA19981@bottich> <4F995890.1000002@ozlabs.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <4F995890.1000002@ozlabs.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-ID: rIJFz2ZQQhvrnq3ZD6CMGjp-zzeHvNUZ+nxr1hbmUmVgsGHs+EshP4gkNPDPtEZgeX X-TOI-MSGID: 02f34f4b-18c1-490a-9a3e-11dfd36fe976 Cc: patchwork@lists.ozlabs.org X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Signed-off-by: Dirk Wallenstein --- 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@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()