Mercurial > p > roundup > code
comparison test/test_cgi.py @ 8492:166cb2632315
issue2551413 - Broken MultiLink columns in CSV export (take 2)
Changed how I solved this. Restored the original line that cmeerw took
out, but use the 'id' field rather than the 'name' field. The if
statements folowing the line change it to the 'name' field
(realname if it's a user object): if there is one.
Updated the tests to test for this error and exercise the code. I had
to change the test to create/add messages to an issue. This required
that I suppress the sending of nosy messages using SENDMAILDEBUG env
var.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Mon, 15 Dec 2025 00:04:16 -0500 |
| parents | 224ccb8b49ca |
| children | 9c3ec0a5c7fc |
comparison
equal
deleted
inserted
replaced
| 8491:520075b29474 | 8492:166cb2632315 |
|---|---|
| 106 ['<i>x</i><br />\n<b>x</b>']) | 106 ['<i>x</i><br />\n<b>x</b>']) |
| 107 | 107 |
| 108 class testCsvExport(object): | 108 class testCsvExport(object): |
| 109 | 109 |
| 110 def testCSVExportBase(self): | 110 def testCSVExportBase(self): |
| 111 if 'SENDMAILDEBUG' not in os.environ: | |
| 112 os.environ['SENDMAILDEBUG'] = 'mail-test1.log' | |
| 113 SENDMAILDEBUG = os.environ['SENDMAILDEBUG'] | |
| 114 | |
| 111 cl = self._make_client( | 115 cl = self._make_client( |
| 112 {'@columns': 'id,title,status,keyword,assignedto,nosy,creation'}, | 116 {'@columns': 'id,title,status,keyword,assignedto,nosy,creation,messages'}, |
| 113 nodeid=None, userid='1') | 117 nodeid=None, userid='1') |
| 114 cl.classname = 'issue' | 118 cl.classname = 'issue' |
| 115 | 119 |
| 116 demo_id=self.db.user.create(username='demo', address='demo@test.test', | 120 demo_id=self.db.user.create(username='demo', address='demo@test.test', |
| 117 roles='User', realname='demo') | 121 roles='User', realname='demo') |
| 125 def dummyClosure(adate=None, translator=None): | 129 def dummyClosure(adate=None, translator=None): |
| 126 return dummy | 130 return dummy |
| 127 return dummyClosure | 131 return dummyClosure |
| 128 date.Date = dummyDate() | 132 date.Date = dummyDate() |
| 129 | 133 |
| 134 a_msg = self.db.msg.create(content="23a", author="4", | |
| 135 messageid="xyzzy@there", | |
| 136 recipients=['3']) | |
| 137 b_msg = self.db.msg.create(content="23b", author="3", | |
| 138 messageid="xyzzy@here", | |
| 139 recipients=['4']) | |
| 140 | |
| 130 self.db.issue.create(title='foo1', status='2', assignedto='4', nosy=['3',demo_id]) | 141 self.db.issue.create(title='foo1', status='2', assignedto='4', nosy=['3',demo_id]) |
| 131 self.db.issue.create(title='bar2', status='1', assignedto='3', keyword=[key_id1,key_id2]) | 142 self.db.issue.create(title='bar2', status='1', assignedto='3', keyword=[key_id1,key_id2]) |
| 132 self.db.issue.create(title='baz32', status='4') | 143 self.db.issue.create(title='baz32', status='4', messages=[a_msg, b_msg]) |
| 144 | |
| 133 output = io.BytesIO() | 145 output = io.BytesIO() |
| 134 cl.request = MockNull() | 146 cl.request = MockNull() |
| 135 cl.request.wfile = output | 147 cl.request.wfile = output |
| 136 # call export version that outputs names | 148 # call export version that outputs names |
| 137 actions.ExportCSVAction(cl).handle() | 149 actions.ExportCSVAction(cl).handle() |
| 138 should_be=(s2b('"id","title","status","keyword","assignedto","nosy","creation"\r\n' | 150 should_be=(s2b('"id","title","status","keyword","assignedto","nosy","creation","messages"\r\n' |
| 139 '"1","foo1","deferred","","Contrary, Mary","Bork, Chef;Contrary, Mary;demo","2000-06-26 00:34"\r\n' | 151 '"1","foo1","deferred","","Contrary, Mary","Bork, Chef;Contrary, Mary;demo","2000-06-26 00:34",""\r\n' |
| 140 '"2","bar2","unread","keyword1;keyword2","Bork, Chef","Bork, Chef","2000-06-26 00:34"\r\n' | 152 '"2","bar2","unread","keyword1;keyword2","Bork, Chef","Bork, Chef","2000-06-26 00:34",""\r\n' |
| 141 '"3","baz32","need-eg","","","","2000-06-26 00:34"\r\n')) | 153 '"3","baz32","need-eg","","","Bork, Chef;Contrary, Mary","2000-06-26 00:34","1;2"\r\n')) |
| 142 | |
| 143 | 154 |
| 144 #print(should_be) | 155 #print(should_be) |
| 145 #print(output.getvalue()) | 156 #print(output.getvalue()) |
| 146 self.assertEqual(output.getvalue(), should_be) | 157 self.assertEqual(output.getvalue(), should_be) |
| 147 output = io.BytesIO() | 158 output = io.BytesIO() |
| 148 cl.request = MockNull() | 159 cl.request = MockNull() |
| 149 cl.request.wfile = output | 160 cl.request.wfile = output |
| 150 # call export version that outputs id numbers | 161 # call export version that outputs id numbers |
| 151 actions.ExportCSVWithIdAction(cl).handle() | 162 actions.ExportCSVWithIdAction(cl).handle() |
| 152 should_be = s2b('"id","title","status","keyword","assignedto","nosy","creation"\r\n' | 163 should_be = s2b('"id","title","status","keyword","assignedto","nosy","creation","messages"\r\n' |
| 153 '''"1","foo1","2","[]","4","['3', '4', '5']","2000-06-26.00:34:02"\r\n''' | 164 '''"1","foo1","2","[]","4","['3', '4', '5']","2000-06-26.00:34:02","[]"\r\n''' |
| 154 '''"2","bar2","1","['1', '2']","3","['3']","2000-06-26.00:34:02"\r\n''' | 165 '''"2","bar2","1","['1', '2']","3","['3']","2000-06-26.00:34:02","[]"\r\n''' |
| 155 '''"3","baz32","4","[]","None","[]","2000-06-26.00:34:02"\r\n''') | 166 '''"3","baz32","4","[]","None","['3', '4']","2000-06-26.00:34:02","['1', '2']"\r\n''') |
| 156 #print(should_be) | 167 #print(should_be) |
| 157 #print(output.getvalue()) | 168 #print(output.getvalue()) |
| 158 self.assertEqual(output.getvalue(), should_be) | 169 self.assertEqual(output.getvalue(), should_be) |
| 159 | 170 |
| 160 # reset the real date command | 171 # reset the real date command |
| 181 cl.request.wfile = output | 192 cl.request.wfile = output |
| 182 actions.ExportCSVWithIdAction(cl).handle() | 193 actions.ExportCSVWithIdAction(cl).handle() |
| 183 should_be = s2b('"id","title","status","keyword","assignedto","nosy"\r\n' | 194 should_be = s2b('"id","title","status","keyword","assignedto","nosy"\r\n' |
| 184 "\"2\",\"bar2\",\"1\",\"['1', '2']\",\"3\",\"['3']\"\r\n") | 195 "\"2\",\"bar2\",\"1\",\"['1', '2']\",\"3\",\"['3']\"\r\n") |
| 185 self.assertEqual(output.getvalue(), should_be) | 196 self.assertEqual(output.getvalue(), should_be) |
| 197 | |
| 198 # clean up from email log | |
| 199 if os.path.exists(SENDMAILDEBUG): | |
| 200 os.remove(SENDMAILDEBUG) | |
| 201 | |
| 186 | 202 |
| 187 class FormTestCase(FormTestParent, StringFragmentCmpHelper, testCsvExport, unittest.TestCase): | 203 class FormTestCase(FormTestParent, StringFragmentCmpHelper, testCsvExport, unittest.TestCase): |
| 188 | 204 |
| 189 def setUp(self): | 205 def setUp(self): |
| 190 FormTestParent.setUp(self) | 206 FormTestParent.setUp(self) |
