]> git.ozlabs.org Git - patchwork/blob - apps/patchwork/tests/mboxviews.py
Copy headers from original mail into patch mbox output
[patchwork] / apps / patchwork / tests / mboxviews.py
1 # Patchwork - automated patch tracking system
2 # Copyright (C) 2009 Jeremy Kerr <jk@ozlabs.org>
3 #
4 # This file is part of the Patchwork package.
5 #
6 # Patchwork is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # Patchwork is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with Patchwork; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
20 import unittest
21 from django.test import TestCase
22 from django.test.client import Client
23 from patchwork.models import Patch, Comment, Person
24 from patchwork.tests.utils import defaults, create_user, find_in_context
25
26 class MboxPatchResponseTest(TestCase):
27     """ Test that the mbox view appends the Acked-by from a patch comment """
28     def setUp(self):
29         defaults.project.save()
30
31         self.person = defaults.patch_author_person
32         self.person.save()
33
34         self.patch = Patch(project = defaults.project,
35                            msgid = 'p1', name = 'testpatch',
36                            submitter = self.person, content = '')
37         self.patch.save()
38         comment = Comment(patch = self.patch, msgid = 'p1',
39                 submitter = self.person,
40                 content = 'comment 1 text\nAcked-by: 1\n')
41         comment.save()
42
43         comment = Comment(patch = self.patch, msgid = 'p2',
44                 submitter = self.person,
45                 content = 'comment 2 text\nAcked-by: 2\n')
46         comment.save()
47
48     def testPatchResponse(self):
49         response = self.client.get('/patch/%d/mbox/' % self.patch.id)
50         self.assertContains(response,
51                 'Acked-by: 1\nAcked-by: 2\n')
52
53 class MboxPatchSplitResponseTest(TestCase):
54     """ Test that the mbox view appends the Acked-by from a patch comment,
55         and places it before an '---' update line. """
56     def setUp(self):
57         defaults.project.save()
58
59         self.person = defaults.patch_author_person
60         self.person.save()
61
62         self.patch = Patch(project = defaults.project,
63                            msgid = 'p1', name = 'testpatch',
64                            submitter = self.person, content = '')
65         self.patch.save()
66         comment = Comment(patch = self.patch, msgid = 'p1',
67                 submitter = self.person,
68                 content = 'comment 1 text\nAcked-by: 1\n---\nupdate\n')
69         comment.save()
70
71         comment = Comment(patch = self.patch, msgid = 'p2',
72                 submitter = self.person,
73                 content = 'comment 2 text\nAcked-by: 2\n')
74         comment.save()
75
76     def testPatchResponse(self):
77         response = self.client.get('/patch/%d/mbox/' % self.patch.id)
78         self.assertContains(response,
79                 'Acked-by: 1\nAcked-by: 2\n')
80
81 class MboxPassThroughHeaderTest(TestCase):
82     """ Test that we see 'Cc' and 'To' headers passed through from original
83         message to mbox view """
84
85     def setUp(self):
86         defaults.project.save()
87         self.person = defaults.patch_author_person
88         self.person.save()
89
90         self.cc_header = 'Cc: CC Person <cc@example.com>'
91         self.to_header = 'To: To Person <to@example.com>'
92
93         self.patch = Patch(project = defaults.project,
94                            msgid = 'p1', name = 'testpatch',
95                            submitter = self.person, content = '')
96
97     def testCCHeader(self):
98         self.patch.headers = self.cc_header + '\n'
99         self.patch.save()
100
101         response = self.client.get('/patch/%d/mbox/' % self.patch.id)
102         self.assertContains(response, self.cc_header)
103
104     def testToHeader(self):
105         self.patch.headers = self.to_header + '\n'
106         self.patch.save()
107
108         response = self.client.get('/patch/%d/mbox/' % self.patch.id)
109         self.assertContains(response, self.to_header)