Retrieved lost deleted_groups.mako template due to corrupted repo, polished several templates, fixed twilltestcase so new version of twill will work, add some functional tests.

This commit is contained in:
Greg Von Kuster
2008-08-26 15:36:39 -04:00
parent c02f382874
commit 1df6382c09
7 changed files with 299 additions and 93 deletions
+15 -3
View File
@@ -126,6 +126,8 @@ class Admin( BaseController ):
for row in q.execute():
users.append( ( row.user_id,
escape( row.user_email, entities ) ) )
if users:
users = sorted( users, key=operator.itemgetter(1) )
return trans.fill_template( '/admin/dataset_security/group_create.mako', users=users, msg=msg )
@web.expose
def new_group( self, trans, **kwd ):
@@ -169,8 +171,10 @@ class Admin( BaseController ):
return trans.show_error_message( no_privilege_msg )
params = util.Params( kwd )
msg = params.msg
group_id = params.group_id
group_id = int( params.group_id )
group_name = unescape( params.group_name, unentities )
group = galaxy.model.Group.get( group_id )
deleted = group.deleted
# This query retrieves all members of the group
q = sa.select( ( ( galaxy.model.User.table.c.id ).label( 'user_id' ),
( galaxy.model.User.table.c.email ).label( 'user_email' ) ),
@@ -182,9 +186,12 @@ class Admin( BaseController ):
for row in q.execute():
members.append( ( row.user_id,
escape( row.user_email, entities ) ) )
if members:
members = sorted( members, key=operator.itemgetter(1) )
return trans.fill_template( '/admin/dataset_security/group_members.mako',
group_id=group_id,
group_name=escape( group_name, entities ),
deleted=deleted,
members=members,
msg=msg )
@web.expose
@@ -204,6 +211,8 @@ class Admin( BaseController ):
for row in q.execute():
users.append( ( row.user_id,
escape( row.user_email, entities ) ) )
if users:
users = sorted( users, key=operator.itemgetter(1) )
# Then get members of the group
q = sa.select( ( ( galaxy.model.User.table.c.id ).label( 'user_id' ),
( galaxy.model.User.table.c.email ).label( 'user_email' ) ),
@@ -215,6 +224,8 @@ class Admin( BaseController ):
for row in q.execute():
members.append( ( row.user_id,
escape( row.user_email, entities ) ) )
if members:
members = sorted( members, key=operator.itemgetter(1) )
return trans.fill_template( '/admin/dataset_security/group_members_edit.mako',
group_id=group_id,
group_name=escape( group_name, entities ),
@@ -362,6 +373,8 @@ class Admin( BaseController ):
order_by = [ galaxy.model.Group.table.c.name ] )
groups = []
for row in q.execute():
total_datasets = 0
permitted_actions = []
# This 2nd query retrieves the number of datasets and dataset permitted_actions associated with each group
q2 = sa.select( ( ( galaxy.model.Group.table.c.id ).label( 'group_id' ),
( galaxy.model.GroupDatasetAssociation.table.c.permitted_actions ).label( 'permitted_actions' ),
@@ -376,8 +389,7 @@ class Admin( BaseController ):
for row2 in q2.execute():
total_datasets = row2.total_datasets
permitted_actions = []
# There may not yet be any GroupDatasetAssociations, in which case no
# actions will be found
# There may not yet be any GroupDatasetAssociations, in which case no actions will be found
if row2.permitted_actions:
for action in row2.permitted_actions:
permitted_actions.append( action.encode( 'ascii' ) )
@@ -0,0 +1,133 @@
<%inherit file="/base.mako"/>
<%
from galaxy.web.controllers.admin import entities, unentities
from xml.sax.saxutils import escape, unescape
%>
## Render a row
<%def name="render_row( group_name, group )">
<td><a href="${h.url_for( controller='admin', action='undelete_group', group_id=group[0] )}">Undelete</a></td>
<td>${group_name}</td>
<td>${group[2]}</td>
<td><a href="${h.url_for( controller='admin', action='group_members', group_id=group[0], group_name=group[1] )}">${group[3]}</a></td>
%if group[4] > 0:
<td><a href="${h.url_for( controller='admin', action='group_dataset_permitted_actions', group_id=group[0], group_name=group[1] )}">${group[4]}</a></td>
%else:
<td>${group[4]}</td>
%endif
<td>
%if len( group[5] ) == 1:
${group[5][0]}
%elif len( group[5] ) > 1:
%for da in group[5]:
${da}<br/>
%endfor
%endif
</td>
<td><a href="${h.url_for( controller='admin', action='purge_group', group_id=group[0] )}">Purge</a></td>
</%def>
<%def name="title()">Groups</%def>
<div class="toolForm">
<div class="form-row">
<a href="${h.url_for( controller='admin', action='libraries' )}">Libraries</a>&nbsp;&nbsp;|&nbsp;&nbsp;
<a href="${h.url_for( controller='admin', action='groups' )}">Groups</a>&nbsp;&nbsp;|&nbsp;&nbsp;
<tr><td><a href="${h.url_for( controller='admin', action='users' )}">Users</a></td></tr>
</div>
<table align="center" class="colored">
%if msg:
<tr><td colspan="7"><p class="ok_bgr">${msg}</p></td></tr>
%endif
%if len( groups ) == 0:
<tr><td colspan="7">There are no deleted Galaxy groups</td></tr>
%else:
<%
render_quick_find = len( groups ) > 50
ctr = 0
%>
%if render_quick_find:
<%
anchors = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
anchor_loc = 0
anchored = False
curr_anchor = 'A'
%>
<tr class="header"><td colspan="7"><center><a name="TOP">Deleted Galaxy Groups - Quick Find</a></td></center></tr>
<tr>
<td colspan="7">
<center>
|<a href="#A">A</a>|<a href="#B">B</a>|<a href="#C">C</a>|<a href="#D">D</a>|<a href="#E">E</a>|<a href="#F">F</a>
|<a href="#G">G</a>|<a href="#H">H</a>|<a href="#I">I</a>|<a href="#J">J</a>|<a href="#K">K</a>|<a href="#L">L</a>
|<a href="#M">M</a>|<a href="#N">N</a>|<a href="#O">O</a>|<a href="#P">P</a>|<a href="#Q">Q</a>|<a href="#R">R</a>
|<a href="#S">S</a>|<a href="#T">T</a>|<a href="#U">U</a>|<a href="#V">V</a>|<a href="#W">W</a>|<a href="#X">X</a>
|<a href="#Y">Y</a>|<a href="#Z">Z</a>
</center>
</td>
</tr>
%else:
<tr class="header"><td colspan="7"><center>Deleted Galaxy Groups</td></center></tr>
%endif
<tr class="header">
<td>&nbsp;</td>
<td>Group</td>
<td>Priority</td>
<td>Members</td>
<td>Datasets</td>
<td>Group Permitted Actions on Datasets</td>
<td>&nbsp;</td>
</tr>
%for group in groups:
<% group_name = unescape( group[1], unentities ) %>
%if render_quick_find and not group_name.upper().startswith( curr_anchor ):
<% anchored = False %>
%endif
<tr>
%if ctr % 2 == 1:
<div class="odd_row">
%endif
%if render_quick_find and group_name.upper().startswith( curr_anchor ):
%if not anchored:
<tr>
<td colspan="7" class=panel-body">
<a name="${curr_anchor}"></a>
<div style="float: right;"><a href="#TOP">quick find</a></div>
<% anchored = True %>
</td>
</tr>
%endif
${render_row( group_name, group )}
%elif render_quick_find:
%for anchor in anchors[ anchor_loc: ]:
%if group_name.upper().startswith( anchor ):
%if not anchored:
<tr>
<td colspan="7" class="panel-body">
<a name="${anchor}"></a>
<div style="float: right;"><a href="#TOP">quick find</a></div>
<%
curr_anchor = anchor
anchored = True
%>
</td>
</tr>
%endif
${render_row( group_name, group )}
<%
anchor_loc = anchors.index( anchor )
break
%>
%endif
%endfor
%else:
${render_row( group_name, group )}
%endif
%if ctr % 2 == 1:
</div>
%endif
<% ctr += 1 %>
</tr>
%endfor
%endif
</table>
</div>
@@ -27,62 +27,72 @@
%if len( users ) == 0:
<tr><td>There are no Galaxy users</td></tr>
%else:
<tr class="header"><td><a name="TOP">Add Members to Group - Quick Find</a></td></tr>
<%
render_quick_find = len( users ) > 50
%>
%if render_quick_find:
<%
anchors = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
anchor_loc = 0
anchored = False
curr_anchor = 'A'
%>
<tr class="header"><td><a name="TOP">Add Members to Group - Quick Find</a></td></tr>
<tr>
<td>
|<a href="#A">A</a>|<a href="#B">B</a>|<a href="#C">C</a>|<a href="#D">D</a>|<a href="#E">E</a>|<a href="#F">F</a>
|<a href="#G">G</a>|<a href="#H">H</a>|<a href="#I">I</a>|<a href="#J">J</a>|<a href="#K">K</a>|<a href="#L">L</a>
|<a href="#M">M</a>|<a href="#N">N</a>|<a href="#O">O</a>|<a href="#P">P</a>|<a href="#Q">Q</a>|<a href="#R">R</a>
|<a href="#S">S</a>|<a href="#T">T</a>|<a href="#U">U</a>|<a href="#V">V</a>|<a href="#W">W</a>|<a href="#X">X</a>
|<a href="#Y">Y</a>|<a href="#Z">Z</a>
</td>
</tr>
%else:
<tr class="header"><td>Add Members to Group</td></tr>
%endif
<tr>
<td>
|<a href="#A">A</a>|<a href="#B">B</a>|<a href="#C">C</a>|<a href="#D">D</a>|<a href="#E">E</a>|<a href="#F">F</a>
|<a href="#G">G</a>|<a href="#H">H</a>|<a href="#I">I</a>|<a href="#J">J</a>|<a href="#K">K</a>|<a href="#L">L</a>
|<a href="#M">M</a>|<a href="#N">N</a>|<a href="#O">O</a>|<a href="#P">P</a>|<a href="#Q">Q</a>|<a href="#R">R</a>
|<a href="#S">S</a>|<a href="#T">T</a>|<a href="#U">U</a>|<a href="#V">V</a>|<a href="#W">W</a>|<a href="#X">X</a>
|<a href="#Y">Y</a>|<a href="#Z">Z</a>
</td>
</tr>
<tr>
<td>
<%
ctr = 0
anchors = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
anchor_loc = 0
anchored = False
curr_anchor = 'A'
%>
%for user in users:
<% email = unescape( user[1], unentities ) %>
%if not email.upper().startswith( curr_anchor ):
%if render_quick_find and not email.upper().startswith( curr_anchor ):
<% anchored = False %>
%endif
%if ctr % 2 == 1:
<tr class="odd_row">
%else:
<tr class="tr">
%endif
<td>
%if email.upper().startswith( curr_anchor ):
%if not anchored:
<a name="${curr_anchor}"><hr/></a><br/>
<% anchored = True %>
%endif
<input type="checkbox" name="members" value="${user[0]}"/> ${email}
%else:
%for anchor in anchors[ anchor_loc: ]:
%if email.upper().startswith( anchor ):
%if not anchored:
<a name="${anchor}"><hr/></a><br/>
<tr>
<td>
%if render_quick_find and email.upper().startswith( curr_anchor ):
%if not anchored:
<a name="${curr_anchor}"></a>
<hr/>
<div style="float: right;"><a href="#TOP">quick find</a></div>
<br/>
<% anchored = True %>
%endif
<input type="checkbox" name="members" value="${user[0]}"/> ${email}
%elif render_quick_find:
%for anchor in anchors[ anchor_loc: ]:
%if email.upper().startswith( anchor ):
%if not anchored:
<a name="${anchor}"></a>
<hr/>
<div style="float: right;"><a href="#TOP">quick find</a></div>
<br/>
<%
curr_anchor = anchor
anchored = True
%>
%endif
<input type="checkbox" name="members" value="${user[0]}"/> ${email}
<%
curr_anchor = anchor
anchored = True
anchor_loc = anchors.index( anchor )
break
%>
%endif
<input type="checkbox" name="members" value="${user[0]}"/> ${email}
<%
anchor_loc = anchors.index( anchor )
break
%>
%endif
%endfor
%endif
</td>
<% ctr += 1 %>
%endfor
%else:
<input type="checkbox" name="members" value="${user[0]}"/> ${email}
%endif
</td>
</tr>
%endfor
</td>
</tr>
@@ -11,13 +11,19 @@
<div class="toolForm">
<div class="form-row">
<a href="${h.url_for( controller='admin', action='libraries' )}">Libraries</a>&nbsp;&nbsp;|&nbsp;&nbsp;
<a href="${h.url_for( controller='admin', action='groups' )}">Groups</a>&nbsp;&nbsp;|&nbsp;&nbsp;
%if deleted:
<a href="${h.url_for( controller='admin', action='deleted_groups' )}">Deleted Groups</a>&nbsp;&nbsp;|&nbsp;&nbsp;
%else:
<a href="${h.url_for( controller='admin', action='groups' )}">Groups</a>&nbsp;&nbsp;|&nbsp;&nbsp;
%endif
<tr><td><a href="${h.url_for( controller='admin', action='users' )}">Users</a></td></tr>
</div>
<div class="form-row">
<a href="${h.url_for( controller='admin', action='group_members_edit', group_id=group_id, group_name=group_name )}">Manage group membership</a>
<br/>
</div>
%if not deleted:
<div class="form-row">
<a href="${h.url_for( controller='admin', action='group_members_edit', group_id=group_id, group_name=group_name )}">Manage group membership</a>
<br/>
</div>
%endif
<div class="toolFormTitle">Members of Group '${gn}'</div>
<table align="center" class="colored">
%if msg:
@@ -69,6 +69,8 @@
</center>
</td>
</tr>
%else:
<tr class="header"><td colspan="7"><center>Galaxy Groups</td></center></tr>
%endif
<tr class="header">
<td>Group</td>
+48 -24
View File
@@ -7,7 +7,7 @@ from itertools import *
import twill
import twill.commands as tc
from twill.other_packages import ClientForm
from twill.other_packages._mechanize_dist import ClientForm
from elementtree import ElementTree
from galaxy.web.controllers.admin import entities, unentities
@@ -514,41 +514,65 @@ class TwillTestCase( unittest.TestCase ):
def create_group( self, name='New Test Group', priority='10' ):
"""Create a new group with 1 member"""
self.visit_url( "%s/admin/create_group" % self.url )
form = tc.show()
self.check_page_for_string( "Create Group" )
try:
tc.fv( "1", "name", name )
tc.fv( "1", "priority", priority )
tc.fv( "1", "members", "1" )
# twill version 0.9 still does not allow for easily testing forms that contain
# multiple fields with the same name ( e.g., check boxes ). We could attempt to determine
# the number of the field on the form and use it instead of the name of the field, but we
# would be forced to drop and recreate the database every time we test in order to ensure
# the fields will be the same on the form ( since it is dynamically rendered from the database ).
tc.fv( "1", "3", "1" ) # 1-based form field 3 is the 1st check box named 'members', user id 1 is test@bx.psu.edu
tc.submit( "create_group_button" )
except AssertionError, err:
errmsg = 'Exception caught attempting to create group: %s' % str( err )
raise AssertionError( errmsg )
self.home()
#def add_group_member( self, group_id='4', group_name='New+Test+Group' ):
# """Add a member to an existing group"""
# self.visit_page( "admin/group_members_edit?group_id=%s&group_name=%s" % ( group_id, group_name ) )
# self.check_page_for_string( 'Members of' )
# """
# TODO: we need to upgrade twill to be able to test checkbox entries. With the
# current version, the following test produces:
# ItemNotFoundError: cannot find value/label "2" in list control
# Weeding through Internet blogs, I found that some new version of twill has the
# following fv signature:
# def formvalue(formname, fieldname, value, fieldnum=-1)
# The fieldname param allows for multiple form feilds with the same name (checkboxes,
# multi-select lists, etc )
# """
# try:
# tc.fv( "1", "members", "2", 2 ) # user id 2 has email test2@bx.psu.edu
# tc.submit( "group_members_edit_button" )
# except AssertionError, err:
# errmsg = 'Exception caught attempting to create group: %s' % str( err )
# raise AssertionError( errmsg )
# self.home()
return form
def add_group_member( self, group_id='', group_name='' ):
"""Add a member to an existing group"""
# twill version 0.9 does not allow for this test
self.visit_url( "%s/admin/group_members_edit?group_id=%s&group_name=%s" % ( self.url, group_id, group_name ) )
self.check_page_for_string( 'Members of' )
try:
tc.fv( "1", "", "2" ) # 1-based form field 2 is the 2nd check box named 'members', user id 2 is test2@bx.psu.edu
tc.submit( "group_members_edit_button" )
except AssertionError, err:
errmsg = 'Exception caught attempting to create group: %s' % str( err )
raise AssertionError( errmsg )
self.home()
def mark_group_deleted( self, group_id='' ):
"""Delete an existing group"""
self.visit_url( "%s/admin/mark_group_deleted?group_id=%s" % ( self.url, group_id ) )
self.last_page()
self.check_page_for_string( 'The group has been marked as deleted' )
self.home()
def undelete_group( self, group_id='' ):
"""Undelete an existing group"""
self.visit_url( "%s/admin/undelete_group?group_id=%s" % ( self.url, group_id ) )
self.last_page()
self.check_page_for_string( 'The group has been marked as not deleted' )
self.home()
def purge_group( self, group=None ):
"""Purge an existing group"""
if not group.deleted:
self.mark_group_deleted( group_id=group.id )
group_id = str( group.id )
group_name = group.name.replace( ' ', '+' )
self.visit_url( "%s/admin/deleted_groups" % self.url )
self.check_page_for_string( '%s' % group.name )
self.visit_url( "%s/admin/purge_group?group_id=%s" % ( self.url, group_id ) )
self.last_page()
self.check_page_for_string( 'The group has been purged from the database' )
self.home()
# Library stuff
def create_library( self, name='New Test Library', description='New test Library Description' ):
def create_library( self, name='', description='' ):
"""Create a new library"""
name = name.replace( ' ', '+' )
description = description.replace( ' ', '+' )
try:
self.visit_url( "%s/admin/library?name=%s&description=%s&create_library=None" % ( self.url, name, description ) )
except AssertionError, err:
+33 -14
View File
@@ -1,3 +1,4 @@
import galaxy.model
from base.twilltestcase import TwillTestCase
s = 'You must have Galaxy administrator privileges to use this feature.'
@@ -52,21 +53,39 @@ class TestHistory( TwillTestCase ):
self.visit_page( "admin/groups" )
# the following should have been created when account was created.
self.check_page_for_string( 'test@bx.psu.edu private group' )
self.create_group()
self.create_group( name='New Test Group', priority='10' )
self.visit_page( "admin/groups" )
self.check_page_for_string( "group_name=New+Test+Group" )
# TODO: Upgrade twill, make sure the following works
# twill version 0.9 still does not allow for the following test
#def test_15_add_group_member( self ):
# #"""Testing adding a member to an existing group"""
# #self.add_group_member()
# #self.visit_page( 'group_name=New+Test+Group' )
# #self.check_page_for_string( 'test@bx.psu.edu' )
# # TODO: See self.add_group_member() problem
# #self.check_page_for_string( 'test2@bx.psu.edu' )
# TODO: make the following work
#def test_20_create_library( self ):
# """Testing creating new library"""
# self.create_library()
# self.visit_page( 'admin/libraries' )
# self.check_page_for_string( "New Test Library" )
# """Testing adding a member to an existing group"""
# group = galaxy.model.Group.get_by( name='New Test Group' )
# group_id = str( group.id )
# group_name = group.name.replace( ' ', '+' )
# self.add_group_member( group_id=group_id, group_name=group_name )
# self.visit_page( 'admin/group_members?group_id=%s&group_name=%s' % ( group_id, group_name ) )
# self.check_page_for_string( 'test@bx.psu.edu' )
# self.check_page_for_string( 'test2@bx.psu.edu' )
def test_20_delete_group( self ):
"""Testing deleting a group"""
self.visit_page( "admin/groups" )
self.check_page_for_string( "group_name=New+Test+Group" )
group = galaxy.model.Group.get_by( name='New Test Group' )
group_id = str( group.id )
self.mark_group_deleted( group_id=group_id )
def test_25_undelete_group( self ):
"""Testing undeleting a deleted group"""
group = galaxy.model.Group.get_by( name='New Test Group' )
group_id = str( group.id )
self.undelete_group( group_id=group_id )
def test_30_purge_group( self ):
"""Testing purging a group"""
group = galaxy.model.Group.get_by( name='New Test Group' )
self.purge_group( group=group )
def test_20_create_library( self ):
"""Testing creating new library"""
self.create_library( name='New Test Library', description='New test Library Description' )
self.visit_page( 'admin/libraries' )
self.check_page_for_string( "New Test Library" )