Mercurial > p > roundup > code
comparison test/test_cgi.py @ 5614:be99aa02c616
issue2550833 enhance the export csv action to include the keys for
liked items rather than id's. So for nosy list display usernames and
not numbers.
The original code was renamed and also made available. See change
document.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sat, 16 Feb 2019 15:17:21 -0500 |
| parents | 14a61eabcea8 |
| children | b3618882f906 |
comparison
equal
deleted
inserted
replaced
| 5612:da2decb6d0c7 | 5614:be99aa02c616 |
|---|---|
| 1505 self.assert_(not item.hasRole(' ')) | 1505 self.assert_(not item.hasRole(' ')) |
| 1506 self.db.user.set('1', roles='') | 1506 self.db.user.set('1', roles='') |
| 1507 self.assert_(not item.hasRole('')) | 1507 self.assert_(not item.hasRole('')) |
| 1508 | 1508 |
| 1509 def testCSVExport(self): | 1509 def testCSVExport(self): |
| 1510 cl = self._make_client({'@columns': 'id,name'}, nodeid=None, | 1510 cl = self._make_client( |
| 1511 userid='1') | 1511 {'@columns': 'id,title,status,keyword,assignedto,nosy'}, |
| 1512 cl.classname = 'status' | 1512 nodeid=None, userid='1') |
| 1513 cl.classname = 'issue' | |
| 1514 | |
| 1515 demo_id=self.db.user.create(username='demo', address='demo@test.test', | |
| 1516 roles='User', realname='demo') | |
| 1517 key_id1=self.db.keyword.create(name='keyword1') | |
| 1518 key_id2=self.db.keyword.create(name='keyword2') | |
| 1519 self.db.issue.create(title='foo1', status='2', assignedto='4', nosy=['3',demo_id]) | |
| 1520 self.db.issue.create(title='bar2', status='1', assignedto='3', keyword=[key_id1,key_id2]) | |
| 1521 self.db.issue.create(title='baz32', status='4') | |
| 1513 output = StringIO() | 1522 output = StringIO() |
| 1514 cl.request = MockNull() | 1523 cl.request = MockNull() |
| 1515 cl.request.wfile = output | 1524 cl.request.wfile = output |
| 1525 # call export version that outputs names | |
| 1516 actions.ExportCSVAction(cl).handle() | 1526 actions.ExportCSVAction(cl).handle() |
| 1517 self.assertEquals('id,name\r\n1,unread\r\n2,deferred\r\n3,chatting\r\n' | 1527 #print(output.getvalue()) |
| 1518 '4,need-eg\r\n5,in-progress\r\n6,testing\r\n7,done-cbb\r\n' | 1528 self.assertEquals('id,title,status,keyword,assignedto,nosy\r\n' |
| 1519 '8,resolved\r\n', | 1529 '1,foo1,deferred,,"Contrary, Mary","Bork, Chef;demo;Contrary, Mary"\r\n' |
| 1530 '2,bar2,unread,keyword1;keyword2,"Bork, Chef","Bork, Chef"\r\n' | |
| 1531 '3,baz32,need-eg,,,\r\n', | |
| 1532 | |
| 1533 output.getvalue()) | |
| 1534 output = StringIO() | |
| 1535 cl.request = MockNull() | |
| 1536 cl.request.wfile = output | |
| 1537 # call export version that outputs id numbers | |
| 1538 actions.ExportCSVWithIdAction(cl).handle() | |
| 1539 #print(output.getvalue()) | |
| 1540 self.assertEquals('id,title,status,keyword,assignedto,nosy\r\n' | |
| 1541 "1,foo1,2,[],4,\"['3', '5', '4']\"\r\n" | |
| 1542 "2,bar2,1,\"['1', '2']\",3,['3']\r\n" | |
| 1543 '3,baz32,4,[],None,[]\r\n', | |
| 1520 output.getvalue()) | 1544 output.getvalue()) |
| 1521 | 1545 |
| 1522 def testCSVExportBadColumnName(self): | 1546 def testCSVExportBadColumnName(self): |
| 1523 cl = self._make_client({'@columns': 'falseid,name'}, nodeid=None, | 1547 cl = self._make_client({'@columns': 'falseid,name'}, nodeid=None, |
| 1524 userid='1') | 1548 userid='1') |
| 1543 # they can determine if the column name is valid or not. | 1567 # they can determine if the column name is valid or not. |
| 1544 self.assertRaises(exceptions.NotFound, | 1568 self.assertRaises(exceptions.NotFound, |
| 1545 actions.ExportCSVAction(cl).handle) | 1569 actions.ExportCSVAction(cl).handle) |
| 1546 | 1570 |
| 1547 def testCSVExportFailPermissionValidColumn(self): | 1571 def testCSVExportFailPermissionValidColumn(self): |
| 1572 passwd=password.Password('foo') | |
| 1573 demo_id=self.db.user.create(username='demo', address='demo@test.test', | |
| 1574 roles='User', realname='demo', | |
| 1575 password=passwd) | |
| 1576 cl = self._make_client({'@columns': 'id,username,address,password'}, | |
| 1577 nodeid=None, userid=demo_id) | |
| 1578 cl.classname = 'user' | |
| 1579 output = StringIO() | |
| 1580 cl.request = MockNull() | |
| 1581 cl.request.wfile = output | |
| 1582 # used to be self.assertRaises(exceptions.Unauthorised, | |
| 1583 # but not acting like the column name is not found | |
| 1584 | |
| 1585 actions.ExportCSVAction(cl).handle() | |
| 1586 #print(output.getvalue()) | |
| 1587 self.assertEquals('id,username,address,password\r\n' | |
| 1588 '1,admin,[hidden],[hidden]\r\n' | |
| 1589 '2,anonymous,[hidden],[hidden]\r\n' | |
| 1590 '3,Chef,[hidden],[hidden]\r\n' | |
| 1591 '4,mary,[hidden],[hidden]\r\n' | |
| 1592 '5,demo,demo@test.test,%s\r\n'%(passwd), | |
| 1593 output.getvalue()) | |
| 1594 | |
| 1595 def testCSVExportWithId(self): | |
| 1596 cl = self._make_client({'@columns': 'id,name'}, nodeid=None, | |
| 1597 userid='1') | |
| 1598 cl.classname = 'status' | |
| 1599 output = StringIO() | |
| 1600 cl.request = MockNull() | |
| 1601 cl.request.wfile = output | |
| 1602 actions.ExportCSVWithIdAction(cl).handle() | |
| 1603 self.assertEquals('id,name\r\n1,unread\r\n2,deferred\r\n3,chatting\r\n' | |
| 1604 '4,need-eg\r\n5,in-progress\r\n6,testing\r\n7,done-cbb\r\n' | |
| 1605 '8,resolved\r\n', | |
| 1606 output.getvalue()) | |
| 1607 | |
| 1608 def testCSVExportWithIdBadColumnName(self): | |
| 1609 cl = self._make_client({'@columns': 'falseid,name'}, nodeid=None, | |
| 1610 userid='1') | |
| 1611 cl.classname = 'status' | |
| 1612 output = StringIO() | |
| 1613 cl.request = MockNull() | |
| 1614 cl.request.wfile = output | |
| 1615 self.assertRaises(exceptions.NotFound, | |
| 1616 actions.ExportCSVWithIdAction(cl).handle) | |
| 1617 | |
| 1618 def testCSVExportWithIdFailPermissionBadColumn(self): | |
| 1619 cl = self._make_client({'@columns': 'id,email,password'}, nodeid=None, | |
| 1620 userid='2') | |
| 1621 cl.classname = 'user' | |
| 1622 output = StringIO() | |
| 1623 cl.request = MockNull() | |
| 1624 cl.request.wfile = output | |
| 1625 # used to be self.assertRaises(exceptions.Unauthorised, | |
| 1626 # but not acting like the column name is not found | |
| 1627 # see issue2550755 - should this return Unauthorised? | |
| 1628 # The unauthorised user should never get to the point where | |
| 1629 # they can determine if the column name is valid or not. | |
| 1630 self.assertRaises(exceptions.NotFound, | |
| 1631 actions.ExportCSVWithIdAction(cl).handle) | |
| 1632 | |
| 1633 def testCSVExportWithIdFailPermissionValidColumn(self): | |
| 1548 cl = self._make_client({'@columns': 'id,address,password'}, nodeid=None, | 1634 cl = self._make_client({'@columns': 'id,address,password'}, nodeid=None, |
| 1549 userid='2') | 1635 userid='2') |
| 1550 cl.classname = 'user' | 1636 cl.classname = 'user' |
| 1551 output = StringIO() | 1637 output = StringIO() |
| 1552 cl.request = MockNull() | 1638 cl.request = MockNull() |
| 1553 cl.request.wfile = output | 1639 cl.request.wfile = output |
| 1554 # used to be self.assertRaises(exceptions.Unauthorised, | 1640 # used to be self.assertRaises(exceptions.Unauthorised, |
| 1555 # but not acting like the column name is not found | 1641 # but not acting like the column name is not found |
| 1556 self.assertRaises(exceptions.Unauthorised, | 1642 self.assertRaises(exceptions.Unauthorised, |
| 1557 actions.ExportCSVAction(cl).handle) | 1643 actions.ExportCSVWithIdAction(cl).handle) |
| 1558 | 1644 |
| 1559 class TemplateHtmlRendering(unittest.TestCase): | 1645 class TemplateHtmlRendering(unittest.TestCase): |
| 1560 ''' try to test the rendering code for tal ''' | 1646 ''' try to test the rendering code for tal ''' |
| 1561 def setUp(self): | 1647 def setUp(self): |
| 1562 self.dirname = '_test_template' | 1648 self.dirname = '_test_template' |
