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):
45 fixtures = ['default_states']
49 ('AlCMyjOsx', 'AlxMyjOsx@nRbqkQV.wBw', d(2014,3,16,13, 4,50, 155643)),
50 ('MMZnrcDjT', 'MMmnrcDjT@qGaIfOl.tbk', d(2014,1,25,13, 4,50, 162814)),
51 ('WGirwRXgK', 'WGSrwRXgK@TriIETY.GhE', d(2014,2,14,13, 4,50, 169305)),
52 ('isjNIuiAc', 'issNIuiAc@OsEirYx.EJh', d(2014,3,15,13, 4,50, 176264)),
53 ('XkAQpYGws', 'XkFQpYGws@hzntTcm.JSE', d(2014,1,18,13, 4,50, 182493)),
54 ('uJuCPWMvi', 'uJACPWMvi@AVRBOBl.ecy', d(2014,3,12,13, 4,50, 189554)),
55 ('TyQmWtcbg', 'TylmWtcbg@DzrNeNH.JuB', d(2014,2, 3,13, 4,50, 195685)),
56 ('FpvAhWRdX', 'FpKAhWRdX@agxnCAI.wFO', d(2014,3,15,13, 4,50, 201398)),
57 ('bmoYvnyWa', 'bmdYvnyWa@aeoPnlX.juy', d(2014,3, 4,13, 4,50, 206800)),
58 ('CiReUQsAq', 'CiieUQsAq@DnOYRuf.TTI', d(2014,3,28,13, 4,50, 212169)),
62 defaults.project.save()
64 for (name, email, date) in self.patchmeta:
65 patch_name = 'testpatch' + name
66 person = Person(name = name, email = email)
68 patch = Patch(project = defaults.project, msgid = patch_name,
69 submitter = person, content = '', date = date)
72 def _extract_patch_ids(self, response):
73 id_re = re.compile('<tr id="patch_row:(\d+)" ')
74 ids = [ int(m.group(1)) for m in id_re.finditer(response.content) ]
77 def _test_sequence(self, response, test_fn):
78 ids = self._extract_patch_ids(response)
79 self.assertTrue(bool(ids))
80 patches = [ Patch.objects.get(id = i) for i in ids ]
81 pairs = zip(patches, patches[1:])
82 [ test_fn(p1, p2) for (p1, p2) in pairs ]
84 def testDateOrder(self):
85 url = reverse('patchwork.views.patch.list',
86 kwargs={'project_id': defaults.project.linkname})
87 response = self.client.get(url + '?order=date')
89 self.assertLessEqual(p1.date, p2.date)
90 self._test_sequence(response, test_fn)
92 def testDateReverseOrder(self):
93 url = reverse('patchwork.views.patch.list',
94 kwargs={'project_id': defaults.project.linkname})
95 response = self.client.get(url + '?order=-date')
97 self.assertGreaterEqual(p1.date, p2.date)
98 self._test_sequence(response, test_fn)
100 def testSubmitterOrder(self):
101 url = reverse('patchwork.views.patch.list',
102 kwargs={'project_id': defaults.project.linkname})
103 response = self.client.get(url + '?order=submitter')
105 self.assertLessEqual(p1.submitter.name.lower(),
106 p2.submitter.name.lower())
107 self._test_sequence(response, test_fn)
109 def testSubmitterReverseOrder(self):
110 url = reverse('patchwork.views.patch.list',
111 kwargs={'project_id': defaults.project.linkname})
112 response = self.client.get(url + '?order=-submitter')
114 self.assertGreaterEqual(p1.submitter.name.lower(),
115 p2.submitter.name.lower())
116 self._test_sequence(response, test_fn)