]> git.ozlabs.org Git - patchwork/blob - apps/patchwork/tests/mboxviews.py
tests/mboxviews: add test for correct From header
[patchwork] / apps / patchwork / tests / mboxviews.py
1 # vim: set fileencoding=utf-8 :
2 #
3 # Patchwork - automated patch tracking system
4 # Copyright (C) 2009 Jeremy Kerr <jk@ozlabs.org>
5 #
6 # This file is part of the Patchwork package.
7 #
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.
12 #
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.
17 #
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
21
22 import unittest
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
27
28 class MboxPatchResponseTest(TestCase):
29     """ Test that the mbox view appends the Acked-by from a patch comment """
30     def setUp(self):
31         defaults.project.save()
32
33         self.person = defaults.patch_author_person
34         self.person.save()
35
36         self.patch = Patch(project = defaults.project,
37                            msgid = 'p1', name = 'testpatch',
38                            submitter = self.person, content = '')
39         self.patch.save()
40         comment = Comment(patch = self.patch, msgid = 'p1',
41                 submitter = self.person,
42                 content = 'comment 1 text\nAcked-by: 1\n')
43         comment.save()
44
45         comment = Comment(patch = self.patch, msgid = 'p2',
46                 submitter = self.person,
47                 content = 'comment 2 text\nAcked-by: 2\n')
48         comment.save()
49
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')
54
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. """
58     def setUp(self):
59         defaults.project.save()
60
61         self.person = defaults.patch_author_person
62         self.person.save()
63
64         self.patch = Patch(project = defaults.project,
65                            msgid = 'p1', name = 'testpatch',
66                            submitter = self.person, content = '')
67         self.patch.save()
68         comment = Comment(patch = self.patch, msgid = 'p1',
69                 submitter = self.person,
70                 content = 'comment 1 text\nAcked-by: 1\n---\nupdate\n')
71         comment.save()
72
73         comment = Comment(patch = self.patch, msgid = 'p2',
74                 submitter = self.person,
75                 content = 'comment 2 text\nAcked-by: 2\n')
76         comment.save()
77
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')
82
83 class MboxPassThroughHeaderTest(TestCase):
84     """ Test that we see 'Cc' and 'To' headers passed through from original
85         message to mbox view """
86
87     def setUp(self):
88         defaults.project.save()
89         self.person = defaults.patch_author_person
90         self.person.save()
91
92         self.cc_header = 'Cc: CC Person <cc@example.com>'
93         self.to_header = 'To: To Person <to@example.com>'
94
95         self.patch = Patch(project = defaults.project,
96                            msgid = 'p1', name = 'testpatch',
97                            submitter = self.person, content = '')
98
99     def testCCHeader(self):
100         self.patch.headers = self.cc_header + '\n'
101         self.patch.save()
102
103         response = self.client.get('/patch/%d/mbox/' % self.patch.id)
104         self.assertContains(response, self.cc_header)
105
106     def testToHeader(self):
107         self.patch.headers = self.to_header + '\n'
108         self.patch.save()
109
110         response = self.client.get('/patch/%d/mbox/' % self.patch.id)
111         self.assertContains(response, self.to_header)
112
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
117         in some ways. """
118
119     def setUp(self):
120         defaults.project.save()
121         self.person = defaults.patch_author_person
122         self.person.name = u'©ool guŷ'
123         self.person.save()
124
125         self.patch = Patch(project = defaults.project,
126                 msgid = 'p1', name = 'testpatch',
127                 submitter = self.person, content = '')
128
129     def testFromHeader(self):
130         self.patch.save()
131         from_email = '<' + self.person.email + '>'
132
133         response = self.client.get('/patch/%d/mbox/' % self.patch.id)
134         self.assertContains(response, from_email)