Package trac :: Package search :: Package tests :: Module web_ui

Source Code for Module trac.search.tests.web_ui

 1  # -*- coding: utf-8 -*- 
 2  # 
 3  # Copyright (C) 2015-2020 Edgewall Software 
 4  # All rights reserved. 
 5  # 
 6  # This software is licensed as described in the file COPYING, which 
 7  # you should have received as part of this distribution. The terms 
 8  # are also available at https://trac.edgewall.org/wiki/TracLicense. 
 9  # 
10  # This software consists of voluntary contributions made by many 
11  # individuals. For the exact contribution history, see the revision 
12  # history and logs, available at https://trac.edgewall.org/log/. 
13   
14  import unittest 
15   
16  from trac.search.web_ui import SearchModule 
17  from trac.test import EnvironmentStub, MockRequest 
18  from trac.ticket.model import Ticket 
19  from trac.ticket.web_ui import TicketModule 
20   
21   
22 -class SearchModuleTestCase(unittest.TestCase):
23
24 - def setUp(self):
25 self.env = EnvironmentStub() 26 self.search_module = SearchModule(self.env)
27
28 - def tearDown(self):
29 self.env.reset_db()
30
31 - def _insert_ticket(self, **kw):
32 """Helper for inserting a ticket into the database""" 33 ticket = Ticket(self.env) 34 for k, v in kw.items(): 35 ticket[k] = v 36 return ticket.insert()
37
39 for _ in range(0, 21): 40 self._insert_ticket(summary="Trac") 41 req = MockRequest(self.env, 42 args={'page': '3', 'q': 'Trac', 'ticket': 'on'}) 43 44 data = self.search_module.process_request(req)[1] 45 46 self.assertEqual([], req.chrome['warnings']) 47 self.assertEqual(2, data['results'].page)
48
50 """Out of range value for page defaults to page 1.""" 51 for _ in range(0, 20): 52 self._insert_ticket(summary="Trac") 53 req = MockRequest(self.env, 54 args={'page': '3', 'q': 'Trac', 'ticket': 'on'}) 55 56 data = self.search_module.process_request(req)[1] 57 58 self.assertIn("Page 3 is out of range.", req.chrome['warnings']) 59 self.assertEqual(0, data['results'].page)
60 61
62 -def suite():
63 suite = unittest.TestSuite() 64 suite.addTest(unittest.makeSuite(SearchModuleTestCase)) 65 return suite
66 67 68 if __name__ == '__main__': 69 unittest.main(defaultTest='suite') 70