comparison test/test_cgi.py @ 6600:65336409738c

Fix csv export with text search. test csv export Sqlite FTS syntax error
author John Rouillard <rouilj@ieee.org>
date Wed, 26 Jan 2022 16:48:06 -0500
parents 39189dd94f2c
children 154f286061e2
comparison
equal deleted inserted replaced
6599:39189dd94f2c 6600:65336409738c
100 self.assertEqual(cm([],'<i>x</i>\n<b>x</b>',False), 100 self.assertEqual(cm([],'<i>x</i>\n<b>x</b>',False),
101 ['<i>x</i><br />\n<b>x</b>']) 101 ['<i>x</i><br />\n<b>x</b>'])
102 102
103 class testCsvExport(object): 103 class testCsvExport(object):
104 104
105 def testCSVExport(self): 105 def testCSVExportBase(self):
106 cl = self._make_client( 106 cl = self._make_client(
107 {'@columns': 'id,title,status,keyword,assignedto,nosy'}, 107 {'@columns': 'id,title,status,keyword,assignedto,nosy'},
108 nodeid=None, userid='1') 108 nodeid=None, userid='1')
109 cl.classname = 'issue' 109 cl.classname = 'issue'
110 110
135 should_be = s2b('"id","title","status","keyword","assignedto","nosy"\r\n' 135 should_be = s2b('"id","title","status","keyword","assignedto","nosy"\r\n'
136 "\"1\",\"foo1\",\"2\",\"[]\",\"4\",\"['3', '4', '5']\"\r\n" 136 "\"1\",\"foo1\",\"2\",\"[]\",\"4\",\"['3', '4', '5']\"\r\n"
137 "\"2\",\"bar2\",\"1\",\"['1', '2']\",\"3\",\"['3']\"\r\n" 137 "\"2\",\"bar2\",\"1\",\"['1', '2']\",\"3\",\"['3']\"\r\n"
138 '\"3\","baz32",\"4\","[]","None","[]"\r\n') 138 '\"3\","baz32",\"4\","[]","None","[]"\r\n')
139 #print(should_be) 139 #print(should_be)
140 print(output.getvalue()) 140 #print(output.getvalue())
141 self.assertEqual(output.getvalue(), should_be) 141 self.assertEqual(output.getvalue(), should_be)
142 142
143 # test full text search 143 # test full text search
144 # call export version that outputs names
144 cl = self._make_client( 145 cl = self._make_client(
145 {'@columns': 'id,title,status,keyword,assignedto,nosy', 146 {'@columns': 'id,title,status,keyword,assignedto,nosy',
146 "@search_text": "bar2"}, nodeid=None, userid='1') 147 "@search_text": "bar2"}, nodeid=None, userid='1')
147 cl.classname = 'issue' 148 cl.classname = 'issue'
148 output = io.BytesIO() 149 output = io.BytesIO()
149 cl.request = MockNull() 150 cl.request = MockNull()
150 cl.request.wfile = output 151 cl.request.wfile = output
151
152 # call export version that outputs names
153 actions.ExportCSVAction(cl).handle() 152 actions.ExportCSVAction(cl).handle()
154 should_be=(s2b('"id","title","status","keyword","assignedto","nosy"\r\n' 153 should_be=(s2b('"id","title","status","keyword","assignedto","nosy"\r\n'
155 '"2","bar2","unread","keyword1;keyword2","Bork, Chef","Bork, Chef"\r\n')) 154 '"2","bar2","unread","keyword1;keyword2","Bork, Chef","Bork, Chef"\r\n'))
156 155
156 self.assertEqual(output.getvalue(), should_be)
157
157 # call export version that outputs id numbers 158 # call export version that outputs id numbers
159 output = io.BytesIO()
160 cl.request = MockNull()
161 cl.request.wfile = output
158 actions.ExportCSVWithIdAction(cl).handle() 162 actions.ExportCSVWithIdAction(cl).handle()
159 should_be = s2b('"id","title","status","keyword","assignedto","nosy"\r\n' 163 should_be = s2b('"id","title","status","keyword","assignedto","nosy"\r\n'
160 "\"2\",\"bar2\",\"1\",\"['1', '2']\",\"3\",\"['3']\"\r\n") 164 "\"2\",\"bar2\",\"1\",\"['1', '2']\",\"3\",\"['3']\"\r\n")
165 self.assertEqual(output.getvalue(), should_be)
161 166
162 class FormTestCase(FormTestParent, StringFragmentCmpHelper, testCsvExport, unittest.TestCase): 167 class FormTestCase(FormTestParent, StringFragmentCmpHelper, testCsvExport, unittest.TestCase):
163 168
164 def setUp(self): 169 def setUp(self):
165 FormTestParent.setUp(self) 170 FormTestParent.setUp(self)
2476 cl._error_message = [] 2481 cl._error_message = []
2477 cl._ok_message = [] 2482 cl._ok_message = []
2478 cl.template = template 2483 cl.template = template
2479 return cl 2484 return cl
2480 2485
2486 def testCSVExportSearchError(self):
2487 # test full text search
2488 cl = self._make_client(
2489 {'@columns': 'id,title,status,keyword,assignedto,nosy',
2490 "@search_text": "foo + ^bar2"}, nodeid=None, userid='1')
2491 cl.classname = 'issue'
2492 output = io.BytesIO()
2493 cl.request = MockNull()
2494 cl.request.wfile = output
2495
2496 # note NotFound isn't quite right. however this exception
2497 # passes up the stack to where it is handled with a suitable
2498 # display of the error.
2499 # call export version that outputs names
2500 with self.assertRaises(NotFound) as cm:
2501 actions.ExportCSVAction(cl).handle()
2502
2503 # call export version that outputs id numbers
2504 with self.assertRaises(NotFound) as cm:
2505 actions.ExportCSVWithIdAction(cl).handle()
2481 2506
2482 class SqliteNativeCgiTest(unittest.TestCase, testFtsQuery): 2507 class SqliteNativeCgiTest(unittest.TestCase, testFtsQuery):
2483 """All of the rest of the tests use anydbm as the backend. 2508 """All of the rest of the tests use anydbm as the backend.
2484 This class tests renderContext for fulltext search. 2509 This class tests renderContext for fulltext search.
2485 Run with sqlite and native indexer. 2510 Run with sqlite and native indexer.

Roundup Issue Tracker: http://roundup-tracker.org/