Mercurial > p > roundup > code
comparison test/test_cgi.py @ 6601:154f286061e2
Add date column to CSV output - test date display code.
Test date formatting code. Uses date.Date mock/override so creation
date is reproducible.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Wed, 26 Jan 2022 17:30:59 -0500 |
| parents | 65336409738c |
| children | da6c9050a79e |
comparison
equal
deleted
inserted
replaced
| 6600:65336409738c | 6601:154f286061e2 |
|---|---|
| 102 | 102 |
| 103 class testCsvExport(object): | 103 class testCsvExport(object): |
| 104 | 104 |
| 105 def testCSVExportBase(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,creation'}, |
| 108 nodeid=None, userid='1') | 108 nodeid=None, userid='1') |
| 109 cl.classname = 'issue' | 109 cl.classname = 'issue' |
| 110 | 110 |
| 111 demo_id=self.db.user.create(username='demo', address='demo@test.test', | 111 demo_id=self.db.user.create(username='demo', address='demo@test.test', |
| 112 roles='User', realname='demo') | 112 roles='User', realname='demo') |
| 113 key_id1=self.db.keyword.create(name='keyword1') | 113 key_id1=self.db.keyword.create(name='keyword1') |
| 114 key_id2=self.db.keyword.create(name='keyword2') | 114 key_id2=self.db.keyword.create(name='keyword2') |
| 115 | |
| 116 originalDate = date.Date | |
| 117 dummy=date.Date('2000-06-26.00:34:02.0') | |
| 118 # is a closure the best way to return a static Date object?? | |
| 119 def dummyDate(adate=None): | |
| 120 def dummyClosure(adate=None, translator=None): | |
| 121 return dummy | |
| 122 return dummyClosure | |
| 123 date.Date = dummyDate() | |
| 124 | |
| 115 self.db.issue.create(title='foo1', status='2', assignedto='4', nosy=['3',demo_id]) | 125 self.db.issue.create(title='foo1', status='2', assignedto='4', nosy=['3',demo_id]) |
| 116 self.db.issue.create(title='bar2', status='1', assignedto='3', keyword=[key_id1,key_id2]) | 126 self.db.issue.create(title='bar2', status='1', assignedto='3', keyword=[key_id1,key_id2]) |
| 117 self.db.issue.create(title='baz32', status='4') | 127 self.db.issue.create(title='baz32', status='4') |
| 118 output = io.BytesIO() | 128 output = io.BytesIO() |
| 119 cl.request = MockNull() | 129 cl.request = MockNull() |
| 120 cl.request.wfile = output | 130 cl.request.wfile = output |
| 121 # call export version that outputs names | 131 # call export version that outputs names |
| 122 actions.ExportCSVAction(cl).handle() | 132 actions.ExportCSVAction(cl).handle() |
| 123 should_be=(s2b('"id","title","status","keyword","assignedto","nosy"\r\n' | 133 should_be=(s2b('"id","title","status","keyword","assignedto","nosy","creation"\r\n' |
| 124 '"1","foo1","deferred","","Contrary, Mary","Bork, Chef;Contrary, Mary;demo"\r\n' | 134 '"1","foo1","deferred","","Contrary, Mary","Bork, Chef;Contrary, Mary;demo","2000-06-26 00:34"\r\n' |
| 125 '"2","bar2","unread","keyword1;keyword2","Bork, Chef","Bork, Chef"\r\n' | 135 '"2","bar2","unread","keyword1;keyword2","Bork, Chef","Bork, Chef","2000-06-26 00:34"\r\n' |
| 126 '"3","baz32","need-eg","","",""\r\n')) | 136 '"3","baz32","need-eg","","","","2000-06-26 00:34"\r\n')) |
| 137 | |
| 138 | |
| 127 #print(should_be) | 139 #print(should_be) |
| 128 print(output.getvalue()) | 140 #print(output.getvalue()) |
| 129 self.assertEqual(output.getvalue(), should_be) | 141 self.assertEqual(output.getvalue(), should_be) |
| 130 output = io.BytesIO() | 142 output = io.BytesIO() |
| 131 cl.request = MockNull() | 143 cl.request = MockNull() |
| 132 cl.request.wfile = output | 144 cl.request.wfile = output |
| 133 # call export version that outputs id numbers | 145 # call export version that outputs id numbers |
| 134 actions.ExportCSVWithIdAction(cl).handle() | 146 actions.ExportCSVWithIdAction(cl).handle() |
| 135 should_be = s2b('"id","title","status","keyword","assignedto","nosy"\r\n' | 147 should_be = s2b('"id","title","status","keyword","assignedto","nosy","creation"\r\n' |
| 136 "\"1\",\"foo1\",\"2\",\"[]\",\"4\",\"['3', '4', '5']\"\r\n" | 148 '''"1","foo1","2","[]","4","['3', '4', '5']","2000-06-26.00:34:02"\r\n''' |
| 137 "\"2\",\"bar2\",\"1\",\"['1', '2']\",\"3\",\"['3']\"\r\n" | 149 '''"2","bar2","1","['1', '2']","3","['3']","2000-06-26.00:34:02"\r\n''' |
| 138 '\"3\","baz32",\"4\","[]","None","[]"\r\n') | 150 '''"3","baz32","4","[]","None","[]","2000-06-26.00:34:02"\r\n''') |
| 139 #print(should_be) | 151 #print(should_be) |
| 140 #print(output.getvalue()) | 152 #print(output.getvalue()) |
| 141 self.assertEqual(output.getvalue(), should_be) | 153 self.assertEqual(output.getvalue(), should_be) |
| 154 | |
| 155 # reset the real date command | |
| 156 date.Date = originalDate | |
| 142 | 157 |
| 143 # test full text search | 158 # test full text search |
| 144 # call export version that outputs names | 159 # call export version that outputs names |
| 145 cl = self._make_client( | 160 cl = self._make_client( |
| 146 {'@columns': 'id,title,status,keyword,assignedto,nosy', | 161 {'@columns': 'id,title,status,keyword,assignedto,nosy', |
