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
23 from django.test import TestCase
24 from django.test.client import Client
25 from patchwork.models import Patch, Comment, Person
26 from patchwork.tests.utils import defaults, create_user, find_in_context
28 class MboxPatchResponseTest(TestCase):
29 """ Test that the mbox view appends the Acked-by from a patch comment """
31 defaults.project.save()
33 self.person = defaults.patch_author_person
36 self.patch = Patch(project = defaults.project,
37 msgid = 'p1', name = 'testpatch',
38 submitter = self.person, content = '')
40 comment = Comment(patch = self.patch, msgid = 'p1',
41 submitter = self.person,
42 content = 'comment 1 text\nAcked-by: 1\n')
45 comment = Comment(patch = self.patch, msgid = 'p2',
46 submitter = self.person,
47 content = 'comment 2 text\nAcked-by: 2\n')
50 def testPatchResponse(self):
51 response = self.client.get('/patch/%d/mbox/' % self.patch.id)
52 self.assertContains(response,
53 'Acked-by: 1\nAcked-by: 2\n')
55 class MboxPatchSplitResponseTest(TestCase):
56 """ Test that the mbox view appends the Acked-by from a patch comment,
57 and places it before an '---' update line. """
59 defaults.project.save()
61 self.person = defaults.patch_author_person
64 self.patch = Patch(project = defaults.project,
65 msgid = 'p1', name = 'testpatch',
66 submitter = self.person, content = '')
68 comment = Comment(patch = self.patch, msgid = 'p1',
69 submitter = self.person,
70 content = 'comment 1 text\nAcked-by: 1\n---\nupdate\n')
73 comment = Comment(patch = self.patch, msgid = 'p2',
74 submitter = self.person,
75 content = 'comment 2 text\nAcked-by: 2\n')
78 def testPatchResponse(self):
79 response = self.client.get('/patch/%d/mbox/' % self.patch.id)
80 self.assertContains(response,
81 'Acked-by: 1\nAcked-by: 2\n')
83 class MboxPassThroughHeaderTest(TestCase):
84 """ Test that we see 'Cc' and 'To' headers passed through from original
85 message to mbox view """
88 defaults.project.save()
89 self.person = defaults.patch_author_person
92 self.cc_header = 'Cc: CC Person <cc@example.com>'
93 self.to_header = 'To: To Person <to@example.com>'
95 self.patch = Patch(project = defaults.project,
96 msgid = 'p1', name = 'testpatch',
97 submitter = self.person, content = '')
99 def testCCHeader(self):
100 self.patch.headers = self.cc_header + '\n'
103 response = self.client.get('/patch/%d/mbox/' % self.patch.id)
104 self.assertContains(response, self.cc_header)
106 def testToHeader(self):
107 self.patch.headers = self.to_header + '\n'
110 response = self.client.get('/patch/%d/mbox/' % self.patch.id)
111 self.assertContains(response, self.to_header)
113 class MboxBrokenFromHeaderTest(TestCase):
114 """ Test that a person with characters outside ASCII in his name do
115 produce correct From header. As RFC 2822 state we must retain the
116 <user@doamin.tld> format for the mail while the name part may be coded
120 defaults.project.save()
121 self.person = defaults.patch_author_person
122 self.person.name = u'©ool guŷ'
125 self.patch = Patch(project = defaults.project,
126 msgid = 'p1', name = 'testpatch',
127 submitter = self.person, content = '')
129 def testFromHeader(self):
131 from_email = '<' + self.person.email + '>'
133 response = self.client.get('/patch/%d/mbox/' % self.patch.id)
134 self.assertContains(response, from_email)