comparison roundup/admin.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 ca3e56590fcd
children 6ae426092d7d
comparison
equal deleted inserted replaced
5109:43a1f7fe39f5 5110:87b0358790ed
105 def usage(self, message=''): 105 def usage(self, message=''):
106 """ Display a simple usage message. 106 """ Display a simple usage message.
107 """ 107 """
108 if message: 108 if message:
109 message = _('Problem: %(message)s\n\n')%locals() 109 message = _('Problem: %(message)s\n\n')%locals()
110 print _("""%(message)sUsage: roundup-admin [options] [<command> <arguments>] 110 sys.stdout.write( _("""%(message)sUsage: roundup-admin [options] [<command> <arguments>]
111 111
112 Options: 112 Options:
113 -i instance home -- specify the issue tracker "home directory" to administer 113 -i instance home -- specify the issue tracker "home directory" to administer
114 -u -- the user[:password] to use for commands 114 -u -- the user[:password] to use for commands
115 -d -- print full designators not just class id numbers 115 -d -- print full designators not just class id numbers
126 Help: 126 Help:
127 roundup-admin -h 127 roundup-admin -h
128 roundup-admin help -- this help 128 roundup-admin help -- this help
129 roundup-admin help <command> -- command-specific help 129 roundup-admin help <command> -- command-specific help
130 roundup-admin help all -- all available help 130 roundup-admin help all -- all available help
131 """)%locals() 131 """)%locals())
132 self.help_commands() 132 self.help_commands()
133 133
134 def help_commands(self): 134 def help_commands(self):
135 """List the commands available with their help summary. 135 """List the commands available with their help summary.
136 """ 136 """
137 print _('Commands:'), 137 sys.stdout.write( _('Commands: '))
138 commands = [''] 138 commands = ['']
139 for command in self.commands.itervalues(): 139 for command in self.commands.itervalues():
140 h = _(command.__doc__).split('\n')[0] 140 h = _(command.__doc__).split('\n')[0]
141 commands.append(' '+h[7:]) 141 commands.append(' '+h[7:])
142 commands.sort() 142 commands.sort()
143 commands.append(_( 143 commands.append(_(
144 """Commands may be abbreviated as long as the abbreviation 144 """Commands may be abbreviated as long as the abbreviation
145 matches only one command, e.g. l == li == lis == list.""")) 145 matches only one command, e.g. l == li == lis == list."""))
146 print '\n'.join(commands) 146 sys.stdout.write('\n'.join(commands) + '\n\n')
147 print
148 147
149 def help_commands_html(self, indent_re=re.compile(r'^(\s+)\S+')): 148 def help_commands_html(self, indent_re=re.compile(r'^(\s+)\S+')):
150 """ Produce an HTML command list. 149 """ Produce an HTML command list.
151 """ 150 """
152 commands = sorted(self.commands.itervalues(), 151 commands = sorted(self.commands.itervalues(),
734 # get the key property 733 # get the key property
735 keyprop = cl.getkey() 734 keyprop = cl.getkey()
736 for key in cl.properties: 735 for key in cl.properties:
737 value = cl.properties[key] 736 value = cl.properties[key]
738 if keyprop == key: 737 if keyprop == key:
739 print _('%(key)s: %(value)s (key property)')%locals() 738 sys.stdout.write( _('%(key)s: %(value)s (key property)\n')%locals() )
740 else: 739 else:
741 print _('%(key)s: %(value)s')%locals() 740 sys.stdout.write( _('%(key)s: %(value)s\n')%locals() )
742 741
743 def do_display(self, args): 742 def do_display(self, args):
744 ''"""Usage: display designator[,designator]* 743 ''"""Usage: display designator[,designator]*
745 Show the property values for the given node(s). 744 Show the property values for the given node(s).
746 745
827 raise UsageError(_('you must provide the "%(propname)s" ' 826 raise UsageError(_('you must provide the "%(propname)s" '
828 'property.')%locals()) 827 'property.')%locals())
829 828
830 # do the actual create 829 # do the actual create
831 try: 830 try:
832 print cl.create(**props) 831 sys.stdout.write(cl.create(**props) + '\n')
833 except (TypeError, IndexError, ValueError), message: 832 except (TypeError, IndexError, ValueError), message:
834 raise UsageError(message) 833 raise UsageError(message)
835 self.db_uncommitted = True 834 self.db_uncommitted = True
836 return 0 835 return 0
837 836
1352 if len(args) == 1: 1351 if len(args) == 1:
1353 role = args[0] 1352 role = args[0]
1354 try: 1353 try:
1355 roles = [(args[0], self.db.security.role[args[0]])] 1354 roles = [(args[0], self.db.security.role[args[0]])]
1356 except KeyError: 1355 except KeyError:
1357 print _('No such Role "%(role)s"')%locals() 1356 sys.stdout.write( _('No such Role "%(role)s"\n')%locals() )
1358 return 1 1357 return 1
1359 else: 1358 else:
1360 roles = list(self.db.security.role.items()) 1359 roles = list(self.db.security.role.items())
1361 role = self.db.config.NEW_WEB_USER_ROLES 1360 role = self.db.config.NEW_WEB_USER_ROLES
1362 if ',' in role: 1361 if ',' in role:
1363 print _('New Web users get the Roles "%(role)s"')%locals() 1362 sys.stdout.write( _('New Web users get the Roles "%(role)s"\n')%locals() )
1364 else: 1363 else:
1365 print _('New Web users get the Role "%(role)s"')%locals() 1364 sys.stdout.write( _('New Web users get the Role "%(role)s"\n')%locals() )
1366 role = self.db.config.NEW_EMAIL_USER_ROLES 1365 role = self.db.config.NEW_EMAIL_USER_ROLES
1367 if ',' in role: 1366 if ',' in role:
1368 print _('New Email users get the Roles "%(role)s"')%locals() 1367 sys.stdout.write( _('New Email users get the Roles "%(role)s"\n')%locals() )
1369 else: 1368 else:
1370 print _('New Email users get the Role "%(role)s"')%locals() 1369 sys.stdout.write( _('New Email users get the Role "%(role)s"\n')%locals() )
1371 roles.sort() 1370 roles.sort()
1372 for rolename, role in roles: 1371 for rolename, role in roles:
1373 print _('Role "%(name)s":')%role.__dict__ 1372 sys.stdout.write( _('Role "%(name)s":\n')%role.__dict__ )
1374 for permission in role.permissions: 1373 for permission in role.permissions:
1375 d = permission.__dict__ 1374 d = permission.__dict__
1376 if permission.klass: 1375 if permission.klass:
1377 if permission.properties: 1376 if permission.properties:
1378 print _(' %(description)s (%(name)s for "%(klass)s"' 1377 sys.stdout.write( _(' %(description)s (%(name)s for "%(klass)s"' +
1379 ': %(properties)s only)')%d 1378 ': %(properties)s only)\n')%d )
1380 else: 1379 else:
1381 print _(' %(description)s (%(name)s for "%(klass)s" ' 1380 sys.stdout.write( _(' %(description)s (%(name)s for "%(klass)s" ' +
1382 'only)')%d 1381 'only)\n')%d )
1383 else: 1382 else:
1384 print _(' %(description)s (%(name)s)')%d 1383 sys.stdout.write( _(' %(description)s (%(name)s)\n')%d )
1385 return 0 1384 return 0
1386 1385
1387 1386
1388 def do_migrate(self, args): 1387 def do_migrate(self, args):
1389 ''"""Usage: migrate 1388 ''"""Usage: migrate

Roundup Issue Tracker: http://roundup-tracker.org/