Mercurial > p > roundup > code
comparison test/test_cgi.py @ 5786:68b0c1767b50
Replace assertEquals (depricated) with assertEqual.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Mon, 10 Jun 2019 20:14:14 -0400 |
| parents | 3f00269f3297 |
| children | 95a366d46065 |
comparison
equal
deleted
inserted
replaced
| 5785:1dffff48979f | 5786:68b0c1767b50 |
|---|---|
| 824 pt.pt_edit(page_template, 'application/xml') | 824 pt.pt_edit(page_template, 'application/xml') |
| 825 | 825 |
| 826 cl = self.setupClient({ }, 'issue', | 826 cl = self.setupClient({ }, 'issue', |
| 827 env_addon = {'HTTP_REFERER': 'http://whoami.com/path/'}) | 827 env_addon = {'HTTP_REFERER': 'http://whoami.com/path/'}) |
| 828 out = pt.render(cl, 'issue', MockNull()) | 828 out = pt.render(cl, 'issue', MockNull()) |
| 829 self.assertEquals(out, '<?xml version="1.0" encoding="UTF-8"?><feed\n xmlns="http://www.w3.org/2005/Atom"/>\n') | 829 self.assertEqual(out, '<?xml version="1.0" encoding="UTF-8"?><feed\n xmlns="http://www.w3.org/2005/Atom"/>\n') |
| 830 | 830 |
| 831 def testCsrfProtection(self): | 831 def testCsrfProtection(self): |
| 832 # need to set SENDMAILDEBUG to prevent | 832 # need to set SENDMAILDEBUG to prevent |
| 833 # downstream issue when email is sent on successful | 833 # downstream issue when email is sent on successful |
| 834 # issue creation. Also delete the file afterwards | 834 # issue creation. Also delete the file afterwards |
| 1501 cl.serve_static_file,"missing.css") | 1501 cl.serve_static_file,"missing.css") |
| 1502 | 1502 |
| 1503 # TEMPLATES dir is searched by default. So this file exists. | 1503 # TEMPLATES dir is searched by default. So this file exists. |
| 1504 # Check the returned values. | 1504 # Check the returned values. |
| 1505 cl.serve_static_file("issue.index.html") | 1505 cl.serve_static_file("issue.index.html") |
| 1506 self.assertEquals(output[0][1], "text/html") | 1506 self.assertEqual(output[0][1], "text/html") |
| 1507 self.assertEquals(output[0][3], "_test_cgi_form/html/issue.index.html") | 1507 self.assertEqual(output[0][3], "_test_cgi_form/html/issue.index.html") |
| 1508 del output[0] # reset output buffer | 1508 del output[0] # reset output buffer |
| 1509 | 1509 |
| 1510 # stop searching TEMPLATES for the files. | 1510 # stop searching TEMPLATES for the files. |
| 1511 cl.instance.config['STATIC_FILES'] = '-' | 1511 cl.instance.config['STATIC_FILES'] = '-' |
| 1512 # previously found file should not be found | 1512 # previously found file should not be found |
| 1514 cl.serve_static_file,"issue.index.html") | 1514 cl.serve_static_file,"issue.index.html") |
| 1515 | 1515 |
| 1516 # explicitly allow html directory | 1516 # explicitly allow html directory |
| 1517 cl.instance.config['STATIC_FILES'] = 'html -' | 1517 cl.instance.config['STATIC_FILES'] = 'html -' |
| 1518 cl.serve_static_file("issue.index.html") | 1518 cl.serve_static_file("issue.index.html") |
| 1519 self.assertEquals(output[0][1], "text/html") | 1519 self.assertEqual(output[0][1], "text/html") |
| 1520 self.assertEquals(output[0][3], "_test_cgi_form/html/issue.index.html") | 1520 self.assertEqual(output[0][3], "_test_cgi_form/html/issue.index.html") |
| 1521 del output[0] # reset output buffer | 1521 del output[0] # reset output buffer |
| 1522 | 1522 |
| 1523 # set the list of files and do not look at the templates directory | 1523 # set the list of files and do not look at the templates directory |
| 1524 cl.instance.config['STATIC_FILES'] = 'detectors extensions - ' | 1524 cl.instance.config['STATIC_FILES'] = 'detectors extensions - ' |
| 1525 | 1525 |
| 1526 # find file in first directory | 1526 # find file in first directory |
| 1527 cl.serve_static_file("messagesummary.py") | 1527 cl.serve_static_file("messagesummary.py") |
| 1528 self.assertEquals(output[0][1], "text/x-python") | 1528 self.assertEqual(output[0][1], "text/x-python") |
| 1529 self.assertEquals(output[0][3], "_test_cgi_form/detectors/messagesummary.py") | 1529 self.assertEqual(output[0][3], "_test_cgi_form/detectors/messagesummary.py") |
| 1530 del output[0] # reset output buffer | 1530 del output[0] # reset output buffer |
| 1531 | 1531 |
| 1532 # find file in second directory | 1532 # find file in second directory |
| 1533 cl.serve_static_file("README.txt") | 1533 cl.serve_static_file("README.txt") |
| 1534 self.assertEquals(output[0][1], "text/plain") | 1534 self.assertEqual(output[0][1], "text/plain") |
| 1535 self.assertEquals(output[0][3], "_test_cgi_form/extensions/README.txt") | 1535 self.assertEqual(output[0][3], "_test_cgi_form/extensions/README.txt") |
| 1536 del output[0] # reset output buffer | 1536 del output[0] # reset output buffer |
| 1537 | 1537 |
| 1538 # make sure an embedded - ends the searching. | 1538 # make sure an embedded - ends the searching. |
| 1539 cl.instance.config['STATIC_FILES'] = ' detectors - extensions ' | 1539 cl.instance.config['STATIC_FILES'] = ' detectors - extensions ' |
| 1540 self.assertRaises(NotFound, cl.serve_static_file, "README.txt") | 1540 self.assertRaises(NotFound, cl.serve_static_file, "README.txt") |
| 1544 | 1544 |
| 1545 # create an empty README.txt in the first directory | 1545 # create an empty README.txt in the first directory |
| 1546 f = open('_test_cgi_form/detectors/README.txt', 'a').close() | 1546 f = open('_test_cgi_form/detectors/README.txt', 'a').close() |
| 1547 # find file now in first directory | 1547 # find file now in first directory |
| 1548 cl.serve_static_file("README.txt") | 1548 cl.serve_static_file("README.txt") |
| 1549 self.assertEquals(output[0][1], "text/plain") | 1549 self.assertEqual(output[0][1], "text/plain") |
| 1550 self.assertEquals(output[0][3], "_test_cgi_form/detectors/README.txt") | 1550 self.assertEqual(output[0][3], "_test_cgi_form/detectors/README.txt") |
| 1551 del output[0] # reset output buffer | 1551 del output[0] # reset output buffer |
| 1552 | 1552 |
| 1553 cl.instance.config['STATIC_FILES'] = ' detectors extensions ' | 1553 cl.instance.config['STATIC_FILES'] = ' detectors extensions ' |
| 1554 # make sure lack of trailing - allows searching TEMPLATES | 1554 # make sure lack of trailing - allows searching TEMPLATES |
| 1555 cl.serve_static_file("issue.index.html") | 1555 cl.serve_static_file("issue.index.html") |
| 1556 self.assertEquals(output[0][1], "text/html") | 1556 self.assertEqual(output[0][1], "text/html") |
| 1557 self.assertEquals(output[0][3], "_test_cgi_form/html/issue.index.html") | 1557 self.assertEqual(output[0][3], "_test_cgi_form/html/issue.index.html") |
| 1558 del output[0] # reset output buffer | 1558 del output[0] # reset output buffer |
| 1559 | 1559 |
| 1560 # Make STATIC_FILES a single element. | 1560 # Make STATIC_FILES a single element. |
| 1561 cl.instance.config['STATIC_FILES'] = 'detectors' | 1561 cl.instance.config['STATIC_FILES'] = 'detectors' |
| 1562 # find file now in first directory | 1562 # find file now in first directory |
| 1563 cl.serve_static_file("messagesummary.py") | 1563 cl.serve_static_file("messagesummary.py") |
| 1564 self.assertEquals(output[0][1], "text/x-python") | 1564 self.assertEqual(output[0][1], "text/x-python") |
| 1565 self.assertEquals(output[0][3], "_test_cgi_form/detectors/messagesummary.py") | 1565 self.assertEqual(output[0][3], "_test_cgi_form/detectors/messagesummary.py") |
| 1566 del output[0] # reset output buffer | 1566 del output[0] # reset output buffer |
| 1567 | 1567 |
| 1568 # make sure files found in subdirectory | 1568 # make sure files found in subdirectory |
| 1569 os.mkdir('_test_cgi_form/detectors/css') | 1569 os.mkdir('_test_cgi_form/detectors/css') |
| 1570 f = open('_test_cgi_form/detectors/css/README.css', 'a').close() | 1570 f = open('_test_cgi_form/detectors/css/README.css', 'a').close() |
| 1571 # use subdir in filename | 1571 # use subdir in filename |
| 1572 cl.serve_static_file("css/README.css") | 1572 cl.serve_static_file("css/README.css") |
| 1573 self.assertEquals(output[0][1], "text/css") | 1573 self.assertEqual(output[0][1], "text/css") |
| 1574 self.assertEquals(output[0][3], "_test_cgi_form/detectors/css/README.css") | 1574 self.assertEqual(output[0][3], "_test_cgi_form/detectors/css/README.css") |
| 1575 del output[0] # reset output buffer | 1575 del output[0] # reset output buffer |
| 1576 | 1576 |
| 1577 | 1577 |
| 1578 # use subdir in static files path | 1578 # use subdir in static files path |
| 1579 cl.instance.config['STATIC_FILES'] = 'detectors html/css' | 1579 cl.instance.config['STATIC_FILES'] = 'detectors html/css' |
| 1580 os.mkdir('_test_cgi_form/html/css') | 1580 os.mkdir('_test_cgi_form/html/css') |
| 1581 f = open('_test_cgi_form/html/css/README1.css', 'a').close() | 1581 f = open('_test_cgi_form/html/css/README1.css', 'a').close() |
| 1582 cl.serve_static_file("README1.css") | 1582 cl.serve_static_file("README1.css") |
| 1583 self.assertEquals(output[0][1], "text/css") | 1583 self.assertEqual(output[0][1], "text/css") |
| 1584 self.assertEquals(output[0][3], "_test_cgi_form/html/css/README1.css") | 1584 self.assertEqual(output[0][3], "_test_cgi_form/html/css/README1.css") |
| 1585 del output[0] # reset output buffer | 1585 del output[0] # reset output buffer |
| 1586 | 1586 |
| 1587 | 1587 |
| 1588 def testRoles(self): | 1588 def testRoles(self): |
| 1589 cl = self._make_client({}) | 1589 cl = self._make_client({}) |
| 1633 cl.request = MockNull() | 1633 cl.request = MockNull() |
| 1634 cl.request.wfile = output | 1634 cl.request.wfile = output |
| 1635 # call export version that outputs id numbers | 1635 # call export version that outputs id numbers |
| 1636 actions.ExportCSVWithIdAction(cl).handle() | 1636 actions.ExportCSVWithIdAction(cl).handle() |
| 1637 print(output.getvalue()) | 1637 print(output.getvalue()) |
| 1638 self.assertEquals('id,title,status,keyword,assignedto,nosy\r\n' | 1638 self.assertEqual('id,title,status,keyword,assignedto,nosy\r\n' |
| 1639 "1,foo1,2,[],4,\"['3', '4', '5']\"\r\n" | 1639 "1,foo1,2,[],4,\"['3', '4', '5']\"\r\n" |
| 1640 "2,bar2,1,\"['1', '2']\",3,['3']\r\n" | 1640 "2,bar2,1,\"['1', '2']\",3,['3']\r\n" |
| 1641 '3,baz32,4,[],None,[]\r\n', | 1641 '3,baz32,4,[],None,[]\r\n', |
| 1642 output.getvalue()) | 1642 output.getvalue()) |
| 1643 | 1643 |
| 1680 # used to be self.assertRaises(exceptions.Unauthorised, | 1680 # used to be self.assertRaises(exceptions.Unauthorised, |
| 1681 # but not acting like the column name is not found | 1681 # but not acting like the column name is not found |
| 1682 | 1682 |
| 1683 actions.ExportCSVAction(cl).handle() | 1683 actions.ExportCSVAction(cl).handle() |
| 1684 #print(output.getvalue()) | 1684 #print(output.getvalue()) |
| 1685 self.assertEquals('id,username,address,password\r\n' | 1685 self.assertEqual('id,username,address,password\r\n' |
| 1686 '1,admin,[hidden],[hidden]\r\n' | 1686 '1,admin,[hidden],[hidden]\r\n' |
| 1687 '2,anonymous,[hidden],[hidden]\r\n' | 1687 '2,anonymous,[hidden],[hidden]\r\n' |
| 1688 '3,Chef,[hidden],[hidden]\r\n' | 1688 '3,Chef,[hidden],[hidden]\r\n' |
| 1689 '4,mary,[hidden],[hidden]\r\n' | 1689 '4,mary,[hidden],[hidden]\r\n' |
| 1690 '5,demo,demo@test.test,%s\r\n'%(passwd), | 1690 '5,demo,demo@test.test,%s\r\n'%(passwd), |
| 1696 cl.classname = 'status' | 1696 cl.classname = 'status' |
| 1697 output = StringIO() | 1697 output = StringIO() |
| 1698 cl.request = MockNull() | 1698 cl.request = MockNull() |
| 1699 cl.request.wfile = output | 1699 cl.request.wfile = output |
| 1700 actions.ExportCSVWithIdAction(cl).handle() | 1700 actions.ExportCSVWithIdAction(cl).handle() |
| 1701 self.assertEquals('id,name\r\n1,unread\r\n2,deferred\r\n3,chatting\r\n' | 1701 self.assertEqual('id,name\r\n1,unread\r\n2,deferred\r\n3,chatting\r\n' |
| 1702 '4,need-eg\r\n5,in-progress\r\n6,testing\r\n7,done-cbb\r\n' | 1702 '4,need-eg\r\n5,in-progress\r\n6,testing\r\n7,done-cbb\r\n' |
| 1703 '8,resolved\r\n', | 1703 '8,resolved\r\n', |
| 1704 output.getvalue()) | 1704 output.getvalue()) |
| 1705 | 1705 |
| 1706 def testCSVExportWithIdBadColumnName(self): | 1706 def testCSVExportWithIdBadColumnName(self): |
| 2048 os.remove(subdir + "/user.item.html") | 2048 os.remove(subdir + "/user.item.html") |
| 2049 os.symlink("../user.item.html", subdir + "/user.item.xml") | 2049 os.symlink("../user.item.html", subdir + "/user.item.xml") |
| 2050 | 2050 |
| 2051 # template check works | 2051 # template check works |
| 2052 r = t.selectTemplate("user", "subdir/item") | 2052 r = t.selectTemplate("user", "subdir/item") |
| 2053 self.assertEquals("subdir/user.item", r) | 2053 self.assertEqual("subdir/user.item", r) |
| 2054 | 2054 |
| 2055 # vim: set filetype=python sts=4 sw=4 et si : | 2055 # vim: set filetype=python sts=4 sw=4 et si : |
