Mercurial > p > roundup > code
comparison test/db_test_base.py @ 5110:87b0358790ed
Adding some tests for admin.py. Specifically for issue2550572: setting
nosy=+foo on multiple issues gives them all the same exact nosy
list.
To make this work had to change the admin.py code to use
"sys.stdout.write" in place of "print". In the test I now hijack
stdout.write following an existing example of this for admin's
import/export command that hijacks sys.stderr.write.
Also I corrected a misspelling in security.py. The word "everything"
was misspelled. It is not inside _() markers so I don't think it's
going to affect translation and grepping the locale subdir doesn't
show the original string.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Wed, 29 Jun 2016 18:35:19 -0400 |
| parents | e424987d294a |
| children | 8901cc4ef0e0 |
comparison
equal
deleted
inserted
replaced
| 5109:43a1f7fe39f5 | 5110:87b0358790ed |
|---|---|
| 23 import pytest | 23 import pytest |
| 24 from roundup.hyperdb import String, Password, Link, Multilink, Date, \ | 24 from roundup.hyperdb import String, Password, Link, Multilink, Date, \ |
| 25 Interval, DatabaseError, Boolean, Number, Node, Integer | 25 Interval, DatabaseError, Boolean, Number, Node, Integer |
| 26 from roundup.mailer import Mailer | 26 from roundup.mailer import Mailer |
| 27 from roundup import date, password, init, instance, configuration, \ | 27 from roundup import date, password, init, instance, configuration, \ |
| 28 roundupdb, i18n | 28 roundupdb, i18n, hyperdb |
| 29 from roundup.cgi.templating import HTMLItem | 29 from roundup.cgi.templating import HTMLItem |
| 30 | 30 |
| 31 from mocknull import MockNull | 31 from mocknull import MockNull |
| 32 | 32 |
| 33 config = configuration.CoreConfig() | 33 config = configuration.CoreConfig() |
| 1956 tool.verbose = False | 1956 tool.verbose = False |
| 1957 tool.do_import(['_test_export']) | 1957 tool.do_import(['_test_export']) |
| 1958 finally: | 1958 finally: |
| 1959 roundup.admin.sys = sys | 1959 roundup.admin.sys = sys |
| 1960 shutil.rmtree('_test_export') | 1960 shutil.rmtree('_test_export') |
| 1961 | |
| 1962 # test props from args parsing | |
| 1963 def testAdminOtherCommands(self): | |
| 1964 import roundup.admin | |
| 1965 from roundup.exceptions import UsageError | |
| 1966 | |
| 1967 # use the filtering setup to create a bunch of items | |
| 1968 ae, dummy1, dummy2 = self.filteringSetup() | |
| 1969 # create large field | |
| 1970 self.db.priority.create(name = 'X' * 500) | |
| 1971 self.db.config.CSV_FIELD_SIZE = 400 | |
| 1972 self.db.commit() | |
| 1973 | |
| 1974 eoutput = [] # stderr output | |
| 1975 soutput = [] # stdout output | |
| 1976 | |
| 1977 def stderrwrite(s): | |
| 1978 eoutput.append(s) | |
| 1979 def stdoutwrite(s): | |
| 1980 soutput.append(s) | |
| 1981 roundup.admin.sys = MockNull () | |
| 1982 try: | |
| 1983 roundup.admin.sys.stderr.write = stderrwrite | |
| 1984 roundup.admin.sys.stdout.write = stdoutwrite | |
| 1985 | |
| 1986 tool = roundup.admin.AdminTool() | |
| 1987 home = '.' | |
| 1988 tool.tracker_home = home | |
| 1989 tool.db = self.db | |
| 1990 tool.verbose = False | |
| 1991 tool.separator = "\n" | |
| 1992 tool.print_designator = True | |
| 1993 | |
| 1994 # test props_from_args | |
| 1995 self.assertRaises(UsageError, tool.props_from_args, "fullname") # invalid propname | |
| 1996 | |
| 1997 self.assertEqual(tool.props_from_args("="), {'': None}) # not sure this desired, I'd expect UsageError | |
| 1998 | |
| 1999 props = tool.props_from_args(["fullname=robert", "friends=+rouilj,+other", "key="]) | |
| 2000 self.assertEqual(props, {'fullname': 'robert', 'friends': '+rouilj,+other', 'key': None}) | |
| 2001 | |
| 2002 # test get_class() | |
| 2003 self.assertRaises(UsageError, tool.get_class, "bar") # invalid class | |
| 2004 | |
| 2005 # This writes to stdout, need to figure out how to redirect to a variable. | |
| 2006 # classhandle = tool.get_class("user") # valid class | |
| 2007 # FIXME there should be some test here | |
| 2008 | |
| 2009 issue_class_spec = tool.do_specification(["issue"]) | |
| 2010 self.assertEqual(soutput, ['files: <roundup.hyperdb.Multilink to "file">\n', | |
| 2011 'status: <roundup.hyperdb.Link to "status">\n', | |
| 2012 'feedback: <roundup.hyperdb.Link to "msg">\n', | |
| 2013 'spam: <roundup.hyperdb.Multilink to "msg">\n', | |
| 2014 'nosy: <roundup.hyperdb.Multilink to "user">\n', | |
| 2015 'title: <roundup.hyperdb.String>\n', | |
| 2016 'messages: <roundup.hyperdb.Multilink to "msg">\n', | |
| 2017 'priority: <roundup.hyperdb.Link to "priority">\n', | |
| 2018 'assignedto: <roundup.hyperdb.Link to "user">\n', | |
| 2019 'deadline: <roundup.hyperdb.Date>\n', | |
| 2020 'foo: <roundup.hyperdb.Interval>\n', | |
| 2021 'superseder: <roundup.hyperdb.Multilink to "issue">\n']) | |
| 2022 | |
| 2023 #userclassprop=tool.do_list(["mls"]) | |
| 2024 #tool.print_designator = False | |
| 2025 #userclassprop=tool.do_get(["realname","user1"]) | |
| 2026 | |
| 2027 # test do_create | |
| 2028 soutput[:] = [] # empty for next round of output | |
| 2029 userclass=tool.do_create(["issue", "title='title1 title'", "nosy=1,3"]) # should be issue 5 | |
| 2030 userclass=tool.do_create(["issue", "title='title2 title'", "nosy=2,3"]) # should be issue 6 | |
| 2031 self.assertEqual(soutput, ['5\n', '6\n']) | |
| 2032 # verify nosy setting | |
| 2033 props=self.db.issue.get('5', "nosy") | |
| 2034 self.assertEqual(props, ['1','3']) | |
| 2035 | |
| 2036 # test do_set using newly created issues | |
| 2037 # remove user 3 from issues | |
| 2038 # verifies issue2550572 | |
| 2039 userclass=tool.do_set(["issue5,issue6", "nosy=-3"]) | |
| 2040 # verify proper result | |
| 2041 props=self.db.issue.get('5', "nosy") | |
| 2042 self.assertEqual(props, ['1']) | |
| 2043 props=self.db.issue.get('6', "nosy") | |
| 2044 self.assertEqual(props, ['2']) | |
| 2045 | |
| 2046 # basic usage test. TODO add full output verification | |
| 2047 soutput[:] = [] # empty for next round of output | |
| 2048 tool.usage(message="Hello World") | |
| 2049 self.failUnless(soutput[0].startswith('Problem: Hello World'), None) | |
| 2050 | |
| 2051 # check security output | |
| 2052 soutput[:] = [] # empty for next round of output | |
| 2053 tool.do_security("Admin") | |
| 2054 self.assertEqual(soutput, [ 'New Web users get the Role "User"\n', | |
| 2055 'New Email users get the Role "User"\n', | |
| 2056 'Role "admin":\n', | |
| 2057 ' User may create everything (Create)\n', | |
| 2058 ' User may edit everything (Edit)\n', | |
| 2059 ' User may retire everything (Retire)\n', | |
| 2060 ' User may view everything (View)\n', | |
| 2061 ' User may access the web interface (Web Access)\n', | |
| 2062 ' User may manipulate user Roles through the web (Web Roles)\n', | |
| 2063 ' User may use the email interface (Email Access)\n', | |
| 2064 'Role "anonymous":\n', 'Role "user":\n', | |
| 2065 ' User is allowed to access msg (View for "msg" only)\n']) | |
| 2066 | |
| 2067 | |
| 2068 self.nukeAndCreate() | |
| 2069 tool = roundup.admin.AdminTool() | |
| 2070 tool.tracker_home = home | |
| 2071 tool.db = self.db | |
| 2072 tool.verbose = False | |
| 2073 finally: | |
| 2074 roundup.admin.sys = sys | |
| 1961 | 2075 |
| 1962 def testAddProperty(self): | 2076 def testAddProperty(self): |
| 1963 self.db.issue.create(title="spam", status='1') | 2077 self.db.issue.create(title="spam", status='1') |
| 1964 self.db.commit() | 2078 self.db.commit() |
| 1965 | 2079 |
