Skip to content

Commit 09335d4

Browse files
committed
Fix csv export with text search. test csv export Sqlite FTS syntax error
1 parent b54ef4f commit 09335d4

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

test/test_cgi.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def testAddMessageNoEscape(self):
102102

103103
class testCsvExport(object):
104104

105-
def testCSVExport(self):
105+
def testCSVExportBase(self):
106106
cl = self._make_client(
107107
{'@columns': 'id,title,status,keyword,assignedto,nosy'},
108108
nodeid=None, userid='1')
@@ -137,27 +137,32 @@ def testCSVExport(self):
137137
"\"2\",\"bar2\",\"1\",\"['1', '2']\",\"3\",\"['3']\"\r\n"
138138
'\"3\","baz32",\"4\","[]","None","[]"\r\n')
139139
#print(should_be)
140-
print(output.getvalue())
140+
#print(output.getvalue())
141141
self.assertEqual(output.getvalue(), should_be)
142142

143143
# test full text search
144+
# call export version that outputs names
144145
cl = self._make_client(
145146
{'@columns': 'id,title,status,keyword,assignedto,nosy',
146147
"@search_text": "bar2"}, nodeid=None, userid='1')
147148
cl.classname = 'issue'
148149
output = io.BytesIO()
149150
cl.request = MockNull()
150151
cl.request.wfile = output
151-
152-
# call export version that outputs names
153152
actions.ExportCSVAction(cl).handle()
154153
should_be=(s2b('"id","title","status","keyword","assignedto","nosy"\r\n'
155154
'"2","bar2","unread","keyword1;keyword2","Bork, Chef","Bork, Chef"\r\n'))
156155

156+
self.assertEqual(output.getvalue(), should_be)
157+
157158
# call export version that outputs id numbers
159+
output = io.BytesIO()
160+
cl.request = MockNull()
161+
cl.request.wfile = output
158162
actions.ExportCSVWithIdAction(cl).handle()
159163
should_be = s2b('"id","title","status","keyword","assignedto","nosy"\r\n'
160164
"\"2\",\"bar2\",\"1\",\"['1', '2']\",\"3\",\"['3']\"\r\n")
165+
self.assertEqual(output.getvalue(), should_be)
161166

162167
class FormTestCase(FormTestParent, StringFragmentCmpHelper, testCsvExport, unittest.TestCase):
163168

@@ -2478,6 +2483,26 @@ def _make_client(self, form, classname='user', nodeid='1',
24782483
cl.template = template
24792484
return cl
24802485

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()
24812506

24822507
class SqliteNativeCgiTest(unittest.TestCase, testFtsQuery):
24832508
"""All of the rest of the tests use anydbm as the backend.

0 commit comments

Comments
 (0)