From patchwork Thu Jun 23 21:53:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 639929 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rbFgH1ryDz9sDX for ; Fri, 24 Jun 2016 07:57:15 +1000 (AEST) Received: from ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3rbFgH165XzDqmg for ; Fri, 24 Jun 2016 07:57:15 +1000 (AEST) X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lists.ozlabs.org (Postfix) with ESMTP id 3rbFbW32vRzDqlG for ; Fri, 24 Jun 2016 07:53:59 +1000 (AEST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP; 23 Jun 2016 14:53:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,518,1459839600"; d="scan'208";a="834152237" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga003.jf.intel.com with ESMTP; 23 Jun 2016 14:53:55 -0700 Received: from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com [10.237.217.45]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id u5NLrtcF016859; Thu, 23 Jun 2016 22:53:55 +0100 Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id u5NLrteT016968; Thu, 23 Jun 2016 22:53:55 +0100 Received: (from sfinucan@localhost) by sivswdev01.ir.intel.com with id u5NLrsFV016964; Thu, 23 Jun 2016 22:53:54 +0100 From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: =?UTF-8?q?=5BPATCH=2013/25=5D=20tests=3A=20Clean=20up=20=27test=5Fmboxviews=27?= Date: Thu, 23 Jun 2016 22:53:34 +0100 Message-Id: <1466718826-15770-14-git-send-email-stephen.finucane@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1466718826-15770-1-git-send-email-stephen.finucane@intel.com> References: <1466718826-15770-1-git-send-email-stephen.finucane@intel.com> MIME-Version: 1.0 X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.22 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" * Don't use hardcode routes: use the reverse function instead * Make use of 'create_' helper functions * Include every import on its own line * Use underscore_case, rather than camelCase * Rename and regroup some tests to make more sense Signed-off-by: Stephen Finucane Reviewed-by: Andy Doan --- patchwork/tests/test_mboxviews.py | 291 ++++++++++++++----------------------- 1 files changed, 111 insertions(+), 180 deletions(-) diff --git a/patchwork/tests/test_mboxviews.py b/patchwork/tests/test_mboxviews.py index 7c6e9fc..a772c34 100644 --- a/patchwork/tests/test_mboxviews.py +++ b/patchwork/tests/test_mboxviews.py @@ -24,229 +24,160 @@ import dateutil.parser import dateutil.tz import email +from django.core.urlresolvers import reverse from django.test import TestCase -from patchwork.models import Patch, Comment -from patchwork.tests.utils import defaults, create_user +from patchwork.tests.utils import create_comment +from patchwork.tests.utils import create_patch +from patchwork.tests.utils import create_project +from patchwork.tests.utils import create_person +from patchwork.tests.utils import create_user class MboxPatchResponseTest(TestCase): - fixtures = ['default_states'] - - """ 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, diff='', - content='comment 1 text\nAcked-by: 1\n') - self.patch.save() - comment = Comment(submission=self.patch, - msgid='p2', - submitter=self.person, - content='comment 2 text\nAcked-by: 2\n') - comment.save() + """Test that the mbox view appends the Acked-by from a patch comment.""" - 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): fixtures = ['default_states'] - """ 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, diff='', - content='comment 1 text\nAcked-by: 1\n---\nupdate\n') - self.patch.save() - - comment = Comment(submission=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 MboxPassThroughHeaderTest(TestCase): - fixtures = ['default_states'] - - """ Test that we see 'Cc' and 'To' headers passed through from original - message to mbox view """ - - def setUp(self): - defaults.project.save() - self.person = defaults.patch_author_person - self.person.save() - - self.cc_header = 'Cc: CC Person ' - self.to_header = 'To: To Person ' - self.date_header = 'Date: Fri, 7 Jun 2013 15:42:54 +1000' - - self.patch = Patch(project=defaults.project, - msgid='p1', name='testpatch', - submitter=self.person, content='') + project = create_project() + self.person = create_person() + self.patch = create_patch( + project=project, + submitter=self.person, + content='comment 1 text\nAcked-by: 1\n') + self.comment = create_comment( + submission=self.patch, + submitter=self.person, + content='comment 2 text\nAcked-by: 2\n') + + def test_patch_response(self): + response = self.client.get(reverse('patch-mbox', args=[self.patch.id])) + self.assertContains(response, 'Acked-by: 1\nAcked-by: 2\n') - def testCCHeader(self): - self.patch.headers = self.cc_header + '\n' - self.patch.save() - response = self.client.get('/patch/%d/mbox/' % self.patch.id) - self.assertContains(response, self.cc_header) - - def testToHeader(self): - self.patch.headers = self.to_header + '\n' - self.patch.save() - - response = self.client.get('/patch/%d/mbox/' % self.patch.id) - self.assertContains(response, self.to_header) - - def testDateHeader(self): - self.patch.headers = self.date_header + '\n' - self.patch.save() - - response = self.client.get('/patch/%d/mbox/' % self.patch.id) - self.assertContains(response, self.date_header) +class MboxPatchSplitResponseTest(TestCase): + """Test that the mbox view appends the Acked-by from a patch comment, + and places it before an '---' update line.""" -class MboxGeneratedHeaderTest(TestCase): fixtures = ['default_states'] def setUp(self): - defaults.project.save() - self.person = defaults.patch_author_person - self.person.save() - - self.user = create_user() + project = create_project() + self.person = create_person() + self.patch = create_patch( + project=project, + submitter=self.person, + diff='', + content='comment 1 text\nAcked-by: 1\n---\nupdate\n') + self.comment = create_comment( + submission=self.patch, + submitter=self.person, + content='comment 2 text\nAcked-by: 2\n') - self.patch = Patch(project=defaults.project, - msgid='p1', - name='testpatch', - submitter=self.person, - delegate=self.user, - content='') - self.patch.save() + def test_patch_response(self): + response = self.client.get(reverse('patch-mbox', args=[self.patch.id])) + self.assertContains(response, 'Acked-by: 1\nAcked-by: 2\n') - def testPatchworkIdHeader(self): - response = self.client.get('/patch/%d/mbox/' % self.patch.id) - self.assertContains(response, 'X-Patchwork-Id: %d' % self.patch.id) - def testPatchworkDelegateHeader(self): - response = self.client.get('/patch/%d/mbox/' % self.patch.id) - self.assertContains(response, - 'X-Patchwork-Delegate: %s' % self.user.email) +class MboxHeaderTest(TestCase): + """Test the passthrough and generation of various headers.""" -class MboxBrokenFromHeaderTest(TestCase): fixtures = ['default_states'] - """ Test that a person with characters outside ASCII in his name do - produce correct From header. As RFC 2822 state we must retain the - format for the mail while the name part may be coded - in some ways. """ - - def setUp(self): - defaults.project.save() - self.person = defaults.patch_author_person - self.person.name = u'©ool guŷ' - self.person.save() - - self.patch = Patch(project=defaults.project, - msgid='p1', name='testpatch', - submitter=self.person, content='') - - def testFromHeader(self): - self.patch.save() - from_email = '<' + self.person.email + '>' - - response = self.client.get('/patch/%d/mbox/' % self.patch.id) + def test_header_passthrough_cc(self): + """Validate passthrough of 'Cc' header.""" + header = 'Cc: CC Person ' + patch = create_patch(headers=header + '\n') + response = self.client.get(reverse('patch-mbox', args=[patch.id])) + self.assertContains(response, header) + + def test_header_passthrough_to(self): + """Validate passthrough of 'To' header.""" + header = 'To: To Person ' + patch = create_patch(headers=header + '\n') + response = self.client.get(reverse('patch-mbox', args=[patch.id])) + self.assertContains(response, header) + + def test_header_passthrough_date(self): + """Validate passthrough of 'Date' header.""" + header = 'Date: Fri, 7 Jun 2013 15:42:54 +1000' + patch = create_patch(headers=header + '\n') + response = self.client.get(reverse('patch-mbox', args=[patch.id])) + self.assertContains(response, header) + + def test_patchwork_id_header(self): + """Validate inclusion of generated 'X-Patchwork-Id' header.""" + patch = create_patch() + response = self.client.get(reverse('patch-mbox', args=[patch.id])) + self.assertContains(response, 'X-Patchwork-Id: %d' % patch.id) + + def test_patchwork_delegate_header(self): + """Validate inclusion of generated 'X-Patchwork-Delegate' header.""" + user = create_user() + patch = create_patch(delegate=user) + response = self.client.get(reverse('patch-mbox', args=[patch.id])) + self.assertContains(response, 'X-Patchwork-Delegate: %s' % user.email) + + def test_from_header(self): + """Validate non-ascii 'From' header. + + Test that a person with characters outside ASCII in his name do + produce correct From header. As RFC 2822 state we must retain + the format for the mail while the name part + may be coded in some ways. + """ + person = create_person(name=u'©ool guŷ') + patch = create_patch(submitter=person) + from_email = '<' + person.email + '>' + response = self.client.get(reverse('patch-mbox', args=[patch.id])) self.assertContains(response, from_email) - -class MboxDateHeaderTest(TestCase): - fixtures = ['default_states'] - - """ Test that the date provided in the patch mail view is correct """ - - 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() - - def testDateHeader(self): - response = self.client.get('/patch/%d/mbox/' % self.patch.id) + def test_date_header(self): + patch = create_patch() + response = self.client.get(reverse('patch-mbox', args=[patch.id])) mail = email.message_from_string(response.content.decode()) mail_date = dateutil.parser.parse(mail['Date']) # patch dates are all in UTC - patch_date = self.patch.date.replace(tzinfo=dateutil.tz.tzutc(), - microsecond=0) + patch_date = patch.date.replace(tzinfo=dateutil.tz.tzutc(), + microsecond=0) self.assertEqual(mail_date, patch_date) - def testSuppliedDateHeader(self): - hour_offset = 3 - tz = dateutil.tz.tzoffset(None, hour_offset * 60 * 60) + def test_supplied_date_header(self): + patch = create_patch() + offset = 3 * 60 * 60 # 3 (hours) * 60 (minutes) * 60 (seconds) + tz = dateutil.tz.tzoffset(None, offset) date = datetime.datetime.utcnow() - datetime.timedelta(days=1) date = date.replace(tzinfo=tz, microsecond=0) - self.patch.headers = 'Date: %s\n' % date.strftime("%a, %d %b %Y %T %z") - self.patch.save() + patch.headers = 'Date: %s\n' % date.strftime("%a, %d %b %Y %T %z") + patch.save() - response = self.client.get('/patch/%d/mbox/' % self.patch.id) + response = self.client.get(reverse('patch-mbox', args=[patch.id])) mail = email.message_from_string(response.content.decode()) mail_date = dateutil.parser.parse(mail['Date']) self.assertEqual(mail_date, date) class MboxCommentPostcriptUnchangedTest(TestCase): - fixtures = ['default_states'] - - """ Test that the mbox view doesn't change the postscript part of a mail. - There where always a missing blank right after the postscript - delimiter '---' and an additional newline right before. """ - def setUp(self): - defaults.project.save() + fixtures = ['default_states'] - self.person = defaults.patch_author_person - self.person.save() + def test_comment_unchanged(self): + """Validate postscript part of mail is unchanged. - self.txt = 'some comment\n---\n some/file | 1 +\n' + Test that the mbox view doesn't change the postscript part of + a mail. There where always a missing blank right after the + postscript delimiter '---' and an additional newline right + before. + """ + content = 'some comment\n---\n some/file | 1 +\n' + patch = create_patch(content=content, diff='') - self.patch = Patch(project=defaults.project, - msgid='p1', name='testpatch', - submitter=self.person, diff='', - content=self.txt) - self.patch.save() + response = self.client.get(reverse('patch-mbox', args=[patch.id])) - def testCommentUnchanged(self): - response = self.client.get('/patch/%d/mbox/' % self.patch.id) - self.assertContains(response, self.txt) - self.txt += "\n" - self.assertNotContains(response, self.txt) + self.assertContains(response, content) + self.assertNotContains(response, content + '\n')