1 # Patchwork - automated patch tracking system
2 # Copyright (C) 2012 Jeremy Kerr <jk@ozlabs.org>
4 # This file is part of the Patchwork package.
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.
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.
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
25 from django.test import TestCase
26 from django.test.client import Client
27 from patchwork.tests.utils import defaults, create_user, find_in_context
28 from patchwork.models import Person, Patch
29 from django.core.urlresolvers import reverse
31 class EmptyPatchListTest(TestCase):
33 def testEmptyPatchList(self):
34 """test that we don't output an empty table when there are no
36 project = defaults.project
37 defaults.project.save()
38 url = reverse('patchwork.views.patch.list',
39 kwargs={'project_id': project.linkname})
40 response = self.client.get(url)
41 self.assertContains(response, 'No patches to display')
42 self.assertNotContains(response, 'tbody')
44 class PatchOrderTest(TestCase):
48 ('AlCMyjOsx', 'AlxMyjOsx@nRbqkQV.wBw', d(2014,3,16,13, 4,50, 155643)),
49 ('MMZnrcDjT', 'MMmnrcDjT@qGaIfOl.tbk', d(2014,1,25,13, 4,50, 162814)),
50 ('WGirwRXgK', 'WGSrwRXgK@TriIETY.GhE', d(2014,2,14,13, 4,50, 169305)),
51 ('isjNIuiAc', 'issNIuiAc@OsEirYx.EJh', d(2014,3,15,13, 4,50, 176264)),
52 ('XkAQpYGws', 'XkFQpYGws@hzntTcm.JSE', d(2014,1,18,13, 4,50, 182493)),
53 ('uJuCPWMvi', 'uJACPWMvi@AVRBOBl.ecy', d(2014,3,12,13, 4,50, 189554)),
54 ('TyQmWtcbg', 'TylmWtcbg@DzrNeNH.JuB', d(2014,2, 3,13, 4,50, 195685)),
55 ('FpvAhWRdX', 'FpKAhWRdX@agxnCAI.wFO', d(2014,3,15,13, 4,50, 201398)),
56 ('bmoYvnyWa', 'bmdYvnyWa@aeoPnlX.juy', d(2014,3, 4,13, 4,50, 206800)),
57 ('CiReUQsAq', 'CiieUQsAq@DnOYRuf.TTI', d(2014,3,28,13, 4,50, 212169)),
61 defaults.project.save()
63 for (name, email, date) in self.patchmeta:
64 patch_name = 'testpatch' + name
65 person = Person(name = name, email = email)
67 patch = Patch(project = defaults.project, msgid = patch_name,
68 submitter = person, content = '', date = date)
71 def _extract_patch_ids(self, response):
72 id_re = re.compile('<tr id="patch_row:(\d+)" ')
73 ids = [ int(m.group(1)) for m in id_re.finditer(response.content) ]
76 def _test_sequence(self, response, test_fn):
77 ids = self._extract_patch_ids(response)
78 self.assertTrue(bool(ids))
79 patches = [ Patch.objects.get(id = i) for i in ids ]
80 pairs = zip(patches, patches[1:])
81 [ test_fn(p1, p2) for (p1, p2) in pairs ]
83 def testDateOrder(self):
84 url = reverse('patchwork.views.patch.list',
85 kwargs={'project_id': defaults.project.linkname})
86 response = self.client.get(url + '?order=date')
88 self.assertLessEqual(p1.date, p2.date)
89 self._test_sequence(response, test_fn)
91 def testDateReverseOrder(self):
92 url = reverse('patchwork.views.patch.list',
93 kwargs={'project_id': defaults.project.linkname})
94 response = self.client.get(url + '?order=-date')
96 self.assertGreaterEqual(p1.date, p2.date)
97 self._test_sequence(response, test_fn)
99 def testSubmitterOrder(self):
100 url = reverse('patchwork.views.patch.list',
101 kwargs={'project_id': defaults.project.linkname})
102 response = self.client.get(url + '?order=submitter')
104 self.assertLessEqual(p1.submitter.name.lower(),
105 p2.submitter.name.lower())
106 self._test_sequence(response, test_fn)
108 def testSubmitterReverseOrder(self):
109 url = reverse('patchwork.views.patch.list',
110 kwargs={'project_id': defaults.project.linkname})
111 response = self.client.get(url + '?order=-submitter')
113 self.assertGreaterEqual(p1.submitter.name.lower(),
114 p2.submitter.name.lower())
115 self._test_sequence(response, test_fn)