Rewrite the functional tests that cover all Galaxy forms related behavior. Clean up / fix bugs in several sample run request templates. Fix a bug introduced in change set a8cdece11998 which incorrectly generated selected options in a select list in the data library framework.

This commit is contained in:
Greg Von Kuster
2010-09-22 16:38:49 -04:00
parent 7dcc8b5f08
commit 858349cb63
12 changed files with 966 additions and 987 deletions
+1 -3
View File
@@ -107,9 +107,7 @@ class Forms( BaseController ):
return trans.fill_template( '/admin/forms/show_form_read_only.mako',
form=fdc.latest_form )
def __form_types_widget(self, trans, selected='none'):
form_type_selectbox = SelectField( 'form_type_selectbox',
refresh_on_change=True,
refresh_on_change_values=[trans.app.model.FormDefinition.types.SAMPLE] )
form_type_selectbox = SelectField( 'form_type_selectbox' )
if selected == 'none':
form_type_selectbox.add_option('Select one', 'none', selected=True)
else:
+5 -4
View File
@@ -906,7 +906,7 @@ class LibraryCommon( BaseController, UsesFormDefinitionWidgets ):
else:
action = web.url_for( controller='library_common', action='upload_library_dataset' )
upload_option_select_list = self._build_upload_option_select_list( trans, upload_option )
roles_select_list = self._build_roles_select_list( trans, cntrller, library, roles )
roles_select_list = self._build_roles_select_list( trans, cntrller, library, util.listify( roles ) )
return trans.fill_template( '/library/common/upload.mako',
cntrller=cntrller,
upload_option_select_list=upload_option_select_list,
@@ -1252,7 +1252,7 @@ class LibraryCommon( BaseController, UsesFormDefinitionWidgets ):
trans.sa_session.refresh( history )
action = 'add_history_datasets_to_library'
upload_option_select_list = self._build_upload_option_select_list( trans, upload_option )
roles_select_list = self._build_roles_select_list( trans, cntrller, library, roles )
roles_select_list = self._build_roles_select_list( trans, cntrller, library, util.listify( roles ) )
return trans.fill_template( "/library/common/upload.mako",
cntrller=cntrller,
upload_option_select_list=upload_option_select_list,
@@ -1273,7 +1273,7 @@ class LibraryCommon( BaseController, UsesFormDefinitionWidgets ):
ldda_message=ldda_message,
message=message,
status=status )
def _build_roles_select_list( self, trans, cntrller, library, selected_roles ):
def _build_roles_select_list( self, trans, cntrller, library, selected_role_ids=[] ):
# Get the list of legitimate roles to display on the upload form. If the library is public,
# all active roles are legitimate. If the library is restricted by the LIBRARY_ACCESS permission, only
# the set of all roles associated with users that have that permission are legitimate.
@@ -1283,7 +1283,8 @@ class LibraryCommon( BaseController, UsesFormDefinitionWidgets ):
# were selected before refresh_on_change, if one occurred.
roles_select_list = SelectField( "roles", multiple="true", size="5" )
for role in legitimate_roles:
roles_select_list.add_option( text=role.name, value=str( role.id ), selected=str( role.id ) in selected_roles )
selected = str( role.id ) in selected_role_ids
roles_select_list.add_option( text=role.name, value=str( role.id ), selected=selected )
return roles_select_list
else:
return None
+17 -14
View File
@@ -158,6 +158,8 @@ class RequestsCommon( BaseController, UsesFormDefinitionWidgets ):
for user in user_list:
if not user.deleted:
user_ids.append(str(user.id))
# gvk - 9/22/10: TODO: why does select_user require a refresh_on_change? Nothing in the
# code is apparent as to why this is done.
select_user = SelectField('select_user',
refresh_on_change=True,
refresh_on_change_values=user_ids[1:])
@@ -830,24 +832,24 @@ class RequestsCommon( BaseController, UsesFormDefinitionWidgets ):
current_samples, details, edit_mode, libraries = self.__update_samples( trans, request, **kwd )
selected_samples = self.__selected_samples(trans, request, **kwd)
sample_ops = self.__sample_operation_selectbox(trans, request,**kwd)
if params.get('select_sample_operation', 'none') != 'none' and not len(selected_samples):
if params.get( 'select_sample_operation', False ) and not selected_samples:
return trans.response.send_redirect( web.url_for( controller=cntrller,
action='list',
operation='show',
id=trans.security.encode_id(request.id),
status='error',
message='Select at least one sample before selecting an operation.' ))
if params.get('import_samples_button', False) == 'Import samples':
if params.get( 'import_samples_button', False ):
return self.__import_samples(trans, cntrller, request, current_samples, details, libraries, **kwd)
elif params.get('add_sample_button', False) == 'Add New':
elif params.get('add_sample_button', False ):
# add an empty or filled sample
# if the user has selected a sample no. to copy then copy the contents
# of the src sample to the new sample else an empty sample
src_sample_index = int(params.get( 'copy_sample', -1 ))
src_sample_index = int(params.get( 'copy_sample', -1 ) )
# get the number of new copies of the src sample
num_sample_to_copy = int(params.get( 'num_sample_to_copy', 1 ))
num_sample_to_copy = int( params.get( 'num_sample_to_copy', 1 ) )
if src_sample_index == -1:
for ns in range(num_sample_to_copy):
for ns in range( num_sample_to_copy ):
# empty sample
lib_widget, folder_widget = self.__library_widgets(trans, request.user,
len(current_samples),
@@ -882,10 +884,11 @@ class RequestsCommon( BaseController, UsesFormDefinitionWidgets ):
request_details=self.request_details(trans, request.id),
current_samples=current_samples,
sample_copy=self.__copy_sample(current_samples),
details=details, selected_samples=selected_samples,
details=details,
selected_samples=selected_samples,
sample_ops=sample_ops,
edit_mode=edit_mode)
elif params.get('save_samples_button', False) == 'Save':
elif params.get( 'save_samples_button', False ):
# check for duplicate sample names
message = ''
for index in range(len(current_samples)-len(request.samples)):
@@ -974,7 +977,7 @@ class RequestsCommon( BaseController, UsesFormDefinitionWidgets ):
id=trans.security.encode_id(request.id),
status=status,
message=message ))
elif params.get('edit_samples_button', False) == 'Edit samples':
elif params.get( 'edit_samples_button', False ):
edit_mode = 'True'
return trans.fill_template( '/requests/common/show_request.mako',
cntrller=cntrller,
@@ -985,12 +988,12 @@ class RequestsCommon( BaseController, UsesFormDefinitionWidgets ):
sample_ops=sample_ops,
details=details, libraries=libraries,
edit_mode=edit_mode)
elif params.get('cancel_changes_button', False) == 'Cancel':
elif params.get( 'cancel_changes_button', False ):
return trans.response.send_redirect( web.url_for( controller=cntrller,
action='list',
operation='show',
id=trans.security.encode_id(request.id)) )
elif params.get('change_state_button', False) == 'Save':
elif params.get( 'change_state_button', False ) == 'Save':
comments = util.restore_text( params.comment )
selected_state = int( params.select_state )
new_state = trans.sa_session.query( trans.app.model.SampleState ).get( selected_state )
@@ -1003,12 +1006,12 @@ class RequestsCommon( BaseController, UsesFormDefinitionWidgets ):
cntrller=cntrller,
action='update_request_state',
request_id=request.id ))
elif params.get('change_state_button', False) == 'Cancel':
elif params.get( 'change_state_button', False ) == 'Cancel':
return trans.response.send_redirect( web.url_for( controller=cntrller,
action='list',
operation='show',
id=trans.security.encode_id(request.id)) )
elif params.get('change_lib_button', False) == 'Save':
elif params.get( 'change_lib_button', False ) == 'Save':
library = trans.sa_session.query( trans.app.model.Library ).get( int( params.get( 'sample_0_library_id', None ) ) )
folder = trans.sa_session.query( trans.app.model.LibraryFolder ).get( int( params.get( 'sample_0_folder_id', None ) ) )
for sample_id in selected_samples:
@@ -1023,7 +1026,7 @@ class RequestsCommon( BaseController, UsesFormDefinitionWidgets ):
id=trans.security.encode_id(request.id),
status='done',
message='Changes made to the selected sample(s) are saved. ') )
elif params.get('change_lib_button', False) == 'Cancel':
elif params.get( 'change_lib_button', False ) == 'Cancel':
return trans.response.send_redirect( web.url_for( controller=cntrller,
action='list',
operation='show',
+1 -3
View File
@@ -59,12 +59,10 @@ $(document).ready(function(){
%for i, option in enumerate(options):
<div class="form-row">
<b> ${i+1}</b>
${option[1].get_html()}
##<a class="action-button" href="${h.url_for( controller='forms', action='edit', form_id=form.id, select_box_options='remove', field_index=index, option_index=i )}">Remove</a><br>
${option[1].get_html()}
<input type="submit" name="removeoption_${index}_${i}" value="Remove"/>
</div>
%endfor
<input type="hidden" name="field_index" value="${index}"/>
</div>
</div>
<div class="form-row">
+333 -379
View File
@@ -1,165 +1,162 @@
<%inherit file="/base.mako"/>
<%namespace file="/message.mako" import="render_msg" />
<%namespace file="/requests/common/sample_state.mako" import="render_sample_state" />
<%namespace file="/requests/common/sample_datasets.mako" import="render_sample_datasets" />
<%!
def inherit(context):
if context.get('use_panels'):
return '/webapps/galaxy/base_panels.mako'
else:
return '/base.mako'
%>
<%inherit file="${inherit(context)}"/>
<%def name="stylesheets()">
${parent.stylesheets()}
${h.css( "library" )}
</%def>
<script type="text/javascript">
$( function() {
$( "select[refresh_on_change='true']").change( function() {
var refresh = false;
var refresh_on_change_values = $( this )[0].attributes.getNamedItem( 'refresh_on_change_values' )
if ( refresh_on_change_values ) {
refresh_on_change_values = refresh_on_change_values.value.split( ',' );
var last_selected_value = $( this )[0].attributes.getNamedItem( 'last_selected_value' );
for( i= 0; i < refresh_on_change_values.length; i++ ) {
if ( $( this )[0].value == refresh_on_change_values[i] || ( last_selected_value && last_selected_value.value == refresh_on_change_values[i] ) ){
<%def name="javascripts()">
${parent.javascripts()}
<script type="text/javascript">
$( function() {
$( "select[refresh_on_change='true']").change( function() {
var refresh = false;
var refresh_on_change_values = $( this )[0].attributes.getNamedItem( 'refresh_on_change_values' )
if ( refresh_on_change_values ) {
refresh_on_change_values = refresh_on_change_values.value.split( ',' );
var last_selected_value = $( this )[0].attributes.getNamedItem( 'last_selected_value' );
for( i= 0; i < refresh_on_change_values.length; i++ ) {
if ( $( this )[0].value == refresh_on_change_values[i] || ( last_selected_value && last_selected_value.value == refresh_on_change_values[i] ) ){
refresh = true;
break;
}
}
}
else {
refresh = true;
break;
}
}
}
else {
refresh = true;
}
if ( refresh ){
$( "#show_request" ).submit();
}
});
});
</script>
<script type="text/javascript">
function showContent(vThis)
{
// http://www.javascriptjunkie.com
// alert(vSibling.className + " " + vDef_Key);
vParent = vThis.parentNode;
vSibling = vParent.nextSibling;
while (vSibling.nodeType==3) {
// Fix for Mozilla/FireFox Empty Space becomes a TextNode or Something
vSibling = vSibling.nextSibling;
};
if(vSibling.style.display == "none")
{
vThis.src="/static/images/fugue/toggle.png";
vThis.alt = "Hide";
vSibling.style.display = "block";
} else {
vSibling.style.display = "none";
vThis.src="/static/images/fugue/toggle-expand.png";
vThis.alt = "Show";
}
return;
}
</script>
<script type="text/javascript">
$(document).ready(function(){
//hide the all of the element with class msg_body
$(".msg_body").hide();
//toggle the componenet with class msg_body
$(".msg_head").click(function(){
$(this).next(".msg_body").slideToggle(0);
});
});
</script>
<script type="text/javascript">
// Looks for changes in sample states using an async request. Keeps
// calling itself (via setTimeout) until all samples are in a terminal
// state.
var updater = function ( sample_states ) {
// Check if there are any items left to track
var empty = true;
for ( i in sample_states ) {
empty = false;
break;
}
if ( ! empty ) {
setTimeout( function() { updater_callback( sample_states ) }, 1000 );
}
};
var updater_callback = function ( sample_states ) {
// Build request data
var ids = []
var states = []
$.each( sample_states, function ( id, state ) {
ids.push( id );
states.push( state );
if ( refresh ){
$( "#show_request" ).submit();
}
});
});
// Make ajax call
$.ajax( {
type: "POST",
url: "${h.url_for( controller='requests_common', action='sample_state_updates' )}",
dataType: "json",
data: { ids: ids.join( "," ), states: states.join( "," ) },
success : function ( data ) {
$.each( data, function( id, val, cntrller ) {
// Replace HTML
var cell1 = $("#sampleState-" + id);
cell1.html( val.html_state );
var cell2 = $("#sampleDatasets-" + id);
cell2.html( val.html_datasets );
sample_states[ parseInt(id) ] = val.state;
});
updater( sample_states );
},
error: function() {
// Just retry, like the old method, should try to be smarter
updater( sample_states );
}
});
};
function checkAllFields()
{
var chkAll = document.getElementById('checkAll');
var checks = document.getElementsByTagName('input');
var boxLength = checks.length;
var allChecked = false;
var totalChecked = 0;
if ( chkAll.checked == true )
function showContent(vThis)
{
for ( i=0; i < boxLength; i++ )
// http://www.javascriptjunkie.com
// alert(vSibling.className + " " + vDef_Key);
vParent = vThis.parentNode;
vSibling = vParent.nextSibling;
while (vSibling.nodeType==3) {
// Fix for Mozilla/FireFox Empty Space becomes a TextNode or Something
vSibling = vSibling.nextSibling;
};
if(vSibling.style.display == "none")
{
if ( checks[i].name.indexOf( 'select_sample_' ) != -1)
{
checks[i].checked = true;
}
}
vThis.src="/static/images/fugue/toggle.png";
vThis.alt = "Hide";
vSibling.style.display = "block";
} else {
vSibling.style.display = "none";
vThis.src="/static/images/fugue/toggle-expand.png";
vThis.alt = "Show";
}
return;
}
else
{
for ( i=0; i < boxLength; i++ )
$(document).ready(function(){
//hide the all of the element with class msg_body
$(".msg_body").hide();
//toggle the componenet with class msg_body
$(".msg_head").click(function(){
$(this).next(".msg_body").slideToggle(0);
});
});
// Looks for changes in sample states using an async request. Keeps
// calling itself (via setTimeout) until all samples are in a terminal
// state.
var updater = function ( sample_states ) {
// Check if there are any items left to track
var empty = true;
for ( i in sample_states ) {
empty = false;
break;
}
if ( ! empty ) {
setTimeout( function() { updater_callback( sample_states ) }, 1000 );
}
};
var updater_callback = function ( sample_states ) {
// Build request data
var ids = []
var states = []
$.each( sample_states, function ( id, state ) {
ids.push( id );
states.push( state );
});
// Make ajax call
$.ajax( {
type: "POST",
url: "${h.url_for( controller='requests_common', action='sample_state_updates' )}",
dataType: "json",
data: { ids: ids.join( "," ), states: states.join( "," ) },
success : function ( data ) {
$.each( data, function( id, val, cntrller ) {
// Replace HTML
var cell1 = $("#sampleState-" + id);
cell1.html( val.html_state );
var cell2 = $("#sampleDatasets-" + id);
cell2.html( val.html_datasets );
sample_states[ parseInt(id) ] = val.state;
});
updater( sample_states );
},
error: function() {
// Just retry, like the old method, should try to be smarter
updater( sample_states );
}
});
};
function checkAllFields()
{
var chkAll = document.getElementById('checkAll');
var checks = document.getElementsByTagName('input');
var boxLength = checks.length;
var allChecked = false;
var totalChecked = 0;
if ( chkAll.checked == true )
{
if ( checks[i].name.indexOf( 'select_sample_' ) != -1)
for ( i=0; i < boxLength; i++ )
{
checks[i].checked = false
if ( checks[i].name.indexOf( 'select_sample_' ) != -1)
{
checks[i].checked = true;
}
}
}
else
{
for ( i=0; i < boxLength; i++ )
{
if ( checks[i].name.indexOf( 'select_sample_' ) != -1)
{
checks[i].checked = false
}
}
}
}
function stopRKey(evt) {
var evt = (evt) ? evt : ((event) ? event : null);
var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
}
}
</script>
<style type="text/css">
.msg_head {
padding: 0px 0px;
cursor: pointer;
}
</style>
<script type="text/javascript">
function stopRKey(evt) {
var evt = (evt) ? evt : ((event) ? event : null);
var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
}
document.onkeypress = stopRKey
</script>
document.onkeypress = stopRKey
</script>
</%def>
<% samples_not_ready = request.sequence_run_ready() %>
%if samples_not_ready:
@@ -187,244 +184,218 @@ $(document).ready(function(){
| <b>State</b>: ${request.state()}
%endif
</div>
</div>
<br/>
<br/>
<br/><br/>
<ul class="manage-table-actions">
<li><a class="action-button" id="seqreq-${request.id}-popup" class="menubutton">Sequencing Request Actions</a></li>
<div popupmenu="seqreq-${request.id}-popup">
%if request.unsubmitted() and request.samples:
<a class="action-button" confirm="More samples cannot be added to this request once it is submitted. Click OK to submit." href="${h.url_for( controller=cntrller, action='list', operation='Submit', id=trans.security.encode_id(request.id) )}">
<span>Submit</span></a>
<a class="action-button" confirm="More samples cannot be added to this request once it is submitted. Click OK to submit." href="${h.url_for( controller=cntrller, action='list', operation='Submit', id=trans.security.encode_id(request.id) )}">Submit</a>
%endif
<a class="action-button" href="${h.url_for( controller=cntrller, action='list', operation='events', id=trans.security.encode_id(request.id) )}">
<span>History</span></a>
<a class="action-button" href="${h.url_for( controller=cntrller, action='list', operation='Edit', id=trans.security.encode_id(request.id))}">
<span>Edit</span></a>
<a class="action-button" href="${h.url_for( controller=cntrller, action='list', operation='events', id=trans.security.encode_id(request.id) )}">History</a>
<a class="action-button" href="${h.url_for( controller=cntrller, action='list', operation='Edit', id=trans.security.encode_id(request.id))}">Edit</a>
%if cntrller == 'requests_admin' and trans.user_is_admin():
%if request.submitted():
<a class="action-button" href="${h.url_for( controller=cntrller, action='list', operation='reject', id=trans.security.encode_id(request.id))}">
<span>Reject</span></a>
<a class="action-button" href="${h.url_for( controller='requests_admin', action='get_data', show_page=True, request_id=request.id)}">
<span>Select dataset(s) to transfer</span></a>
<a class="action-button" href="${h.url_for( controller=cntrller, action='list', operation='reject', id=trans.security.encode_id(request.id))}">Reject</a>
<a class="action-button" href="${h.url_for( controller='requests_admin', action='get_data', show_page=True, request_id=request.id)}">Select dataset(s) to transfer</a>
%endif
%endif
</div>
<li>
<a class="action-button" href="${h.url_for( controller=cntrller, action='list')}">
<span>Browse requests</span></a>
</li>
<li><a class="action-button" href="${h.url_for( controller=cntrller, action='list')}">Browse requests</a></li>
</ul>
<div>
<h4><img src="/static/images/fugue/toggle-expand.png" alt="Show" onclick="showContent(this);" style="cursor:pointer;"/> Request Information</h4>
<div style="display:none;" >
<table class="grid" border="0">
<tbody>
<tr>
<td valign="top" width="50%">
<div class="form-row">
<label>Description:</label>
%if request.desc:
${request.desc}
%else:
<i>None</i>
%endif
</div>
<div style="clear: both"></div>
%for index, rd in enumerate(request_details):
<div class="form-row">
<label>${rd['label']}:</label>
%if not rd['value']:
<i>None</i>
%else:
%if rd['label'] == 'State':
<a href="${h.url_for( controller=cntrller, action='list', operation='events', id=trans.security.encode_id(request.id) )}">${rd['value']}</a>
%else:
${rd['value']}
%endif
%endif
</div>
<div style="clear: both"></div>
%endfor
</td>
<td valign="top" width="50%">
<div class="form-row">
<label>Date created:</label>
${request.create_time}
</div>
<div class="form-row">
<label>Date updated:</label>
${request.update_time}
</div>
<div class="form-row">
<label>Email notification recipient(s):</label>
<% emails = ', '.join(request.notification['email']) %>
%if emails:
${emails}
%else:
<i>None</i>
%endif
</div>
<div style="clear: both"></div>
<div class="form-row">
<label>Email notification on sample state(s):</label>
<%
states = []
for ss in request.type.states:
if ss.id in request.notification['sample_states']:
states.append(ss.name)
states = ', '.join(states)
%>
%if states:
${states}
%else:
<i>None</i>
%endif
</div>
<div style="clear: both"></div>
</td>
</tr>
</tbody>
</table>
<div class="form-row">
<ul class="manage-table-actions">
<li>
<a class="action-button" href="${h.url_for( controller=cntrller, action='list', operation='Edit', id=trans.security.encode_id(request.id))}">
<span>Edit request information</span></a>
</li>
</ul>
</div>
</div>
</div>
<br/>
##<div class="toolForm">
<form id="show_request" name="show_request" action="${h.url_for( controller='requests_common', cntrller=cntrller, action='request_page', edit_mode=edit_mode )}" method="post" >
##<div class="form-row">
%if current_samples:
## first render the basic info grid
${render_basic_info_grid()}
%if not request.new() and edit_mode == 'False' and len(sample_ops.options) > 1:
<div class="form-row" style="background-color:#FAFAFA;">
For selected sample(s):
${sample_ops.get_html()}
<h4><img src="/static/images/fugue/toggle-expand.png" alt="Show" onclick="showContent(this);" style="cursor:pointer;"/> Request Information</h4>
<div style="display:none;" >
<table class="grid" border="0">
<tbody>
<tr>
<td valign="top" width="50%">
<div class="form-row">
<label>Description:</label>
%if request.desc:
${request.desc}
%else:
<i>None</i>
%endif
</div>
%if 'none' not in sample_ops.get_selected( return_label=True, return_value=True ) and len(selected_samples):
<div class="form-row" style="background-color:#FAFAFA;">
%if trans.app.model.Sample.bulk_operations.CHANGE_STATE in sample_ops.get_selected( return_label=True, return_value=True ):
<%
widgets, title = request.type.change_state_widgets(trans)
%>
%for w in widgets:
<div class="form-row">
<label>
${w[0]}:
</label>
${w[1].get_html()}
%if w[0] == 'Comments':
<div class="toolParamHelp" style="clear: both;">
Optional
</div>
%endif
</div>
%endfor
<div class="form-row">
<input type="submit" name="change_state_button" value="Save"/>
<input type="submit" name="change_state_button" value="Cancel"/>
</div>
%elif trans.app.model.Sample.bulk_operations.SELECT_LIBRARY in sample_ops.get_selected( return_label=True, return_value=True ):
<div class="form-row">
<label>Select data library:</label>
${bulk_lib_ops[0].get_html()}
</div>
%if not 'none' in bulk_lib_ops[0].get_selected( return_label=True, return_value=True ):
<div class="form-row">
<label>Select folder:</label>
${bulk_lib_ops[1].get_html()}
</div>
<div class="form-row">
<input type="submit" name="change_lib_button" value="Save"/>
<input type="submit" name="change_lib_button" value="Cancel"/>
<div style="clear: both"></div>
%for index, rd in enumerate(request_details):
<div class="form-row">
<label>${rd['label']}:</label>
%if not rd['value']:
<i>None</i>
%else:
%if rd['label'] == 'State':
<a href="${h.url_for( controller=cntrller, action='list', operation='events', id=trans.security.encode_id(request.id) )}">${rd['value']}</a>
%else:
${rd['value']}
%endif
%endif
</div>
<div style="clear: both"></div>
%endfor
</td>
<td valign="top" width="50%">
<div class="form-row">
<label>Date created:</label>
${request.create_time}
</div>
<div class="form-row">
<label>Date updated:</label>
${request.update_time}
</div>
<div class="form-row">
<label>Email notification recipient(s):</label>
<% emails = ', '.join(request.notification['email']) %>
%if emails:
${emails}
%else:
<i>None</i>
%endif
</div>
<div style="clear: both"></div>
<div class="form-row">
<label>Email notification on sample state(s):</label>
<%
states = []
for ss in request.type.states:
if ss.id in request.notification['sample_states']:
states.append(ss.name)
states = ', '.join(states)
%>
%if states:
${states}
%else:
<i>None</i>
%endif
</div>
<div style="clear: both"></div>
</td>
</tr>
</tbody>
</table>
<div class="form-row">
<ul class="manage-table-actions">
<li><a class="action-button" href="${h.url_for( controller=cntrller, action='list', operation='Edit', id=trans.security.encode_id(request.id))}">Edit request information</a></li>
</ul>
</div>
</div>
<br/>
<form id="show_request" name="show_request" action="${h.url_for( controller='requests_common', cntrller=cntrller, action='request_page', edit_mode=edit_mode )}" method="post" >
<input type="hidden" name="id" value="${trans.security.encode_id(request.id)}" />
%if current_samples:
## first render the basic info grid
${render_basic_info_grid()}
%if not request.new() and edit_mode == 'False' and len(sample_ops.options) > 1:
<div class="form-row" style="background-color:#FAFAFA;">
For selected sample(s):
${sample_ops.get_html()}
</div>
%if 'none' not in sample_ops.get_selected( return_label=True, return_value=True ) and len(selected_samples):
<div class="form-row" style="background-color:#FAFAFA;">
%if trans.app.model.Sample.bulk_operations.CHANGE_STATE in sample_ops.get_selected( return_label=True, return_value=True ):
<%
widgets, title = request.type.change_state_widgets(trans)
%>
%for w in widgets:
<div class="form-row">
<label>
${w[0]}:
</label>
${w[1].get_html()}
%if w[0] == 'Comments':
<div class="toolParamHelp" style="clear: both;">
Optional
</div>
%endif
%endif
%endif
</div>
%endfor
<div class="form-row">
<input type="submit" name="change_state_button" value="Save"/>
<input type="submit" name="change_state_button" value="Cancel"/>
</div>
%elif trans.app.model.Sample.bulk_operations.SELECT_LIBRARY in sample_ops.get_selected( return_label=True, return_value=True ):
<div class="form-row">
<label>Select data library:</label>
${bulk_lib_ops[0].get_html()}
</div>
%if not 'none' in bulk_lib_ops[0].get_selected( return_label=True, return_value=True ):
<div class="form-row">
<label>Select folder:</label>
${bulk_lib_ops[1].get_html()}
</div>
<div class="form-row">
<input type="submit" name="change_lib_button" value="Save"/>
<input type="submit" name="change_lib_button" value="Cancel"/>
</div>
%endif
%endif
%endif
## then render the other grid(s)
<% trans.sa_session.refresh( request.type.sample_form ) %>
%for grid_index, grid_name in enumerate(request.type.sample_form.layout):
${render_grid( grid_index, grid_name, request.type.sample_form.fields_of_grid( grid_index ) )}
%endfor
%else:
<label>There are no samples.</label>
</div>
%endif
##</div>
%if request.samples and request.submitted():
<script type="text/javascript">
// Updater
updater({${ ",".join( [ '"%s" : "%s"' % ( s.id, s.current_state().name ) for s in request.samples ] ) }});
</script>
%endif
%if edit_mode == 'False':
<table class="grid">
<tbody>
<tr>
<div class="form-row">
%if request.unsubmitted():
<td>
%if current_samples:
<label>Copy </label>
<input type="integer" name="num_sample_to_copy" value="1" size="3"/>
<label>sample(s) from sample</label>
${sample_copy.get_html()}
%endif
<input type="submit" name="add_sample_button" value="Add New"/>
</td>
%endif
## then render the other grid(s)
<% trans.sa_session.refresh( request.type.sample_form ) %>
%for grid_index, grid_name in enumerate(request.type.sample_form.layout):
${render_grid( grid_index, grid_name, request.type.sample_form.fields_of_grid( grid_index ) )}
%endfor
%else:
<label>There are no samples.</label>
%endif
%if request.samples and request.submitted():
<script type="text/javascript">
// Updater
updater({${ ",".join( [ '"%s" : "%s"' % ( s.id, s.current_state().name ) for s in request.samples ] ) }});
</script>
%endif
%if edit_mode == 'False':
<table class="grid">
<tbody>
<tr>
<div class="form-row">
%if request.unsubmitted():
<td>
%if len(current_samples) and len(current_samples) <= len(request.samples):
<input type="submit" name="edit_samples_button" value="Edit samples"/>
%if current_samples:
<label>Copy </label>
<input type="integer" name="num_sample_to_copy" value="1" size="3"/>
<label>sample(s) from sample</label>
${sample_copy.get_html()}
%endif
<input type="submit" name="add_sample_button" value="Add New"/>
</td>
</div>
</tr>
</tbody>
</table>
%endif
%if request.samples or current_samples:
%endif
<td>
%if len(current_samples) and len(current_samples) <= len(request.samples):
<input type="submit" name="edit_samples_button" value="Edit samples"/>
%endif
</td>
</div>
</tr>
</tbody>
</table>
%endif
%if request.samples or current_samples:
<div class="form-row">
<div style="float: left; width: 250px; margin-right: 10px;">
<input type="hidden" name="refresh" value="true" size="40"/>
</div>
<div style="clear: both"></div>
</div>
%if edit_mode == 'True':
<div class="form-row">
<input type="submit" name="save_samples_button" value="Save"/>
<input type="submit" name="cancel_changes_button" value="Cancel"/>
</div>
%elif edit_mode == 'True' or len(current_samples) > len(request.samples):
<div class="form-row">
<div style="float: left; width: 250px; margin-right: 10px;">
<input type="hidden" name="refresh" value="true" size="40"/>
</div>
<div style="clear: both"></div>
</div>
%if edit_mode == 'True':
<div class="form-row">
<input type="submit" name="save_samples_button" value="Save"/>
<input type="submit" name="cancel_changes_button" value="Cancel"/>
</div>
%elif edit_mode == 'True' or len(current_samples) > len(request.samples):
<div class="form-row">
<input type="submit" name="save_samples_button" value="Save"/>
<input type="submit" name="cancel_changes_button" value="Cancel"/>
</div>
%endif
<input type="submit" name="save_samples_button" value="Save"/>
<input type="submit" name="cancel_changes_button" value="Cancel"/>
</div>
%endif
<input type="hidden" name="id" value="${trans.security.encode_id(request.id)}" />
</form>
##</div>
%endif
</form>
<br/>
%if request.unsubmitted():
<form id="import" name="import" action="${h.url_for( controller='requests_common', action='request_page', edit_mode=edit_mode, request_id=trans.security.encode_id(request.id) )}" enctype="multipart/form-data" method="post" >
<h4><img src="/static/images/fugue/toggle-expand.png" alt="Show" onclick="showContent(this);" style="cursor:pointer;"/> Import samples</h4>
@@ -438,11 +409,8 @@ $(document).ready(function(){
</div>
</div>
</form>
##</div>
%endif
<%def name="render_grid( grid_index, grid_name, fields_dict )">
<br/>
<% if not grid_name:
@@ -515,10 +483,8 @@ $(document).ready(function(){
</tr>
<thead>
<tbody>
<%
trans.sa_session.refresh( request )
%>
%for sample_index, info in enumerate(current_samples):
<% trans.sa_session.refresh( request ) %>
%for sample_index, info in enumerate( current_samples ):
<%
if sample_index in range(len(request.samples)):
sample = request.samples[sample_index]
@@ -563,8 +529,6 @@ $(document).ready(function(){
${render_sample_datasets( cntrller, sample )}
</td>
%endif
%else:
${show_basic_info_form( sample_index, sample, info )}
%endif
@@ -589,7 +553,7 @@ $(document).ready(function(){
<%def name="show_basic_info_form( sample_index, sample, info )">
<td></td>
<td>
<input type="text" name=sample_${sample_index}_name value="${info['name']}" size="10"/>
<input type="text" name="sample_${sample_index}_name" value="${info['name']}" size="10"/>
<div class="toolParamHelp" style="clear: both;">
<i>${' (required)' }</i>
</div>
@@ -599,7 +563,7 @@ $(document).ready(function(){
%if sample.request.unsubmitted():
<td></td>
%else:
<td><input type="text" name=sample_${sample_index}_barcode value="${info['barcode']}" size="10"/></td>
<td><input type="text" name="sample_${sample_index}_barcode" value="${info['barcode']}" size="10"/></td>
%endif
%else:
<td></td>
@@ -609,7 +573,7 @@ $(document).ready(function(){
%if sample.request.unsubmitted():
<td></td>
%else:
<td><input type="text" name=sample_${sample_index}_barcode value="${info['barcode']}" size="10"/></td>
<td><input type="text" name="sample_${sample_index}_barcode" value="${info['barcode']}" size="10"/></td>
%endif
%else:
<td></td>
@@ -701,13 +665,3 @@ $(document).ready(function(){
</td>
%endfor
</%def>
+3 -1
View File
@@ -90,8 +90,10 @@ def get_latest_history_for_user( user ):
galaxy.model.History.table.c.user_id==user.id ) ) \
.order_by( desc( galaxy.model.History.table.c.create_time ) ) \
.first()
def get_latest_ldda():
def get_latest_ldda_by_name( name ):
return sa_session.query( galaxy.model.LibraryDatasetDatasetAssociation ) \
.filter( and_( galaxy.model.LibraryDatasetDatasetAssociation.table.c.name==name,
galaxy.model.LibraryDatasetDatasetAssociation.table.c.deleted == False ) ) \
.order_by( desc( galaxy.model.LibraryDatasetDatasetAssociation.table.c.create_time ) ) \
.first()
def get_latest_lddas( limit ):
+221 -260
View File
@@ -767,68 +767,45 @@ class TwillTestCase( unittest.TestCase ):
except:
pass
return previously_created, username_taken, invalid_username
def create_user_with_info( self, email, password, username, user_info_forms, user_info_form_id, user_info_values ):
def create_user_with_info( self, email, password, username, user_info_values, user_info_select='', admin_view='False',
strings_displayed=[], strings_displayed_after_submit=[] ):
# This method creates a new user with associated info
if user_info_forms == 'multiple':
self.visit_url( "%s/user/create?user_info_select=%i&admin_view=False&use_panels=False" % ( self.url, user_info_form_id ) )
else:
self.visit_url( "%s/user/create?admin_view=False&use_panels=False" % self.url )
self.check_page_for_string( "Create account" )
self.visit_url( "%s/user/create?admin_view=%s&use_panels=False" % ( self.url, admin_view ) )
for check_str in strings_displayed:
self.check_page_for_string( check_str)
tc.fv( "1", "email", email )
tc.fv( "1", "password", password )
tc.fv( "1", "confirm", password )
tc.fv( "1", "username", username )
if user_info_forms == 'multiple':
self.check_page_for_string( "User type" )
for index, info_value in enumerate(user_info_values):
if user_info_select:
# The user_info_select SelectField requires a refresh_on_change
self.refresh_form( 'user_info_select', user_info_select )
for index, info_value in enumerate( user_info_values ):
tc.fv( "1", "field_%i" % index, info_value )
tc.submit( "create_user_button" )
def create_user_with_info_as_admin( self, email, password, username, user_info_forms, user_info_form_id, user_info_values ):
# This method creates a new user with associated info from the admin view
self.home()
if user_info_forms == 'multiple':
self.visit_page( "admin/users?operation=create?user_info_select=%i&admin_view=False" % user_info_form_id )
else:
self.visit_page( "admin/users?operation=create" )
self.check_page_for_string( "Create account" )
tc.fv( "2", "email", email )
tc.fv( "2", "password", password )
tc.fv( "2", "confirm", password )
tc.fv( "2", "username", username )
if user_info_forms == 'multiple':
self.check_page_for_string( "User type" )
for index, info_value in enumerate(user_info_values):
tc.fv( "2", "field_%i" % index, info_value )
tc.submit( "create_user_button" )
self.check_page_for_string( "Created new user account (%s)" % email )
def edit_login_info( self, new_email, new_username, strings_displayed=[] ):
self.home()
def edit_user_info( self, new_email='', new_username='', password='', new_password='',
info_values=[], strings_displayed=[], strings_displayed_after_submit=[] ):
self.visit_url( "%s/user/show_info" % self.url )
self.check_page_for_string( "Manage User Information" )
tc.fv( "login_info", "email", new_email )
tc.fv( "login_info", "username", new_username )
tc.submit( "login_info_button" )
for check_str in strings_displayed:
self.check_page_for_string( check_str )
def change_password( self, password, new_password ):
if new_email or new_username:
if new_email:
tc.fv( "login_info", "email", new_email )
if new_username:
tc.fv( "login_info", "username", new_username )
tc.submit( "login_info_button" )
if password and new_password:
tc.fv( "change_password", "current", password )
tc.fv( "change_password", "password", new_password )
tc.fv( "change_password", "confirm", new_password )
tc.submit( "change_password_button" )
if info_values:
for index, info_value in enumerate( info_values ):
tc.fv( "user_info", "field_%i" % index, info_value )
tc.submit( "edit_user_info_button" )
for check_str in strings_displayed_after_submit:
self.check_page_for_string( check_str )
self.home()
self.visit_page( "user/show_info" )
self.check_page_for_string( "Manage User Information" )
tc.fv( "change_password", "current", password )
tc.fv( "change_password", "password", new_password )
tc.fv( "change_password", "confirm", new_password )
tc.submit( "change_password_button" )
self.check_page_for_string( 'The password has been changed.' )
def edit_user_info( self, info_values ):
self.home()
self.visit_page( "user/show_info" )
self.check_page_for_string( "Manage User Information" )
for index, info_value in enumerate(info_values):
tc.fv( "user_info", "field_%i" % index, info_value )
tc.submit( "edit_user_info_button" )
self.check_page_for_string( "The user information has been updated with the changes." )
for value in info_values:
self.check_page_for_string( value )
def user_set_default_permissions( self, permissions_out=[], permissions_in=[], role_id='2' ):
# role.id = 2 is Private Role for test2@bx.psu.edu
# NOTE: Twill has a bug that requires the ~/user/permissions page to contain at least 1 option value
@@ -1340,133 +1317,88 @@ class TwillTestCase( unittest.TestCase ):
self.home()
# Form stuff
def create_form( self, name, desc, formtype, form_layout_name='', num_fields=1 ):
"""
Create a new form definition. Testing framework is still limited to only testing
one instance for each repeat. This has to do with the 'flat' nature of defining
test param values. Using same-named parameters down different branches (having
different scope in the tool) cannot be properly tested when they both exist at the
same time.
"""
self.home()
def create_form( self, name, desc, form_type, field_type='TextField', form_layout_name='',
num_fields=1, num_options=0, strings_displayed=[], strings_displayed_after_submit=[] ):
"""Create a new form definition."""
self.visit_url( "%s/forms/new" % self.url )
self.check_page_for_string( 'Create a new form definition' )
tc.fv( "1", "name", name ) # form field 1 is the field named name...
tc.fv( "1", "description", desc ) # form field 1 is the field named desc...
tc.fv( "1", "form_type_selectbox", formtype )
tc.submit( "create_form_button" )
if formtype == "Sequencing Sample Form":
tc.submit( "add_layout_grid" )
tc.fv( "1", "grid_layout0", form_layout_name )
for index in range( num_fields ):
field_name = 'field_name_%i' % index
field_contents = 'Field %i' % index
field_help_name = 'field_helptext_%i' % index
field_help_contents = 'Field %i help' % index
tc.fv( "1", field_name, field_contents )
tc.fv( "1", field_help_name, field_help_contents )
tc.submit( "save_changes_button" )
if num_fields:
check_str = "The form '%s' has been updated with the changes." % name
for check_str in strings_displayed:
self.check_page_for_string( check_str )
else:
self.home()
self.visit_url( "%s/forms/manage" % self.url )
self.check_page_for_string( name )
self.check_page_for_string( desc )
self.check_page_for_string( formtype )
self.home()
# Form stuff
def create_single_field_type_form_definition( self, name, desc, formtype, field_type ):
"""
Create a new form definition containing 1 field of a specified type ( AddressField, CheckboxField, SelectField,
TextArea, TextField, WorkflowField ). The form_type param value should not be 'Sequencing Sample Form,' use
create_form() above for that.
"""
self.home()
# Create a new form definition
self.visit_url( "%s/forms/new" % self.url )
self.check_page_for_string( 'Create a new form definition' )
tc.fv( "1", "name", name )
tc.fv( "1", "description", desc )
tc.fv( "1", "form_type_selectbox", formtype )
tc.fv( "1", "form_type_selectbox", form_type )
tc.submit( "create_form_button" )
# Add 1 AddressField to the new form definition
field_name = 'field_name_0'
field_contents = field_type
field_help_name = 'field_helptext_0'
field_help_contents = '%s help' % field_type
field_default = 'field_default_0'
field_default_contents = '%s default contents' % field_type
tc.fv( "1", field_name, field_contents )
tc.fv( "1", field_help_name, field_help_contents )
self.refresh_form( 'field_type_0', field_type )
if field_type == 'SelectField':
# Add 2 options so our select list is functional
tc.submit( "addoption_0" )
tc.fv( "1", "field_0_option_0", "One" )
tc.submit( "addoption_0" )
tc.fv( "1", "field_0_option_1", "Two" )
tc.fv( "1", field_default, field_default_contents )
if form_type == "Sequencing Sample Form":
tc.submit( "add_layout_grid" )
tc.fv( "1", "grid_layout0", form_layout_name )
# Add fields to the new form definition
for index1 in range( num_fields ):
field_name = 'field_name_%i' % index1
field_contents = field_type
field_help_name = 'field_helptext_%i' % index1
field_help_contents = 'Field %i help' % index1
field_default = 'field_default_0'
field_default_contents = '%s default contents' % form_type
tc.fv( "1", field_name, field_contents )
tc.fv( "1", field_help_name, field_help_contents )
if field_type == 'SelectField':
# SelectField field_type requires a refresh_on_change
self.refresh_form( 'field_type_0', field_type )
# Add options so our select list is functional
if num_options == 0:
# Default to 2 options
num_options = 2
for index2 in range( 1, num_options+1 ):
tc.submit( "addoption_0" )
# Add contents to the new options fields
for index2 in range( num_options ):
option_field_name = 'field_0_option_%i' % index2
option_field_value = 'Option%i' % index2
tc.fv( "1", option_field_name, option_field_value )
else:
tc.fv( "1", "field_type_0", field_type )
tc.fv( "1", field_default, field_default_contents )
tc.submit( "save_changes_button" )
if num_fields == 0:
self.visit_url( "%s/forms/manage" % self.url )
for check_str in strings_displayed_after_submit:
self.check_page_for_string( check_str )
self.home()
self.visit_url( "%s/forms/manage" % self.url )
self.check_page_for_string( name )
self.check_page_for_string( desc )
self.check_page_for_string( formtype )
def edit_form( self, id, form_type='', new_form_name='', new_form_desc='', field_dicts=[], field_index=0,
strings_displayed=[], strings_not_displayed=[], strings_displayed_after_submit=[] ):
"""Edit form details; name and description"""
self.home()
def edit_form( self, form_current_id, form_name, new_form_name="Form One's Name (Renamed)", new_form_desc="This is Form One's description (Re-described)"):
"""
Edit form details; name & description
"""
self.home()
self.visit_url( "%s/forms/manage?sort=create_time&f-name=All&f-desc=All&f-deleted=False&operation=Edit&id=%s" % ( self.url, self.security.encode_id(form_current_id) ) )
self.check_page_for_string( 'Edit form definition "%s"' % form_name )
tc.fv( "1", "name", new_form_name )
tc.fv( "1", "description", new_form_desc )
tc.submit( "save_changes_button" )
self.check_page_for_string( "The form '%s' has been updated with the changes." % new_form_name )
self.home()
def form_add_field( self, form_current_id, form_name, form_desc, form_type, form_layout_name='', field_index=0, fields=None):
"""
Add a new fields to the form definition
"""
self.home()
self.visit_url( "%s/forms/manage?sort=create_time&f-name=All&f-desc=All&f-deleted=False&operation=Edit&id=%s" % ( self.url, self.security.encode_id(form_current_id) ) )
self.check_page_for_string( 'Edit form definition "%s"' % form_name)
for i, field in enumerate(fields):
index = i+field_index
self.visit_url( "%s/forms/manage?operation=Edit&id=%s" % ( self.url, id ) )
for check_str in strings_displayed:
self.check_page_for_string( check_str )
if new_form_name:
tc.fv( "1", "name", new_form_name )
if new_form_desc:
tc.fv( "1", "description", new_form_desc )
for i, field_dict in enumerate( field_dicts ):
index = i + field_index
tc.submit( "add_field_button" )
tc.fv( "1", "field_name_%i" % index, field['name'] )
tc.fv( "1", "field_helptext_%i" % index, field['desc'] )
tc.fv( "1", "field_type_%i" % index, field['type'] )
tc.fv( "1", "field_required_%i" % index, field['required'] )
if field['type'] == 'SelectField':
options = ''
for option_index, option in enumerate(field['selectlist']):
url_str = "%s/forms/manage?operation=Edit&description=%s&grid_layout0=%s&id=%s&form_type_selectbox=%s&addoption_%i=Add&name=%s&field_name_%i=%s&field_helptext_%i=%s&field_type_%i=%s" % \
(self.url, form_desc.replace(" ", "+"), form_layout_name.replace(" ", "+"),
self.security.encode_id(form_current_id), form_type.replace(" ", "+"),
index, form_name.replace(" ", "+"), index, field['name'].replace(" ", "+"),
index, field['desc'].replace(" ", "+"), index, field['type'])
self.visit_url( url_str + options )
tc.fv( "1", "field_%i_option_%i" % (index, option_index), option )
options = options + "&field_%i_option_%i=%s" % (index, option_index, option)
field_name = "field_name_%i" % index
field_value = field_dict[ 'name' ]
field_help = "field_helptext_%i" % index
field_help_value = field_dict[ 'desc' ]
field_type = "field_type_%i" % index
field_type_value = field_dict[ 'type' ]
field_required = "field_required_%i" % index
field_required_value = field_dict[ 'required' ]
tc.fv( "1", field_name, field_value )
tc.fv( "1", field_help, field_help_value )
tc.fv( "1", field_required, field_required_value )
if field_type_value.lower() == 'selectfield':
# SelectFields require a refresh_on_change
self.refresh_form( field_type, field_type_value )
for option_index, option in enumerate( field_dict[ 'selectlist' ] ):
tc.submit( "addoption_0" )
tc.fv( "1", "field_%i_option_%i" % ( index, option_index ), option )
else:
tc.fv( "1", field_type, field_type_value )
tc.submit( "save_changes_button" )
check_str = "The form '%s' has been updated with the changes." % form_name
self.check_page_for_string( check_str )
self.home()
def form_remove_field( self, form_id, form_name, field_name):
"""
Remove a field from the form definition
"""
self.home()
self.visit_url( "%s/forms/manage?operation=Edit&form_id=%i&show_form=True" % (self.url, form_id) )
self.check_page_for_string( 'Edit form definition "%s"' % form_name)
tc.submit( "remove_button" )
tc.submit( "save_changes_button" )
check_str = "The form '%s' has been updated with the changes." % form_name
self.check_page_for_string( check_str )
for check_str in strings_displayed_after_submit:
self.check_page_for_string( check_str )
self.home()
def mark_form_deleted( self, form_id ):
"""Mark a form_definition as deleted"""
@@ -1478,20 +1410,16 @@ class TwillTestCase( unittest.TestCase ):
self.home()
# Requests stuff
def check_request_grid(self, state, request_name, deleted=False):
self.home()
self.visit_url('%s/requests/list?sort=create_time&f-state=%s&f-deleted=%s' \
% (self.url, state.replace(' ', '+'), str(deleted)))
self.check_page_for_string( request_name )
def check_request_admin_grid(self, state, request_name, deleted=False):
self.home()
self.visit_url('%s/requests_admin/list?sort=create_time&f-state=%s&f-deleted=%s' \
% (self.url, state.replace(' ', '+'), str(deleted)))
self.check_page_for_string( request_name )
def create_request_type( self, name, desc, request_form_id, sample_form_id, states ):
def check_request_grid( self, cntrller, state, deleted=False, strings_displayed=[] ):
self.visit_url( '%s/%s/list?sort=create_time&f-state=%s&f-deleted=%s' % \
( self.url, cntrller, state.replace( ' ', '+' ), str( deleted ) ) )
for check_str in strings_displayed:
self.check_page_for_string( check_str )
def create_request_type( self, name, desc, request_form_id, sample_form_id, states, strings_displayed=[], strings_displayed_after_submit=[] ):
self.home()
self.visit_url( "%s/requests_admin/create_request_type" % self.url )
self.check_page_for_string( 'Create a new sequencer configuration' )
for check_str in strings_displayed:
self.check_page_for_string( check_str )
tc.fv( "1", "name", name )
tc.fv( "1", "desc", desc )
tc.fv( "1", "request_form_id", request_form_id )
@@ -1501,7 +1429,8 @@ class TwillTestCase( unittest.TestCase ):
tc.fv("1", "state_name_%i" % index, state[0])
tc.fv("1", "state_desc_%i" % index, state[1])
tc.submit( "save_request_type" )
self.check_page_for_string( "Sequencer configuration <b>%s</b> has been created" % name )
for check_str in strings_displayed_after_submit:
self.check_page_for_string( check_str )
def request_type_permissions( self, request_type_id, request_type_name, role_ids_str, permissions_in, permissions_out ):
# role_ids_str must be a comma-separated string of role ids
url = "requests_admin/manage_request_types?operation=permissions&id=%s&update_roles_button=Save" % ( request_type_id )
@@ -1516,87 +1445,123 @@ class TwillTestCase( unittest.TestCase ):
check_str = "Permissions updated for sequencer configuration '%s'" % request_type_name
self.check_page_for_string( check_str )
self.home()
def create_request( self, request_type_id, name, desc, fields ):
self.home()
self.visit_url( "%s/requests_common/new?select_request_type=%i&refresh=true&cntrller=requests" % ( self.url,
request_type_id ) )
self.check_page_for_string( 'Add a new request' )
def create_request( self, cntrller, request_type_id, name, desc, field_value_tuples, select_user_id='',
refresh='False', strings_displayed=[], strings_displayed_after_submit=[] ):
self.visit_url( "%s/requests_common/new?cntrller=%s&refresh=%s&select_request_type=True" % ( self.url, cntrller, refresh ) )
# The select_request_type SelectList requires a refresh_on_change
self.refresh_form( 'select_request_type', request_type_id )
if cntrller == 'requests_admin' and select_user_id:
# The admin is creating a request on behalf of another user
# The select_user SelectList requires a refresh_on_change
# gvk - 9/22/10: TODO: why does select_user require a refresh_on_change? Nothing in the
# code is apparent as to why this is done.
self.refresh_form( 'select_user', select_user_id )
for check_str in strings_displayed:
self.check_page_for_string( check_str )
tc.fv( "1", "name", name )
tc.fv( "1", "desc", desc )
for index, field_value in enumerate(fields):
tc.fv( "1", "field_%i" % index, field_value )
for index, field_value_tuple in enumerate( field_value_tuples ):
field_name = "field_%i" % index
field_value, refresh_on_change = field_value_tuple
if refresh_on_change:
# TODO: If the field is an AddressField, we should test for adding a new address
# which would need to be handled here. This currently only allows an existing
# user_address to be selected.
self.refresh_form( field_name, field_value )
else:
data = self.last_page()
file( 'greg.html', 'wb' ).write(data )
tc.fv( "1", field_name, field_value )
tc.submit( "create_request_button" )
self.check_page_for_string( name )
self.check_page_for_string( desc )
def edit_request( self, request_id, name, new_name, new_desc, new_fields):
for check_str in strings_displayed_after_submit:
self.check_page_for_string( check_str )
self.home()
self.visit_url( "%s/requests/list?operation=Edit&id=%s" % (self.url, self.security.encode_id(request_id) ) )
def edit_request( self, request_id, name, new_name='', new_desc='', new_fields=[], strings_displayed=[], strings_displayed_after_submit=[] ):
self.visit_url( "%s/requests/list?operation=Edit&id=%s" % ( self.url, request_id ) )
for check_str in strings_displayed:
self.check_page_for_string( check_str )
self.check_page_for_string( 'Edit sequencing request "%s"' % name )
tc.fv( "1", "name", new_name )
tc.fv( "1", "desc", new_desc )
for index, field_value in enumerate(new_fields):
if new_name:
tc.fv( "1", "name", new_name )
if new_desc:
tc.fv( "1", "desc", new_desc )
for index, field_value in enumerate( new_fields ):
tc.fv( "1", "field_%i" % index, field_value )
tc.submit( "save_changes_request_button" )
self.check_page_for_string( new_name )
self.check_page_for_string( new_desc )
def add_samples( self, request_id, request_name, samples ):
self.home()
url = "%s/requests/list?operation=show&id=%s" % ( self.url, self.security.encode_id( request_id ) )
for check_str in strings_displayed_after_submit:
self.check_page_for_string( check_str )
def add_samples( self, cntrller, request_id, request_name, sample_value_tuples, strings_displayed=[], strings_displayed_after_submit=[] ):
self.visit_url( "%s/requests/list?operation=show&id=%s" % ( self.url, request_id ) )
for check_str in strings_displayed:
self.check_page_for_string( check_str )
# Simulate clicking the add-sample_button on the form. (gvk: 9/21/10 - TODO : There must be a bug in the mako template
# because twill cannot find any forms on the page, but I cannot find it although I've spent time cleaning up the
# template code and looking for any problems.
url = "%s/requests_common/request_page?cntrller=%s&edit_mode=False&id=%s" % ( self.url, cntrller, request_id )
# This should work, but although twill does not thorw any exceptions, the button click never occurs
# There are multiple forms on this page, and we'll only be using the form named show_request.
# for sample_index, sample_value_tuple in enumerate( sample_value_tuples ):
# # Add the following form value to the already populated hidden field so that the show_request
# # form is the current form
# tc.fv( "1", "id", request_id )
# tc.submit( 'add_sample_button' )
for sample_index, sample_value_tuple in enumerate( sample_value_tuples ):
sample_name, field_values = sample_value_tuple
sample_name = sample_name.replace( ' ', '+' )
field_name = "sample_%i_name" % sample_index
# The following form_value setting should work but since twill barfed on submitting the add_sample_button
# above, we have to simulate it by appending to the url.
# tc.fv( "1", field_name, sample_name )
url += "&%s=%s" % ( field_name, sample_name )
for field_index, field_value in enumerate( field_values ):
field_name = "sample_%i_field_%i" % ( sample_index, field_index )
field_value = field_value.replace( ' ', '+' )
# The following form_value setting should work but since twill barfed on submitting the add_sample_button
# above, we have to simulate it by appending to the url.
# tc.fv( "1", field_name, field_value )
url += "&%s=%s" % ( field_name , field_value )
# The following button submit should work but since twill barfed on submitting the add_sample_button
# above, we have to simulate it by appending to the url.
# tc.submit( "save_samples_button" )
url += "&save_samples_button=Save"
self.visit_url( url )
self.check_page_for_string( 'Sequencing Request "%s"' % request_name )
self.check_page_for_string( 'There are no samples.' )
# this redundant stmt below is add so that the second form in
# the page gets selected
url = ["%s/requests_common/request_page?cntrller=requests&edit_mode=False&id=%s" % ( self.url, self.security.encode_id( request_id ) )]
for sample_index, sample in enumerate(samples):
sample_name, fields = sample
url.append("sample_%i_name=%s" % (sample_index, sample_name.replace(' ', '+')))
for field_index, field_value in enumerate(fields):
url.append("sample_%i_field_%i=%s" % ( sample_index, field_index , field_value.replace(' ', '+') ))
url.append("save_samples_button=Save")
self.visit_url('&'.join(url))
for sample_name, fields in samples:
self.check_page_for_string( sample_name )
self.check_page_for_string( 'Unsubmitted' )
for field_value in fields:
self.check_page_for_string( field_value )
def submit_request( self, request_id, request_name ):
self.home()
self.visit_url( "%s/requests/list?operation=Submit&id=%s" % ( self.url, self.security.encode_id( request_id ) ))
self.check_page_for_string( 'The request <b>%s</b> has been submitted.' % request_name )
def submit_request_as_admin( self, request_id, request_name ):
self.home()
self.visit_url( "%s/requests_admin/list?operation=Submit&id=%s" % ( self.url, self.security.encode_id( request_id ) ))
self.check_page_for_string( 'The request <b>%s</b> has been submitted.' % request_name )
def reject_request( self, request_id, request_name, comment ):
self.home()
self.visit_url( "%s/requests_admin/list?operation=Reject&id=%s" % ( self.url, self.security.encode_id( request_id ) ))
self.check_page_for_string( 'Reject Sequencing Request "%s"' % request_name )
for check_str in strings_displayed_after_submit:
self.check_page_for_string( check_str )
def submit_request( self, cntrller, request_id, request_name, strings_displayed_after_submit=[] ):
self.visit_url( "%s/%s/list?operation=Submit&id=%s" % ( self.url, cntrller, request_id ) )
for check_str in strings_displayed_after_submit:
self.check_page_for_string( check_str )
def reject_request( self, request_id, request_name, comment, strings_displayed=[], strings_displayed_after_submit=[] ):
self.visit_url( "%s/requests_admin/list?operation=Reject&id=%s" % ( self.url, request_id ) )
for check_str in strings_displayed:
self.check_page_for_string( check_str )
tc.fv( "1", "comment", comment )
tc.submit( "reject_button" )
self.check_page_for_string( 'Request <b>%s</b> has been rejected.' % request_name )
self.visit_url( "%s/requests/list?&operation=show&id=%s" % ( self.url, self.security.encode_id( request_id ) ))
self.check_page_for_string( comment )
def add_bar_codes( self, request_id, request_name, bar_codes, samples ):
self.home()
url = "%s/requests/list?operation=show&id=%s" % ( self.url, self.security.encode_id( request_id ) )
for check_str in strings_displayed_after_submit:
self.check_page_for_string( check_str )
def add_bar_codes( self, request_id, request_name, bar_codes, samples, strings_displayed_after_submit=[] ):
# We have to simulate the form submission here since twill barfs on the page
# gvk - 9/22/10 - TODO: make sure the mako template produces valid html
url = "%s/requests_common/request_page?cntrller=requests_admin&edit_mode=True&id=%s" % ( self.url, request_id )
for index, field_value in enumerate( bar_codes ):
sample_field_name = "sample_%i_name" % index
sample_field_value = samples[ index ].name.replace( ' ', '+' )
field_name = "sample_%i_barcode" % index
url += "&%s=%s" % ( field_name, field_value )
url += "&%s=%s" % ( sample_field_name, sample_field_value )
url += "&save_samples_button=Save"
self.visit_url( url )
self.check_page_for_string( 'Sequencing Request "%s"' % request_name )
url = ["%s/requests_common/request_page?save_samples_button=Save&cntrller=requests&edit_mode=True&id=%s" % ( self.url, self.security.encode_id( request_id ) )]
for index, bar_code in enumerate(bar_codes):
url.append("sample_%i_barcode=%s" % (index, bar_code ))
url.append("sample_%i_name=%s" % (index, samples[index].name.replace(' ', '+') ))
self.visit_url('&'.join(url))
self.check_page_for_string( 'Changes made to the sample(s) are saved.' )
for index, bar_code in enumerate(bar_codes):
self.check_page_for_string( bar_code )
def change_sample_state( self, request_id, request_name, sample_name, sample_id, new_state_id, new_state_name, comment='' ):
self.home()
url = "%s/requests/list?operation=show&id=%s" % ( self.url, self.security.encode_id( request_id ) )
self.visit_url( url )
self.check_page_for_string( 'Sequencing Request "%s"' % request_name )
url = "%s/requests_common/request_page?cntrller=requests_admin&edit_mode=False&id=%s&comment=%s&change_state_button=Save&select_sample_operation=%s&refresh=true&select_sample_%i=true&select_sample_%i=true&select_state=%i" % \
(self.url, self.security.encode_id( request_id ), comment, "Change%20state", sample_id, sample_id, new_state_id )
for check_str in strings_displayed_after_submit:
self.check_page_for_string( check_str )
def change_sample_state( self, request_id, request_name, sample_name, sample_id, new_state_id, new_state_name, comment='',
strings_displayed=[], strings_displayed_after_submit=[] ):
# We have to simulate the form submission here since twill barfs on the page
# gvk - 9/22/10 - TODO: make sure the mako template produces valid html
url = "%s/requests_common/request_page?cntrller=requests_admin&edit_mode=False&id=%s" % ( self.url, request_id )
# select_sample_%i=true must be included twice to simulate a CheckboxField checked setting.
url += "&comment=%s&select_sample_%i=true&select_sample_%i=true&select_state=%i" % ( comment, sample_id, sample_id, new_state_id )
url += "&select_sample_operation=Change%20state&refresh=true"
url += "&change_state_button=Save"
self.visit_url( url )
self.check_page_for_string( 'Sequencing Request "%s"' % request_name )
self.visit_url( "%s/requests_common/sample_events?cntrller=requests_admin&sample_id=%i" % (self.url, sample_id) )
@@ -1610,14 +1575,6 @@ class TwillTestCase( unittest.TestCase ):
tc.fv( "1", field_name, value )
tc.submit( "new_address_button" )
self.check_page_for_string( 'Address (%s) has been added' % address_dict[ 'short_desc' ] )
def add_user_address_as_admin( self, user_id, address_dict ):
self.home()
self.visit_url( "%s/user/new_address?admin_view=True&user_id=%i" % ( self.url, user_id ) )
self.check_page_for_string( 'Add new address' )
for field_name, value in address_dict.items():
tc.fv( "1", field_name, value )
tc.submit( "new_address_button" )
self.check_page_for_string( 'Address (%s) has been added' % address_dict[ 'short_desc' ] )
# Library stuff
def add_library_template( self, cntrller, item_type, library_id, form_id, form_name, folder_id=None, ldda_id=None ):
@@ -1685,6 +1642,8 @@ class TwillTestCase( unittest.TestCase ):
pass
def browse_library( self, cntrller, id, show_deleted=False, strings_displayed=[], strings_not_displayed=[] ):
self.visit_url( '%s/library_common/browse_library?cntrller=%s&id=%s&show_deleted=%s' % ( self.url, cntrller, id, str( show_deleted ) ) )
data=self.last_page()
file( 'greg.html', 'wb' ).write( data )
for check_str in strings_displayed:
self.check_page_for_string( check_str )
for check_str in strings_not_displayed:
@@ -1878,6 +1837,8 @@ class TwillTestCase( unittest.TestCase ):
tc.submit( "runtool_btn" )
# Give the files some time to finish uploading
self.library_wait( library_id )
data = self.last_page()
file( 'greg1.html', 'wb' ).write( data )
self.home()
def ldda_permissions( self, cntrller, library_id, folder_id, id, role_ids_str,
permissions_in=[], permissions_out=[], strings_displayed=[], ldda_name='' ):
@@ -2033,7 +1994,7 @@ class TwillTestCase( unittest.TestCase ):
check_str = "Library '%s' and all of its contents have been purged" % library_name
self.check_page_for_string( check_str )
self.home()
def library_wait( self, library_id, cntrller='library_admin', maxiter=60 ):
def library_wait( self, library_id, cntrller='library_admin', maxiter=90 ):
"""Waits for the tools to finish"""
count = 0
sleep_amount = 1
+226 -186
View File
@@ -7,13 +7,13 @@ sample_states = [ ( 'New', 'Sample entered into the system' ),
( 'Received', 'Sample tube received' ),
( 'Done', 'Sequence run complete' ) ]
address_dict = dict( short_desc="Office",
name="James+Bond",
name="James Bond",
institution="MI6" ,
address="MI6+Headquarters",
address="MI6 Headquarters",
city="London",
state="London",
postal_code="007",
country="United+Kingdom",
country="United Kingdom",
phone="007-007-0007" )
class TestFormsAndRequests( TwillTestCase ):
@@ -90,72 +90,81 @@ class TestFormsAndRequests( TwillTestCase ):
global role_two
role_two = get_role_by_name( name )
assert role_two is not None, 'Problem retrieving role named "Role Two" from the database'
def test_010_create_form( self ):
"""Testing creating a new form and editing it"""
self.logout()
self.login( email=admin_user.email )
# create a form
name = "Request Form"
desc = "This is Form One's description"
formtype = galaxy.model.FormDefinition.types.REQUEST
self.create_form( name=name, desc=desc, formtype=formtype, num_fields=0 )
def test_010_create_request_form( self ):
"""Testing creating a request form definition, editing the name and description and adding fields"""
# Logged in as admin_user
# Create a form definition
tmp_name = "Temp form"
tmp_desc = "Temp form description"
form_type = galaxy.model.FormDefinition.types.REQUEST
self.create_form( name=tmp_name,
desc=tmp_desc,
form_type=form_type,
num_fields=0,
strings_displayed=[ 'Create a new form definition' ],
strings_displayed_after_submit=[ tmp_name, tmp_desc, form_type ] )
tmp_form = get_form( tmp_name )
# Edit the name and description of the form definition, and add 3 fields.
new_name = "Request Form"
new_desc = "Request Form description"
global test_field_name1
test_field_name1 = 'Test field name one'
global test_field_name2
test_field_name2 = 'Test field name two'
global test_field_name3
test_field_name3 = 'Test field name three'
field_dicts = [ dict( name=test_field_name1,
desc='Test field description one',
type='SelectField',
required='optional',
selectlist=[ 'option1', 'option2' ] ),
dict( name=test_field_name2,
desc='Test field description two',
type='AddressField',
required='optional' ),
dict( name=test_field_name3,
desc='Test field description three',
type='TextField',
required='required' ) ]
self.edit_form( id=self.security.encode_id( tmp_form.current.id ),
new_form_name=new_name,
new_form_desc=new_desc,
field_dicts=field_dicts,
field_index=len( tmp_form.fields ),
strings_displayed=[ 'Edit form definition "%s"' % tmp_name ],
strings_displayed_after_submit=[ "The form '%s' has been updated with the changes." % new_name ] )
# Get the form_definition object for later tests
global form_one
form_one = get_form( name )
assert form_one is not None, 'Problem retrieving form named "%s" from the database' % name
# edit form & add few more fields
new_name = "Request Form (Renamed)"
new_desc = "This is Form One's Re-described"
self.edit_form( form_one.current.id, form_one.name, new_form_name=new_name, new_form_desc=new_desc )
self.home()
self.visit_page( 'forms/manage' )
self.check_page_for_string( new_name )
self.check_page_for_string( new_desc )
form_one = get_form( new_name )
def test_015_add_form_fields( self ):
"""Testing adding fields to a form definition"""
fields = [dict(name='Test field name one',
desc='Test field description one',
type='SelectField',
required='optional',
selectlist=['option1', 'option2']),
dict(name='Test field name two',
desc='Test field description two',
type='AddressField',
required='optional'),
dict(name='Test field name three',
desc='Test field description three',
type='TextField',
required='required')]
self.form_add_field( form_one.current.id,
form_one.name,
form_one.desc,
form_one.type,
field_index=len( form_one.fields ),
fields=fields )
form_one_latest = get_form( form_one.name )
assert len( form_one_latest.fields ) == len( form_one.fields ) + len( fields )
def test_020_create_sample_form( self ):
"""Testing creating another form (for samples)"""
assert form_one is not None, 'Problem retrieving form named "%s" from the database' % new_name
assert len( form_one.fields ) == len( tmp_form.fields ) + len( field_dicts )
def test_015_create_sample_form( self ):
"""Testing creating sample form definition"""
name = "Sample Form"
desc = "This is Form Two's description"
formtype = galaxy.model.FormDefinition.types.SAMPLE
form_type = galaxy.model.FormDefinition.types.SAMPLE
form_layout_name = 'Layout Grid One'
self.create_form( name=name, desc=desc, formtype=formtype, form_layout_name=form_layout_name )
self.create_form( name=name,
desc=desc,
form_type=form_type,
form_layout_name=form_layout_name,
strings_displayed=[ 'Create a new form definition' ],
strings_displayed_after_submit=[ "The form '%s' has been updated with the changes." % name ] )
global form_two
form_two = get_form( name )
assert form_two is not None, "Error retrieving form %s from db" % name
self.home()
self.visit_page( 'forms/manage' )
self.check_page_for_string( form_two.name )
self.check_page_for_string( desc )
self.check_page_for_string( formtype )
def test_025_create_request_type( self ):
"""Testing creating a new requestype"""
def test_020_create_request_type( self ):
"""Testing creating a request_type"""
request_form = get_form( form_one.name )
sample_form = get_form( form_two.name )
name = 'Test Requestype'
self.create_request_type( name, "test sequencer configuration", str( request_form.id ), str( sample_form.id ), sample_states )
self.create_request_type( name,
"test sequencer configuration",
str( request_form.id ),
str( sample_form.id ),
sample_states,
strings_displayed=[ 'Create a new sequencer configuration' ],
strings_displayed_after_submit=[ "Sequencer configuration <b>%s</b> has been created" % name ] )
global request_type1
request_type1 = get_request_type_by_name( name )
assert request_type1 is not None, 'Problem retrieving sequencer configuration named "%s" from the database' % name
@@ -180,166 +189,207 @@ class TestFormsAndRequests( TwillTestCase ):
pass
self.logout()
self.login( email=admin_user.email )
def test_030_create_address_and_library( self ):
"""Testing address & library creation"""
# ( 9/17/10 placed by gvk ) Hey, RC, why is this test here? The library is never used later in this script.
# first create a library for the request so that it can be submitted later
name = "TestLib001"
description = "TestLib001 description"
synopsis = "TestLib001 synopsis"
self.create_library( name=name, description=description, synopsis=synopsis )
# Get the library object for later tests
global library_one
library_one = get_library( name, description, synopsis )
assert library_one is not None, 'Problem retrieving library named "%s" from the database' % name
# Make sure library_one is public
assert 'access library' not in [ a.action for a in library_one.actions ], 'Library %s is not public when first created' % library_one.name
# Set permissions on the library, sort for later testing.
permissions_in = [ k for k, v in galaxy.model.Library.permitted_actions.items() ]
permissions_out = []
# Role one members are: admin_user, regular_user1, regular_user3. Each of these users will be permitted for
# LIBRARY_ACCESS, LIBRARY_ADD, LIBRARY_MODIFY, LIBRARY_MANAGE on this library and it's contents.
self.library_permissions( self.security.encode_id( library_one.id ),
library_one.name,
str( role_one.id ),
permissions_in,
permissions_out )
# Make sure the library is accessible by admin_user
self.visit_url( '%s/library/browse_libraries' % self.url )
self.check_page_for_string( library_one.name )
# Make sure the library is not accessible by regular_user2 since regular_user2 does not have Role1.
self.logout()
self.login( email=regular_user2.email )
self.visit_url( '%s/library/browse_libraries' % self.url )
try:
self.check_page_for_string( library_one.name )
raise AssertionError, 'Library %s is accessible by %s when it should be restricted' % ( library_one.name, regular_user2.email )
except:
pass
self.logout()
self.login( email=admin_user.email )
# create folder
root_folder = library_one.root_folder
name = "Root Folder's Folder One"
description = "This is the root folder's Folder One"
self.add_folder( 'library_admin',
self.security.encode_id( library_one.id ),
self.security.encode_id( root_folder.id ),
name=name,
description=description )
global folder_one
folder_one = get_folder( root_folder.id, name, description )
assert folder_one is not None, 'Problem retrieving library folder named "%s" from the database' % name
# create address
def test_025_create_request( self ):
"""Testing creating a sequence run request"""
# logged in as admin_user
# Create a user_address
self.logout()
self.login( email=regular_user1.email )
self.add_user_address( regular_user1.id, address_dict )
global user_address1
user_address1 = get_user_address( regular_user1, address_dict[ 'short_desc' ] )
def test_035_create_request( self ):
"""Testing creating, editing and submitting a request as a regular user"""
# login as a regular user
self.logout()
self.login( email=regular_user1.email )
# set field values
fields = ['option1', str(user_address1.id), 'field three value']
# create the request
user_address1 = get_user_address( regular_user1, address_dict[ 'short_desc' ] )
# Set field values - the tuples in the field_values list include the field_value, and True if refresh_on_change
# is required for that field.
field_value_tuples = [ ( 'option1', False ), ( str( user_address1.id ), True ), ( 'field three value', False ) ]
# Create the request
name = 'Request One'
desc = 'Request One Description'
self.create_request(request_type1.id, name, desc, fields)
self.create_request( cntrller='requests',
request_type_id=str( request_type1.id ),
name=name,
desc=desc,
field_value_tuples=field_value_tuples,
strings_displayed=[ 'Add a new request',
test_field_name1,
test_field_name2,
test_field_name3 ],
strings_displayed_after_submit=[ name, desc ] )
global request_one
request_one = get_request_by_name( name )
# check if the request's state is now set to 'new'
# Make sure the request's state is now set to NEW
assert request_one.state is not request_one.states.NEW, "The state of the request '%s' should be set to '%s'" \
% ( request_one.name, request_one.states.NEW )
# sample fields
samples = [ ( 'Sample One', [ 'S1 Field 0 Value' ] ),
( 'Sample Two', [ 'S2 Field 0 Value' ] ) ]
# add samples to this request
self.add_samples( request_one.id, request_one.name, samples )
# edit this request
fields = ['option2', str(user_address1.id), 'field three value (edited)']
self.edit_request(request_one.id, request_one.name, request_one.name+' (Renamed)',
request_one.desc+' (Re-described)', fields)
# Sample fields - the tuple represents a sample name and a list of sample form field values
sample_value_tuples = [ ( 'Sample One', [ 'S1 Field 0 Value' ] ),
( 'Sample Two', [ 'S2 Field 0 Value' ] ) ]
strings_displayed_after_submit = [ 'Unsubmitted' ]
for sample_name, field_values in sample_value_tuples:
strings_displayed_after_submit.append( sample_name )
for field_value in field_values:
strings_displayed_after_submit.append( field_value )
# Add samples to the request
self.add_samples( cntrller='requests',
request_id=self.security.encode_id( request_one.id ),
request_name=request_one.name,
sample_value_tuples=sample_value_tuples,
strings_displayed=[ 'Sequencing Request "%s"' % request_one.name,
'There are no samples.' ],
strings_displayed_after_submit=strings_displayed_after_submit )
def test_030_edit_request( self ):
"""Testing editing a sequence run request"""
# logged in as regular_user1
fields = [ 'option2', str( user_address1.id ), 'field three value (edited)' ]
new_name=request_one.name + ' (Renamed)'
new_desc=request_one.desc + ' (Re-described)'
self.edit_request( request_id=self.security.encode_id( request_one.id ),
name=request_one.name,
new_name=new_name,
new_desc=new_desc,
new_fields=fields,
strings_displayed=[ 'Edit sequencing request "%s"' % request_one.name ],
strings_displayed_after_submit=[ new_name, new_desc ] )
refresh( request_one )
# check if the request is showing in the 'new' filter
self.check_request_grid(state=request_one.states.NEW, request_name=request_one.name)
# submit the request
self.submit_request( request_one.id, request_one.name )
self.check_request_grid( cntrller='requests',
state=request_one.states.NEW,
strings_displayed=[ request_one.name ] )
def test_035_submit_request( self ):
"""Testing editing a sequence run request"""
# logged in as regular_user1
self.submit_request( cntrller='requests',
request_id=self.security.encode_id( request_one.id ),
request_name=request_one.name,
strings_displayed_after_submit=[ 'The request <b>%s</b> has been submitted.' % request_one.name ] )
refresh( request_one )
# check if the request is showing in the 'submitted' filter
self.check_request_grid(state=request_one.states.SUBMITTED, request_name=request_one.name)
# check if the request's state is now set to 'submitted'
# Make sure the request is showing in the 'submitted' filter
self.check_request_grid( cntrller='requests',
state=request_one.states.SUBMITTED,
strings_displayed=[ request_one.name ] )
# Make sure the request's state is now set to 'submitted'
assert request_one.state is not request_one.states.SUBMITTED, "The state of the request '%s' should be set to '%s'" \
% ( request_one.name, request_one.states.SUBMITTED )
def test_040_request_lifecycle( self ):
"""Testing request lifecycle as it goes through all the states"""
# goto admin manage requests page
"""Testing request life-cycle as it goes through all the states"""
# logged in as regular_user1
self.logout()
self.login( email=admin_user.email )
self.check_request_admin_grid(state=request_one.states.SUBMITTED, request_name=request_one.name)
self.visit_url( "%s/requests_admin/list?operation=show&id=%s" \
% ( self.url, self.security.encode_id( request_one.id ) ))
self.check_request_grid( cntrller='requests_admin',
state=request_one.states.SUBMITTED,
strings_displayed=[ request_one.name ] )
self.visit_url( "%s/requests_admin/list?operation=show&id=%s" % ( self.url, self.security.encode_id( request_one.id ) ))
self.check_page_for_string( 'Sequencing Request "%s"' % request_one.name )
# set bar codes for the samples
# Set bar codes for the samples
bar_codes = [ '1234567890', '0987654321' ]
self.add_bar_codes( request_one.id, request_one.name, bar_codes, request_one.samples )
# change the states of all the samples of this request
strings_displayed_after_submit=[ 'Changes made to the sample(s) are saved.' ]
for bar_code in bar_codes:
strings_displayed_after_submit.append( bar_code )
self.add_bar_codes( request_id=self.security.encode_id( request_one.id ),
request_name=request_one.name,
bar_codes=bar_codes,
samples=request_one.samples,
strings_displayed_after_submit=strings_displayed_after_submit )
# Change the states of all the samples of this request to ultimately be COMPLETE
for sample in request_one.samples:
self.change_sample_state( request_one.id, request_one.name, sample.name, sample.id, request_type1.states[1].id, request_type1.states[1].name )
self.change_sample_state( request_one.id, request_one.name, sample.name, sample.id, request_type1.states[2].id, request_type1.states[2].name )
self.home()
self.change_sample_state( request_id=self.security.encode_id( request_one.id ),
request_name=request_one.name,
sample_name=sample.name,
sample_id=sample.id,
new_state_id=request_type1.states[1].id,
new_state_name=request_type1.states[1].name )
self.change_sample_state( request_id=self.security.encode_id( request_one.id ),
request_name=request_one.name,
sample_name=sample.name,
sample_id=sample.id,
new_state_id=request_type1.states[2].id,
new_state_name=request_type1.states[2].name )
refresh( request_one )
self.logout()
self.login( email=regular_user1.email )
# check if the request's state is now set to 'complete'
self.check_request_grid(state='Complete', request_name=request_one.name)
self.check_request_grid( cntrller='requests',
state='Complete',
strings_displayed=[ request_one.name ] )
assert request_one.state is not request_one.states.COMPLETE, "The state of the request '%s' should be set to '%s'" \
% ( request_one.name, request_one.states.COMPLETE )
def test_045_admin_create_request_on_behalf_of_regular_user( self ):
"""Testing creating and submitting a request as an admin on behalf of a regular user"""
# Logged in as regular_user1
self.logout()
self.login( email=admin_user.email )
# Create the request
name = "RequestTwo"
# TODO: fix this test so it is no longer simulated.
# simulate request creation
url_str = '%s/requests_common/new?cntrller=requests_admin&create_request_button=Save&select_request_type=%i&select_user=%i&name=%s&refresh=True&field_2=%s&field_0=%s&field_1=%i' \
% ( self.url, request_type1.id, regular_user1.id, name, "field_2_value", 'option1', user_address1.id )
self.home()
self.visit_url( url_str )
self.check_page_for_string( "The new request named <b>%s</b> has been created" % name )
desc = 'Request Two Description'
# Set field values - the tuples in the field_values list include the field_value, and True if refresh_on_change
# is required for that field.
field_value_tuples = [ ( 'option2', False ), ( str( user_address1.id ), True ), ( 'field_2_value', False ) ]
self.create_request( cntrller='requests_admin',
request_type_id=str( request_type1.id ),
select_user_id=str( regular_user1.id ),
name=name,
desc=desc,
refresh='True',
field_value_tuples=field_value_tuples,
strings_displayed=[ 'Add a new request',
test_field_name1,
test_field_name2,
test_field_name3 ],
strings_displayed_after_submit=[ "The new request named <b>%s</b> has been created" % name ] )
global request_two
request_two = get_request_by_name( name )
# check if the request is showing in the 'new' filter
self.check_request_admin_grid(state=request_two.states.NEW, request_name=request_two.name)
# check if the request's state is now set to 'new'
# Make sure the request is showing in the 'new' filter
self.check_request_grid( cntrller='requests_admin',
state=request_two.states.NEW,
strings_displayed=[ request_two.name ] )
# Make sure the request's state is now set to 'new'
assert request_two.state is not request_two.states.NEW, "The state of the request '%s' should be set to '%s'" \
% ( request_two.name, request_two.states.NEW )
# sample fields
samples = [ ( 'Sample One', [ 'S1 Field 0 Value' ] ),
( 'Sample Two', [ 'S2 Field 0 Value' ] ) ]
# add samples to this request
self.add_samples( request_two.id, request_two.name, samples )
# submit the request
self.submit_request_as_admin( request_two.id, request_two.name )
# Sample fields - the tuple represents a sample name and a list of sample form field values
sample_value_tuples = [ ( 'Sample One', [ 'S1 Field 0 Value' ] ),
( 'Sample Two', [ 'S2 Field 0 Value' ] ) ]
strings_displayed_after_submit = [ 'Unsubmitted' ]
for sample_name, field_values in sample_value_tuples:
strings_displayed_after_submit.append( sample_name )
for field_value in field_values:
strings_displayed_after_submit.append( field_value )
# Add samples to the request
self.add_samples( cntrller='requests_admin',
request_id=self.security.encode_id( request_two.id ),
request_name=request_two.name,
sample_value_tuples=sample_value_tuples,
strings_displayed=[ 'Sequencing Request "%s"' % request_two.name,
'There are no samples.' ],
strings_displayed_after_submit=strings_displayed_after_submit )
# Submit the request
self.submit_request( cntrller='requests_admin',
request_id=self.security.encode_id( request_two.id ),
request_name=request_two.name,
strings_displayed_after_submit=[ 'The request <b>%s</b> has been submitted.' % request_two.name ] )
refresh( request_two )
# check if the request is showing in the 'submitted' filter
self.check_request_admin_grid(state=request_two.states.SUBMITTED, request_name=request_two.name)
# check if the request's state is now set to 'submitted'
# Make sure the request is showing in the 'submitted' filter
self.check_request_grid( cntrller='requests_admin',
state=request_two.states.SUBMITTED,
strings_displayed=[ request_two.name ] )
# Make sure the request's state is now set to 'submitted'
assert request_two.state is not request_two.states.SUBMITTED, "The state of the request '%s' should be set to '%s'" \
% ( request_two.name, request_two.states.SUBMITTED )
# check if both the requests is showing in the 'All' filter
self.check_request_admin_grid(state='All', request_name=request_one.name)
self.check_request_admin_grid(state='All', request_name=request_two.name)
# Make sure both requests are showing in the 'All' filter
self.check_request_grid( cntrller='requests_admin',
state='All',
strings_displayed=[ request_one.name, request_two.name ] )
def test_050_reject_request( self ):
'''Testing rejecting a request'''
self.logout()
self.login( email=admin_user.email )
self.reject_request( request_two.id, request_two.name, "Rejection test comment" )
"""Testing rejecting a request"""
# Logged in as admin_user
self.reject_request( request_id=self.security.encode_id( request_two.id ),
request_name=request_two.name,
comment="Rejection test comment",
strings_displayed=[ 'Reject Sequencing Request "%s"' % request_two.name ],
strings_displayed_after_submit=[ 'Request <b>%s</b> has been rejected.' % request_two.name ] )
refresh( request_two )
# check if the request is showing in the 'rejected' filter
self.check_request_admin_grid(state=request_two.states.REJECTED, request_name=request_two.name)
# check if the request's state is now set to 'submitted'
# Make sure the request is showing in the 'rejected' filter
self.check_request_grid( cntrller='requests_admin',
state=request_two.states.REJECTED,
strings_displayed=[ request_two.name ] )
# Make sure the request's state is now set to REJECTED
assert request_two.state is not request_two.states.REJECTED, "The state of the request '%s' should be set to '%s'" \
% ( request_two.name, request_two.states.REJECTED )
def test_055_reset_data_for_later_test_runs( self ):
@@ -371,16 +421,6 @@ class TestFormsAndRequests( TwillTestCase ):
for user_address in [ user_address1 ]:
mark_obj_deleted( user_address )
##################
# Purge all libraries
##################
for library in [ library_one ]:
self.delete_library_item( 'library_admin',
self.security.encode_id( library.id ),
self.security.encode_id( library.id ),
library.name,
item_type='library' )
self.purge_library( self.security.encode_id( library.id ), library.name )
##################
# Delete all non-private roles
##################
for role in [ role_one, role_two ]:
+9 -7
View File
@@ -127,7 +127,7 @@ class TestLibraryFeatures( TwillTestCase ):
ldda_message=ldda_message,
strings_displayed=[ 'Upload files' ] )
global ldda2
ldda2 = get_latest_ldda()
ldda2 = get_latest_ldda_by_name( filename )
assert ldda2 is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda2 from the database'
self.browse_library( 'library_admin',
self.security.encode_id( library1.id ),
@@ -146,7 +146,7 @@ class TestLibraryFeatures( TwillTestCase ):
ldda_message=ldda_message,
strings_displayed=[ 'Upload files' ] )
global ldda3
ldda3 = get_latest_ldda()
ldda3 = get_latest_ldda_by_name( filename )
assert ldda3 is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda3 from the database'
self.browse_library( 'library_admin',
self.security.encode_id( library1.id ),
@@ -155,7 +155,8 @@ class TestLibraryFeatures( TwillTestCase ):
"""Testing copying a dataset from the current history to a subfolder"""
# logged in as admin_user
self.new_history()
self.upload_file( "4.bed" )
filename = '4.bed'
self.upload_file( filename )
latest_hda = get_latest_hda()
self.upload_library_dataset( cntrller='library_admin',
library_id=self.security.encode_id( library1.id ),
@@ -165,7 +166,7 @@ class TestLibraryFeatures( TwillTestCase ):
ldda_message='Imported from history',
strings_displayed=[ 'Active datasets in your current history' ] )
global ldda4
ldda4 = get_latest_ldda()
ldda4 = get_latest_ldda_by_name( filename )
assert ldda4 is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda4 from the database'
self.browse_library( 'library_admin',
self.security.encode_id( library1.id ),
@@ -199,7 +200,7 @@ class TestLibraryFeatures( TwillTestCase ):
ldda_message=ldda_message,
strings_displayed=[ 'Upload files', 'You are currently selecting a new file to replace' ] )
global ldda4_version2
ldda4_version2 = get_latest_ldda()
ldda4_version2 = get_latest_ldda_by_name( filename )
assert ldda4_version2 is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda4_version2 from the database'
self.ldda_edit_info( 'library_admin',
self.security.encode_id( library1.id ),
@@ -271,15 +272,16 @@ class TestLibraryFeatures( TwillTestCase ):
# logged in as regular_user3
self.logout()
self.login( email=admin_user.email )
filename = '1.bed'
self.upload_library_dataset( cntrller='library_admin',
library_id=self.security.encode_id( library1.id ),
folder_id=self.security.encode_id( library1.root_folder.id ),
filename='1.bed',
filename=filename,
file_type='bed',
dbkey='hg18',
strings_displayed=[ 'Upload files' ] )
global ldda1
ldda1 = get_latest_ldda()
ldda1 = get_latest_ldda_by_name( filename )
assert ldda1 is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda1 from the database'
for format in ( 'tbz', 'tgz', 'zip' ):
archive = self.download_archive_of_library_files( cntrller='library',
+12 -12
View File
@@ -153,7 +153,7 @@ class TestLibrarySecurity( TwillTestCase ):
ldda_message=ldda_message,
strings_displayed=[ 'Upload files' ] )
global ldda1
ldda1 = get_latest_ldda()
ldda1 = get_latest_ldda_by_name( filename )
assert ldda1 is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda1 from the database'
self.browse_library( 'library_admin',
self.security.encode_id( library1.id ),
@@ -258,10 +258,10 @@ class TestLibrarySecurity( TwillTestCase ):
ldda_message=ldda_message,
strings_displayed=[ 'Upload files' ] )
global ldda2
ldda2 = get_latest_ldda()
ldda2 = get_latest_ldda_by_name( filename )
assert ldda2 is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda2 from the database'
self.browse_library( 'library',
self.security.encode_id( library1.id ),
self.browse_library( cntrller='library',
id=self.security.encode_id( library1.id ),
strings_displayed=[ ldda2.name, ldda2.message, admin_user.email ] )
def test_045_accessing_ldda2_with_role_associated_with_group_and_users( self ):
"""Testing accessing ldda2 with a role that is associated with a group and users"""
@@ -272,7 +272,7 @@ class TestLibrarySecurity( TwillTestCase ):
strings_displayed=[ ldda2.name, ldda2.message, admin_user.email ] )
self.logout()
# regular_user1 should be able to see 2.bed since she is associated with group_two
self.login( email = 'test1@bx.psu.edu' )
self.login( email = regular_user1.email )
self.browse_library( 'library',
self.security.encode_id( library1.id ),
strings_displayed=[ folder1.name, ldda2.name, ldda2.message, admin_user.email ] )
@@ -293,9 +293,9 @@ class TestLibrarySecurity( TwillTestCase ):
self.security.encode_id( folder1.id ),
self.security.encode_id( ldda2.id ),
ldda2.name,
strings_displayed=['2.bed',
'This is the latest version of this library dataset',
'Edit attributes of 2.bed' ] )
strings_displayed=[ '2.bed',
'This is the latest version of this library dataset',
'Edit attributes of 2.bed' ] )
self.act_on_multiple_datasets( 'library',
self.security.encode_id( library1.id ),
'import_to_history',
@@ -465,7 +465,7 @@ class TestLibrarySecurity( TwillTestCase ):
ldda_message=ldda_message,
strings_displayed=[ 'Upload files' ] )
global ldda6
ldda6 = get_latest_ldda()
ldda6 = get_latest_ldda_by_name( filename )
assert ldda6 is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda6 from the database'
def test_070_add_folder2_to_library2( self ):
"""Testing adding folder2 to a library2"""
@@ -495,7 +495,7 @@ class TestLibrarySecurity( TwillTestCase ):
ldda_message=ldda_message,
strings_displayed=[ 'Upload files' ] )
global ldda7
ldda7 = get_latest_ldda()
ldda7 = get_latest_ldda_by_name( filename )
assert ldda7 is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda7 from the database'
def test_080_add_subfolder2_to_folder2( self ):
"""Testing adding subfolder2 to a folder2"""
@@ -524,10 +524,10 @@ class TestLibrarySecurity( TwillTestCase ):
ldda_message=ldda_message,
strings_displayed=[ 'Upload files' ] )
global ldda8
ldda8 = get_latest_ldda()
ldda8 = get_latest_ldda_by_name( filename )
assert ldda8 is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda8 from the database'
def test_090_make_library2_and_contents_public( self ):
"""Testing making library2 and all of it's contetns public"""
"""Testing making library2 and all of it's contents public"""
self.make_library_item_public( self.security.encode_id( library2.id ),
self.security.encode_id( library2.id ),
item_type='library',
+22 -16
View File
@@ -37,11 +37,16 @@ class TestLibraryFeatures( TwillTestCase ):
# Logged in as admin_user
for type in [ 'AddressField', 'CheckboxField', 'SelectField', 'TextArea', 'TextField', 'WorkflowField' ]:
form_desc = '%s description' % type
num_options = 0
if type == 'SelectField':
# Pass number of options we want in our SelectField
num_options = 2
# Create form for library template
self.create_single_field_type_form_definition( name=type,
desc=form_desc,
formtype=galaxy.model.FormDefinition.types.LIBRARY_INFO_TEMPLATE,
field_type=type )
self.create_form( name=type,
desc=form_desc,
form_type=galaxy.model.FormDefinition.types.LIBRARY_INFO_TEMPLATE,
field_type=type,
num_options=num_options )
# Get all of the new form definitions for later use
global AddressField_form
AddressField_form = get_form( 'AddressField' )
@@ -147,7 +152,7 @@ class TestLibraryFeatures( TwillTestCase ):
user_address1 = get_user_address( admin_user, short_desc )
assert user_address1 is not None, 'Problem retrieving user_address1 from the database'
global ldda1
ldda1 = get_latest_ldda()
ldda1 = get_latest_ldda_by_name( filename )
assert ldda1 is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda1 from the database'
self.browse_library( 'library_admin',
self.security.encode_id( library1.id ),
@@ -269,7 +274,7 @@ class TestLibraryFeatures( TwillTestCase ):
dbkey='hg18',
ldda_message=ldda_message,
strings_displayed=[ 'CheckboxField', 'checked' ] )
ldda = get_latest_ldda()
ldda = get_latest_ldda_by_name( filename )
assert ldda is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda from the database'
self.browse_library( 'library_admin',
self.security.encode_id( library2.id ),
@@ -290,9 +295,10 @@ class TestLibraryFeatures( TwillTestCase ):
self.security.encode_id( SelectField_form.id ),
SelectField_form.name )
# Select the 2nd option in the SelectField to make sure the template contents are inherited
# SelectField option names are zero-based
self.library_info( 'library_admin',
self.security.encode_id( library3.id ),
template_fields=[ ( 'field_0', 'Two' ) ] )
template_fields=[ ( 'field_0', 'Option1' ) ] )
def test_085_add_folder3_to_library3( self ):
"""Testing adding a folder to library3"""
# Logged in as admin_user
@@ -320,10 +326,10 @@ class TestLibraryFeatures( TwillTestCase ):
self.folder_info( cntrller='library_admin',
folder_id=self.security.encode_id( folder3.id ),
library_id=self.security.encode_id( library3.id ),
template_fields=[ ( "field_0", 'Two' ) ],
template_fields=[ ( "field_0", 'Option1' ) ],
strings_displayed=[ SelectField_form.name,
'This is an inherited template and is not required to be used with this folder',
'Two' ] )
'Option1' ] )
def test_100_add_ldda_to_folder3( self ):
"""
Testing adding a new library dataset to library3's folder,
@@ -339,8 +345,8 @@ class TestLibraryFeatures( TwillTestCase ):
file_type='bed',
dbkey='hg18',
ldda_message=ldda_message,
strings_displayed=[ 'SelectField', 'selected>Two' ] )
ldda = get_latest_ldda()
strings_displayed=[ 'SelectField', 'selected>Option1' ] )
ldda = get_latest_ldda_by_name( filename )
assert ldda is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda from the database'
self.browse_library( 'library_admin',
self.security.encode_id( library3.id ),
@@ -351,7 +357,7 @@ class TestLibraryFeatures( TwillTestCase ):
self.security.encode_id( folder3.id ),
self.security.encode_id( ldda.id ),
ldda.name,
strings_displayed=[ 'SelectField', 'Two' ] )
strings_displayed=[ 'SelectField', 'Option1' ] )
def test_105_add_template_to_library4( self ):
""" Testing add an inheritable template containing an TextArea to library4"""
# Logged in as admin_user
@@ -406,7 +412,7 @@ class TestLibraryFeatures( TwillTestCase ):
dbkey='hg18',
ldda_message=ldda_message,
strings_displayed=[ 'TextArea', 'This text should be inherited' ] )
ldda = get_latest_ldda()
ldda = get_latest_ldda_by_name( filename )
assert ldda is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda from the database'
self.browse_library( 'library_admin',
self.security.encode_id( library4.id ),
@@ -471,7 +477,7 @@ class TestLibraryFeatures( TwillTestCase ):
dbkey='hg18',
ldda_message=ldda_message,
strings_displayed=[ 'TextField', 'This text should be inherited' ] )
ldda = get_latest_ldda()
ldda = get_latest_ldda_by_name( filename )
assert ldda is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda from the database'
self.browse_library( 'library_admin',
self.security.encode_id( library5.id ),
@@ -512,7 +518,7 @@ class TestLibraryFeatures( TwillTestCase ):
strings_displayed=[ 'TextField',
'This text should be inherited',
'TextArea' ] )
ldda = get_latest_ldda()
ldda = get_latest_ldda_by_name( filename )
assert ldda is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda from the database'
self.browse_library( 'library_admin',
self.security.encode_id( library5.id ),
@@ -576,7 +582,7 @@ class TestLibraryFeatures( TwillTestCase ):
dbkey='hg18',
ldda_message=ldda_message,
strings_displayed=[ 'WorkflowField', 'none' ] )
ldda = get_latest_ldda()
ldda = get_latest_ldda_by_name( filename )
assert ldda is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda from the database'
self.browse_library( 'library_admin',
self.security.encode_id( library6.id ),
+116 -102
View File
@@ -1,9 +1,6 @@
from base.twilltestcase import *
from base.test_db_util import *
# TODO: ( gvk: 9/17/10 ) The code in this script was so horribly written that it could not be maintained. I will fix the worst code
# as soon as I get a chance. I've already gotten started, but have run out of time so I'm commenting out the broken tests for now...
class TestUserInfo( TwillTestCase ):
def test_000_initiate_users( self ):
"""Ensuring all required user accounts exist"""
@@ -35,154 +32,172 @@ class TestUserInfo( TwillTestCase ):
assert admin_user is not None, 'Problem retrieving user with email "test@bx.psu.edu" from the database'
global admin_user_private_role
admin_user_private_role = get_private_role( admin_user )
"""
def test_005_create_user_info_forms( self ):
Testing creating a new user info form and editing it
"""Testing creating a new user info form and editing it"""
# Logged in as admin_user
# Create a the first form
name = "Student"
desc = "This is Student user info form's description"
formtype = get_user_info_form_definition()
self.create_form( name=name, desc=desc, formtype=formtype, num_fields=0 )
form_type = get_user_info_form_definition()
self.create_form( name=name,
desc=desc,
form_type=form_type,
num_fields=0,
strings_displayed=[ 'Create a new form definition' ],
strings_displayed_after_submit=[ name, desc, form_type ] )
tmp_form = get_form( name )
# Add fields to the form
field_dicts = [ dict( name='Affiliation',
desc='The type of organization you are affiliated with',
type='SelectField',
required='optional',
selectlist=[ 'Educational', 'Research', 'Commercial' ] ),
dict( name='Name of Organization',
desc='',
type='TextField',
required='optional' ),
dict( name='Contact for feedback',
desc='',
type='CheckboxField',
required='optional' ) ]
self.edit_form( id=self.security.encode_id( tmp_form.current.id ),
field_dicts=field_dicts,
field_index=len( tmp_form.fields ),
strings_displayed=[ 'Edit form definition "%s"' % name ],
strings_displayed_after_submit=[ "The form '%s' has been updated with the changes." % name ] )
# Get the form_definition object for later tests
global form_one
form_one = get_form( name )
assert form_one is not None, 'Problem retrieving form named "%s" from the database' % name
# edit form & add few more fields
fields = [dict(name='Affiliation',
desc='The type of organization you are affiliated with',
type='SelectField',
required='optional',
selectlist=['Educational', 'Research', 'Commercial']),
dict(name='Name of Organization',
desc='',
type='TextField',
required='optional'),
dict(name='Contact for feedback',
desc='',
type='CheckboxField',
required='optional')]
self.form_add_field( form_one.current.id,
form_one.name,
form_one.desc,
form_one.type,
field_index=len( form_one.fields ),
fields=fields)
form_one_latest = get_form( form_one.name )
assert len( form_one_latest.fields ) == len( form_one.fields ) + len( fields )
# create the second form
assert len( form_one.fields ) == len( tmp_form.fields ) + len( field_dicts )
# Create the second form
name = "Researcher"
desc = "This is Researcher user info form's description"
self.create_form( name=name, desc=desc, formtype=formtype, num_fields=0 )
self.create_form( name=name,
desc=desc,
form_type=form_type,
num_fields=0,
strings_displayed=[ 'Create a new form definition' ],
strings_displayed_after_submit=[ name, desc, form_type ] )
tmp_form = get_form( name )
# Add fields to the form
field_dicts = [ dict( name='Affiliation',
desc='The type of organization you are affiliated with',
type='SelectField',
required='optional',
selectlist=[ 'Educational', 'Research', 'Commercial' ] ),
dict( name='Name of Organization',
desc='',
type='TextField',
required='optional' ),
dict( name='Contact for feedback',
desc='',
type='CheckboxField',
required='optional' ) ]
self.edit_form( id=self.security.encode_id( tmp_form.current.id ),
field_dicts=field_dicts,
field_index=len( tmp_form.fields ),
strings_displayed=[ 'Edit form definition "%s"' % name ],
strings_displayed_after_submit=[ "The form '%s' has been updated with the changes." % name ] )
# Get the form_definition object for later tests
global form_two
form_two = get_form( name )
assert form_two is not None, 'Problem retrieving form named "%s" from the database' % name
# edit form & add few more fields
fields = [dict(name='Affiliation',
desc='The type of organization you are affiliated with',
type='SelectField',
required='optional',
selectlist=['Educational', 'Research', 'Commercial']),
dict(name='Name of Organization',
desc='',
type='TextField',
required='optional'),
dict(name='Contact for feedback',
desc='',
type='CheckboxField',
required='optional')]
self.form_add_field( form_two.current.id,
form_two.name,
form_two.desc,
form_two.type,
field_index=len( form_one.fields ),
fields=fields )
form_two_latest = get_form( form_two.name )
assert len( form_two_latest.fields ) == len( form_two.fields ) + len( fields )
assert len( form_two.fields ) == len( tmp_form.fields ) + len( field_dicts )
def test_010_user_reqistration_multiple_user_info_forms( self ):
Testing user registration with multiple user info forms
"""Testing user registration with multiple user info forms"""
# Logged in as admin_user
self.logout()
# Create a new user with 'Student' user info form
user_info_values=[ 'Educational', 'Penn State', True ]
self.create_user_with_info( 'test11@bx.psu.edu',
'testuser',
'test11',
user_info_forms='multiple',
user_info_form_id=form_one.id,
user_info_values=user_info_values )
# Create a new user with 'Student' user info form. The user_info_values will be the values
# filled into the fields defined in field_dicts above ( 'Educational' -> 'Affiliation,
# 'Penn State' -> 'Name of Organization', '1' -> 'Contact for feedback' )
email = 'test11@bx.psu.edu'
password = 'testuser'
username = 'test11'
user_info_values=[ 'Educational', 'Penn State', '1' ]
self.create_user_with_info( email=email,
password=password,
username=username,
user_info_select=str( form_one.id ),
user_info_values=user_info_values,
strings_displayed=[ "Create account", "User type" ] )
global regular_user11
regular_user11 = get_user( 'test11@bx.psu.edu' )
assert regular_user11 is not None, 'Problem retrieving user with email "test11@bx.psu.edu" from the database'
regular_user11 = get_user( email )
assert regular_user11 is not None, 'Problem retrieving user with email "%s" from the database' % email
global regular_user11_private_role
regular_user11_private_role = get_private_role( regular_user11 )
self.logout()
self.login( email=regular_user11.email, username='regular-user11' )
self.visit_url( "%s/user/show_info" % self.url )
self.check_page_for_string( "Manage User Information" )
self.check_page_for_string( user_info_values[0] )
self.check_page_for_string( user_info_values[1] )
self.check_page_for_string( '<input type="checkbox" name="field_2" value="true" checked>' )
self.login( email=regular_user11.email, username=username )
self.edit_user_info( strings_displayed=[ "Manage User Information",
user_info_values[0],
user_info_values[1],
'<input type="checkbox" name="field_2" value="true" checked>' ] )
def test_015_user_reqistration_single_user_info_forms( self ):
Testing user registration with a single user info form
"""Testing user registration with a single user info form"""
# Logged in as regular_user_11
self.logout()
self.login( email=admin_user.email )
# Delete the 'Researcher' user info form
mark_form_deleted( form_two )
self.visit_url( '%s/forms/manage?sort=create_time&f-deleted=True' % self.url )
self.check_page_for_string( form_two.name )
# Create a new user with 'Student' user info form
user_info_values=['Educational', 'Penn State', True]
self.create_user_with_info( 'test12@bx.psu.edu', 'testuser', 'test12',
user_info_forms='single',
user_info_form_id=form_one.id,
user_info_values=user_info_values )
self.mark_form_deleted( self.security.encode_id( form_two.current.id ) )
# Create a new user with 'Student' user info form. The user_info_values will be the values
# filled into the fields defined in field_dicts above ( 'Educational' -> 'Affiliation,
# 'Penn State' -> 'Name of Organization', '1' -> 'Contact for feedback' )
email = 'test12@bx.psu.edu'
password = 'testuser'
username = 'test12'
user_info_values=[ 'Educational', 'Penn State', '1' ]
self.create_user_with_info( email=email,
password=password,
username=username,
user_info_select=form_one.id,
user_info_values=user_info_values,
strings_displayed=[ "Create account" ] )
global regular_user12
regular_user12 = get_user( 'test12@bx.psu.edu' )
assert regular_user12 is not None, 'Problem retrieving user with email "test12@bx.psu.edu" from the database'
regular_user12 = get_user( email )
assert regular_user12 is not None, 'Problem retrieving user with email "%s" from the database' % email
global regular_user12_private_role
regular_user12_private_role = get_private_role( regular_user12 )
self.logout()
self.login( email=regular_user12.email, username='regular-user12' )
self.visit_url( "%s/user/show_info" % self.url )
self.check_page_for_string( "Manage User Information" )
self.check_page_for_string( user_info_values[0] )
self.check_page_for_string( user_info_values[1] )
self.check_page_for_string( '<input type="checkbox" name="field_2" value="true" checked>' )
self.login( email=regular_user12.email, username=username )
self.edit_user_info( strings_displayed=[ "Manage User Information",
user_info_values[0],
user_info_values[1],
'<input type="checkbox" name="field_2" value="true" checked>' ] )
def test_020_edit_user_info( self ):
Testing editing user info as a regular user
"""Testing editing user info as a regular user"""
# Logged in as regular_user_12
# Test changing email and user name - first try an invalid user name
self.edit_login_info( new_email='test12_new@bx.psu.edu',
new_username='test12_new',
strings_displayed=[ "User name must contain only lower-case letters, numbers and '-'" ] )
self.edit_user_info( new_email='test12_new@bx.psu.edu',
new_username='test12_new',
strings_displayed_after_submit=[ "Public names must be at least four characters" ] )
# Now try a valid user name
self.edit_login_info( new_email='test12_new@bx.psu.edu',
new_username='test12-new',
strings_displayed=[ 'The login information has been updated with the changes' ] )
self.edit_user_info( new_email='test12_new@bx.psu.edu',
new_username='test12-new',
strings_displayed_after_submit=[ 'The login information has been updated with the changes' ] )
# Since we changed the user's account. make sure the user's private role was changed accordingly
if not get_private_role( regular_user12 ):
raise AssertionError, "The private role for %s was not correctly set when their account (email) was changed" % regular_user12.email
# Test changing password
self.change_password( 'testuser', 'testuser#' )
self.edit_user_info( password='testuser',
new_password='testuser#',\
strings_displayed_after_submit=[ 'The password has been changed.' ] )
self.logout()
refresh( regular_user12 )
# Test logging in with new email and password
self.login( email=regular_user12.email, password='testuser#' )
# Test editing the user info
self.edit_user_info( ['Research', 'PSU'] )
self.edit_user_info( info_values=[ 'Research', 'PSU' ],
strings_displayed_after_submit=[ "The user information has been updated with the changes" ] )
def test_999_reset_data_for_later_test_runs( self ):
Reseting data to enable later test runs to pass
"""Reseting data to enable later test runs to pass"""
# Logged in as regular_user_12
self.logout()
self.login( email=admin_user.email )
##################
# Mark all forms deleted
# Mark all forms deleted that have not yet been marked deleted ( form_two has )
##################
for form in [ form_one, form_two ]:
self.mark_form_deleted( form )
for form in [ form_one ]:
self.mark_form_deleted( self.security.encode_id( form.current.id ) )
###############
# Purge appropriate users
###############
@@ -193,4 +208,3 @@ class TestUserInfo( TwillTestCase ):
refresh( user )
delete_user_roles( user )
delete_obj( user )
"""