1 # vim: set fileencoding=utf-8 :
3 # Patchwork - automated patch tracking system
4 # Copyright (C) 2009 Jeremy Kerr <jk@ozlabs.org>
6 # This file is part of the Patchwork package.
8 # Patchwork is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # Patchwork is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Patchwork; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 import dateutil.parser, dateutil.tz
25 from django.test import TestCase
26 from django.test.client import Client
27 from patchwork.models import Patch, Comment, Person
28 from patchwork.tests.utils import defaults, create_user, find_in_context
30 class MboxPatchResponseTest(TestCase):
31 """ Test that the mbox view appends the Acked-by from a patch comment """
33 defaults.project.save()
35 self.person = defaults.patch_author_person
38 self.patch = Patch(project = defaults.project,
39 msgid = 'p1', name = 'testpatch',
40 submitter = self.person, content = '')
42 comment = Comment(patch = self.patch, msgid = 'p1',
43 submitter = self.person,
44 content = 'comment 1 text\nAcked-by: 1\n')
47 comment = Comment(patch = self.patch, msgid = 'p2',
48 submitter = self.person,
49 content = 'comment 2 text\nAcked-by: 2\n')
52 def testPatchResponse(self):
53 response = self.client.get('/patch/%d/mbox/' % self.patch.id)
54 self.assertContains(response,
55 'Acked-by: 1\nAcked-by: 2\n')
57 class MboxPatchSplitResponseTest(TestCase):
58 """ Test that the mbox view appends the Acked-by from a patch comment,
59 and places it before an '---' update line. """
61 defaults.project.save()
63 self.person = defaults.patch_author_person
66 self.patch = Patch(project = defaults.project,
67 msgid = 'p1', name = 'testpatch',
68 submitter = self.person, content = '')
70 comment = Comment(patch = self.patch, msgid = 'p1',
71 submitter = self.person,
72 content = 'comment 1 text\nAcked-by: 1\n---\nupdate\n')
75 comment = Comment(patch = self.patch, msgid = 'p2',
76 submitter = self.person,
77 content = 'comment 2 text\nAcked-by: 2\n')
80 def testPatchResponse(self):
81 response = self.client.get('/patch/%d/mbox/' % self.patch.id)
82 self.assertContains(response,
83 'Acked-by: 1\nAcked-by: 2\n')
85 class MboxPassThroughHeaderTest(TestCase):
86 """ Test that we see 'Cc' and 'To' headers passed through from original
87 message to mbox view """
90 defaults.project.save()
91 self.person = defaults.patch_author_person
94 self.cc_header = 'Cc: CC Person <cc@example.com>'
95 self.to_header = 'To: To Person <to@example.com>'
96 self.date_header = 'Date: Fri, 7 Jun 2013 15:42:54 +1000'
98 self.patch = Patch(project = defaults.project,
99 msgid = 'p1', name = 'testpatch',
100 submitter = self.person, content = '')
102 def testCCHeader(self):
103 self.patch.headers = self.cc_header + '\n'
106 response = self.client.get('/patch/%d/mbox/' % self.patch.id)
107 self.assertContains(response, self.cc_header)
109 def testToHeader(self):
110 self.patch.headers = self.to_header + '\n'
113 response = self.client.get('/patch/%d/mbox/' % self.patch.id)
114 self.assertContains(response, self.to_header)
116 def testDateHeader(self):
117 self.patch.headers = self.date_header + '\n'
120 response = self.client.get('/patch/%d/mbox/' % self.patch.id)
121 self.assertContains(response, self.date_header)
123 class MboxBrokenFromHeaderTest(TestCase):
124 """ Test that a person with characters outside ASCII in his name do
125 produce correct From header. As RFC 2822 state we must retain the
126 <user@doamin.tld> format for the mail while the name part may be coded
130 defaults.project.save()
131 self.person = defaults.patch_author_person
132 self.person.name = u'©ool guŷ'
135 self.patch = Patch(project = defaults.project,
136 msgid = 'p1', name = 'testpatch',
137 submitter = self.person, content = '')
139 def testFromHeader(self):
141 from_email = '<' + self.person.email + '>'
143 response = self.client.get('/patch/%d/mbox/' % self.patch.id)
144 self.assertContains(response, from_email)
146 class MboxDateHeaderTest(TestCase):
147 """ Test that the date provided in the patch mail view is correct """
150 defaults.project.save()
151 self.person = defaults.patch_author_person
154 self.patch = Patch(project = defaults.project,
155 msgid = 'p1', name = 'testpatch',
156 submitter = self.person, content = '')
159 def testDateHeader(self):
160 response = self.client.get('/patch/%d/mbox/' % self.patch.id)
161 mail = email.message_from_string(response.content)
162 mail_date = dateutil.parser.parse(mail['Date'])
163 # patch dates are all in UTC
164 patch_date = self.patch.date.replace(tzinfo=dateutil.tz.tzutc(),
166 self.assertEqual(mail_date, patch_date)