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>'
97 self.patch = Patch(project = defaults.project,
98 msgid = 'p1', name = 'testpatch',
99 submitter = self.person, content = '')
101 def testCCHeader(self):
102 self.patch.headers = self.cc_header + '\n'
105 response = self.client.get('/patch/%d/mbox/' % self.patch.id)
106 self.assertContains(response, self.cc_header)
108 def testToHeader(self):
109 self.patch.headers = self.to_header + '\n'
112 response = self.client.get('/patch/%d/mbox/' % self.patch.id)
113 self.assertContains(response, self.to_header)
115 class MboxBrokenFromHeaderTest(TestCase):
116 """ Test that a person with characters outside ASCII in his name do
117 produce correct From header. As RFC 2822 state we must retain the
118 <user@doamin.tld> format for the mail while the name part may be coded
122 defaults.project.save()
123 self.person = defaults.patch_author_person
124 self.person.name = u'©ool guŷ'
127 self.patch = Patch(project = defaults.project,
128 msgid = 'p1', name = 'testpatch',
129 submitter = self.person, content = '')
131 def testFromHeader(self):
133 from_email = '<' + self.person.email + '>'
135 response = self.client.get('/patch/%d/mbox/' % self.patch.id)
136 self.assertContains(response, from_email)
138 class MboxDateHeaderTest(TestCase):
139 """ Test that the date provided in the patch mail view is correct """
142 defaults.project.save()
143 self.person = defaults.patch_author_person
146 self.patch = Patch(project = defaults.project,
147 msgid = 'p1', name = 'testpatch',
148 submitter = self.person, content = '')
151 def testDateHeader(self):
152 response = self.client.get('/patch/%d/mbox/' % self.patch.id)
153 mail = email.message_from_string(response.content)
154 mail_date = dateutil.parser.parse(mail['Date'])
155 # patch dates are all in UTC
156 patch_date = self.patch.date.replace(tzinfo=dateutil.tz.tzutc(),
158 self.assertEqual(mail_date, patch_date)