details: http://www.bx.psu.edu/hg/galaxy/rev/e66e1e99183c changeset: 2585:e66e1e99183c user: rc date: Fri Aug 14 15:47:13 2009 -0400 description: First pass of the functional tests for forms & requests 14 file(s) affected in this change: lib/galaxy/web/controllers/admin.py lib/galaxy/web/controllers/forms.py lib/galaxy/web/controllers/requests.py lib/galaxy/web/controllers/requests_admin.py lib/galaxy/web/controllers/user.py lib/galaxy/web/framework/__init__.py templates/admin/forms/edit_form.mako templates/admin/requests/add_states.mako templates/admin/requests/grid.mako templates/admin/samples/bar_codes.mako templates/admin/samples/events.mako templates/base_panels.mako templates/requests/grid.mako test/base/twilltestcase.py diffs (493 lines): diff -r f3d25adcace6 -r e66e1e99183c lib/galaxy/web/controllers/admin.py --- a/lib/galaxy/web/controllers/admin.py Wed Aug 12 10:31:33 2009 -0400 +++ b/lib/galaxy/web/controllers/admin.py Fri Aug 14 15:47:13 2009 -0400 @@ -2011,7 +2011,7 @@ num_states = int( util.restore_text( params.get( 'num_states', 0 ) )) proceed = True for i in range( num_states ): - if not util.restore_text( params.get( 'new_element_name_%i' % i, None ) ): + if not util.restore_text( params.get( 'state_name_%i' % i, None ) ): proceed = False break if not proceed: @@ -2029,8 +2029,8 @@ ss.delete() ss.flush() for i in range( num_states ): - name = util.restore_text( params.get( 'new_element_name_%i' % i, None )) - desc = util.restore_text( params.get( 'new_element_description_%i' % i, None )) + name = util.restore_text( params.get( 'state_name_%i' % i, None )) + desc = util.restore_text( params.get( 'state_desc_%i' % i, None )) ss = trans.app.model.SampleState(name, desc, rt) ss.flush() msg = "The new request type named '%s' with %s state(s) has been created" % (rt.name, num_states) diff -r f3d25adcace6 -r e66e1e99183c lib/galaxy/web/controllers/forms.py --- a/lib/galaxy/web/controllers/forms.py Wed Aug 12 10:31:33 2009 -0400 +++ b/lib/galaxy/web/controllers/forms.py Fri Aug 14 15:47:13 2009 -0400 @@ -175,7 +175,7 @@ 'visible': True, 'required': False, 'type': BaseField.form_field_types()[0], - 'selectlist': '' } + 'selectlist': [] } self.current_form['fields'].append(empty_field) def __get_field(self, index, **kwd): params = util.Params( kwd ) @@ -183,10 +183,10 @@ # To reproduce, create a new form, click the "add field" button, click the # browser back arrow, then click the "add field" button again. # You should never attempt to "restore_text()" on a None object... - name = util.restore_text( params.get( 'field_name_%i' % index, None ) ) - helptext = util.restore_text( params.get( 'field_helptext_%i' % index, None ) ) + name = util.restore_text( params.get( 'field_name_%i' % index, '' ) ) + helptext = util.restore_text( params.get( 'field_helptext_%i' % index, '' ) ) required = params.get( 'field_required_%i' % index, False ) - field_type = util.restore_text( params.get( 'field_type_%i' % index, None ) ) + field_type = util.restore_text( params.get( 'field_type_%i' % index, '' ) ) if field_type == 'SelectField': selectlist = self.__get_selectbox_options(index, **kwd) return {'label': name, @@ -434,7 +434,10 @@ if field_name in kwd: # the user had already filled out this field and the same form is re-rendered # due to some reason like required fields have been left out. - value = util.restore_text( params.get( field_name, '' ) ) + if field[ 'type' ] == 'CheckboxField': + value = CheckboxField.is_checked( util.restore_text( params.get( field_name, False ) ) ) + else: + value = util.restore_text( params.get( field_name, '' ) ) elif contents: # this field has a saved value value = str(contents[ index ]) diff -r f3d25adcace6 -r e66e1e99183c lib/galaxy/web/controllers/requests.py --- a/lib/galaxy/web/controllers/requests.py Wed Aug 12 10:31:33 2009 -0400 +++ b/lib/galaxy/web/controllers/requests.py Fri Aug 14 15:47:13 2009 -0400 @@ -63,6 +63,7 @@ request_grid = RequestsListGrid() @web.expose + @web.require_login( "create/submit sequencing requests" ) def index( self, trans ): return trans.fill_template( "requests/index.mako" ) @@ -75,6 +76,7 @@ authorized_libraries.append(library) return authorized_libraries @web.expose + @web.require_login( "create/submit sequencing requests" ) def list( self, trans, **kwargs ): ''' List all request made by the current user @@ -206,6 +208,7 @@ copy_list.add_option(s[0], i) return copy_list @web.expose + @web.require_login( "create/submit sequencing requests" ) def show_request(self, trans, **kwd): params = util.Params( kwd ) msg = util.restore_text( params.get( 'msg', '' ) ) @@ -331,6 +334,7 @@ @web.expose + @web.require_login( "create/submit sequencing requests" ) def delete_sample(self, trans, **kwd): params = util.Params( kwd ) msg = util.restore_text( params.get( 'msg', '' ) ) @@ -353,6 +357,7 @@ edit_mode=self.edit_mode) @web.expose + @web.require_login( "create/submit sequencing requests" ) def toggle_request_details(self, trans, **kwd): params = util.Params( kwd ) msg = util.restore_text( params.get( 'msg', '' ) ) @@ -389,6 +394,7 @@ select_reqtype.add_option(rt.name, rt.id) return select_reqtype @web.expose + @web.require_login( "create/submit sequencing requests" ) def new(self, trans, **kwd): params = util.Params( kwd ) msg = util.restore_text( params.get( 'msg', '' ) ) @@ -581,6 +587,7 @@ request.flush() return request @web.expose + @web.require_login( "create/submit sequencing requests" ) def edit(self, trans, **kwd): params = util.Params( kwd ) msg = util.restore_text( params.get( 'msg', '' ) ) @@ -742,10 +749,14 @@ request.flush() kwd = {} kwd['id'] = trans.security.encode_id(request.id) + kwd['status'] = 'done' + kwd['message'] = 'The request <b>%s</b> has been submitted.' % request.name return trans.response.send_redirect( web.url_for( controller='requests', action='list', + show_filter=trans.app.model.Request.states.SUBMITTED, **kwd) ) @web.expose + @web.require_login( "create/submit sequencing requests" ) def submit_request(self, trans, **kwd): params = util.Params( kwd ) try: @@ -775,13 +786,16 @@ # change request's submitted field request.state = request.states.SUBMITTED request.flush() - ## TODO kwd['id'] = trans.security.encode_id(request.id) + kwd['status'] = 'done' + kwd['message'] = 'The request <b>%s</b> has been submitted.' % request.name return trans.response.send_redirect( web.url_for( controller='requests', action='list', + show_filter=trans.app.model.Request.states.SUBMITTED, **kwd) ) @web.expose + @web.require_login( "create/submit sequencing requests" ) def show_events(self, trans, **kwd): params = util.Params( kwd ) try: diff -r f3d25adcace6 -r e66e1e99183c lib/galaxy/web/controllers/requests_admin.py --- a/lib/galaxy/web/controllers/requests_admin.py Wed Aug 12 10:31:33 2009 -0400 +++ b/lib/galaxy/web/controllers/requests_admin.py Fri Aug 14 15:47:13 2009 -0400 @@ -172,6 +172,8 @@ @web.require_admin def bar_codes(self, trans, **kwd): params = util.Params( kwd ) + msg = util.restore_text( params.get( 'msg', '' ) ) + messagetype = params.get( 'messagetype', 'done' ) request_id = params.get( 'request_id', None ) if request_id: request = trans.app.model.Request.get( int( request_id )) @@ -192,7 +194,9 @@ bc)) return trans.fill_template( '/admin/samples/bar_codes.mako', samples_list=[s for s in request.samples], - user=request.user, request=request, widgets=widgets) + user=request.user, request=request, widgets=widgets, + messagetype=messagetype, + msg=msg) @web.expose @web.require_admin def save_bar_codes(self, trans, **kwd): @@ -256,9 +260,10 @@ sample.bar_code = bar_code sample.flush() return trans.response.send_redirect( web.url_for( controller='requests_admin', - action='list', - operation='show_request', - id=trans.security.encode_id(request.id)) ) + action='bar_codes', + request_id=request.id, + msg='Bar codes has been saved for this request', + messagetype='done')) def __set_request_state(self, request): # check if all the samples of the current request are in the final state complete = True diff -r f3d25adcace6 -r e66e1e99183c lib/galaxy/web/controllers/user.py --- a/lib/galaxy/web/controllers/user.py Wed Aug 12 10:31:33 2009 -0400 +++ b/lib/galaxy/web/controllers/user.py Fri Aug 14 15:47:13 2009 -0400 @@ -229,6 +229,8 @@ def manage_addresses(self, trans, **kwd): if trans.user: params = util.Params( kwd ) + msg = util.restore_text( params.get( 'msg', '' ) ) + messagetype = params.get( 'messagetype', 'done' ) show_filter = util.restore_text( params.get( 'show_filter', 'Active' ) ) if show_filter == 'All': addresses = [address for address in trans.user.addresses] @@ -238,7 +240,9 @@ addresses = [address for address in trans.user.addresses if not address.deleted] return trans.fill_template( 'user/address.mako', addresses=addresses, - show_filter=show_filter) + show_filter=show_filter, + msg=msg, + messagetype=messagetype) else: # User not logged in, history group must be only public return trans.show_error_message( "You must be logged in to change your default permitted actions." ) diff -r f3d25adcace6 -r e66e1e99183c lib/galaxy/web/framework/__init__.py --- a/lib/galaxy/web/framework/__init__.py Wed Aug 12 10:31:33 2009 -0400 +++ b/lib/galaxy/web/framework/__init__.py Fri Aug 14 15:47:13 2009 -0400 @@ -641,6 +641,7 @@ self.name = name self.action = action self.submit_text = submit_text + #self.submit_name = submit_text+"_button" self.inputs = [] def add_input( self, type, name, label, value=None, error=None, help=None, use_label=True ): self.inputs.append( FormInput( type, label, name, value, error, help, use_label ) ) diff -r f3d25adcace6 -r e66e1e99183c templates/admin/forms/edit_form.mako --- a/templates/admin/forms/edit_form.mako Wed Aug 12 10:31:33 2009 -0400 +++ b/templates/admin/forms/edit_form.mako Fri Aug 14 15:47:13 2009 -0400 @@ -70,7 +70,7 @@ </%def> <div class="toolForm"> - <div class="toolFormTitle">Edit form definition '${form.name}'</div> + <div class="toolFormTitle">Edit form definition "${form.name}"</div> <form id="edit_form" name="edit_form" action="${h.url_for( controller='forms', action='edit', form_id=form.id, num_fields=len(form.fields) )}" method="post" > %for label, input in form_details: <div class="form-row"> diff -r f3d25adcace6 -r e66e1e99183c templates/admin/requests/add_states.mako --- a/templates/admin/requests/add_states.mako Wed Aug 12 10:31:33 2009 -0400 +++ b/templates/admin/requests/add_states.mako Fri Aug 14 15:47:13 2009 -0400 @@ -12,9 +12,9 @@ %for element_count in range( num_states ): <div class="form-row"> <label>${1+element_count}) State name:</label> - <input type="text" name="new_element_name_${element_count}" value="" size="40"/> + <input type="text" name="state_name_${element_count}" value="" size="40"/> <label>State help text (optional):</label> - <input type="text" name="new_element_description_${element_count}" value="" size="40"/> + <input type="text" name="state_desc_${element_count}" value="" size="40"/> </div> <div style="clear: both"></div> %endfor diff -r f3d25adcace6 -r e66e1e99183c templates/admin/requests/grid.mako --- a/templates/admin/requests/grid.mako Wed Aug 12 10:31:33 2009 -0400 +++ b/templates/admin/requests/grid.mako Fri Aug 14 15:47:13 2009 -0400 @@ -76,7 +76,7 @@ <div class="grid-header"> <h2>${grid.title}</h2> - ##%if len(query.all()): + %if len(trans.user.requests): ##<span class="title">Filter:</span> %for i, filter in enumerate( grid.standard_filters ): %if i > 0: @@ -96,7 +96,7 @@ %endif %endif %endfor - ##%endif + %endif </div> diff -r f3d25adcace6 -r e66e1e99183c templates/admin/samples/bar_codes.mako --- a/templates/admin/samples/bar_codes.mako Wed Aug 12 10:31:33 2009 -0400 +++ b/templates/admin/samples/bar_codes.mako Fri Aug 14 15:47:13 2009 -0400 @@ -40,7 +40,7 @@ </tbody> </table> <div class="form-row"> - <input type="submit" name="save_new_sample_type" value="Save"/> + <input type="submit" name="save_bar_codes" value="Save"/> </div> </form> </div> \ No newline at end of file diff -r f3d25adcace6 -r e66e1e99183c templates/admin/samples/events.mako --- a/templates/admin/samples/events.mako Wed Aug 12 10:31:33 2009 -0400 +++ b/templates/admin/samples/events.mako Fri Aug 14 15:47:13 2009 -0400 @@ -56,7 +56,7 @@ </div> %endfor <div class="form-row"> - <input type="submit" name="add_event" value="Save"/> + <input type="submit" name="add_event_button" value="Save"/> </div> </form> </div> diff -r f3d25adcace6 -r e66e1e99183c templates/base_panels.mako --- a/templates/base_panels.mako Wed Aug 12 10:31:33 2009 -0400 +++ b/templates/base_panels.mako Fri Aug 14 15:47:13 2009 -0400 @@ -150,12 +150,12 @@ ${tab( "libraries", "Libraries", h.url_for( controller='library', action='index' ))} - %if trans.request_types(): + %if trans.user and trans.request_types(): <td class="tab"> <a>Lab</a> <div class="submenu"> <ul> - <li><a target="requests" href="${h.url_for( controller='requests', action='index' )}">Sequencing Requests</a></li> + <li><a href="${h.url_for( controller='requests', action='index' )}">Sequencing Requests</a></li> </ul> </div> </td> diff -r f3d25adcace6 -r e66e1e99183c templates/requests/grid.mako --- a/templates/requests/grid.mako Wed Aug 12 10:31:33 2009 -0400 +++ b/templates/requests/grid.mako Fri Aug 14 15:47:13 2009 -0400 @@ -76,7 +76,7 @@ <div class="grid-header"> <h2>${grid.title}</h2> - ##%if len(query.all()): + %if len(trans.user.requests): ##<span class="title">Filter:</span> %for i, filter in enumerate( grid.standard_filters ): %if i > 0: @@ -88,7 +88,7 @@ <span class="filter"><a href="${h.url_for( controller='requests', action='list', show_filter=filter.label )}">${filter.label}</a></span> %endif %endfor - ##%endif + %endif </div> <ul class="manage-table-actions"> @@ -98,7 +98,6 @@ <span>New request</span></a> </li> </ul> - %if not len(query.all()): There are no request(s). @@ -215,4 +214,4 @@ </tfoot> </table> </form> -%endif \ No newline at end of file +%endif diff -r f3d25adcace6 -r e66e1e99183c test/base/twilltestcase.py --- a/test/base/twilltestcase.py Wed Aug 12 10:31:33 2009 -0400 +++ b/test/base/twilltestcase.py Fri Aug 14 15:47:13 2009 -0400 @@ -968,7 +968,7 @@ self.home() # Form stuff - def create_form( self, name='Form One', description='This is Form One', num_fields=1 ): + def create_form( self, name='Form One', desc='This is Form One', 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 @@ -984,7 +984,7 @@ 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", description ) # form field 1 is the field named name... + tc.fv( "1", "description", desc ) # form field 1 is the field named name... tc.submit( "create_form_button" ) for index in range( num_fields ): field_name = 'field_name_%i' % index @@ -997,7 +997,119 @@ check_str = "The form '%s' has been updated with the changes." % name self.check_page_for_string( check_str ) self.home() - + def edit_form( self, form_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/edit?form_id=%i&show_form=True" % (self.url, form_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_id, form_name, field_index, fields): + """ + Add a new fields to the form definition + """ + self.home() + self.visit_url( "%s/forms/edit?form_id=%i&show_form=True" % (self.url, form_id) ) + self.check_page_for_string( 'Edit form definition "%s"' % form_name) + for i, field in enumerate(fields): + 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': +# for option_index, option in enumerate(field['selectlist']): +# self.visit_url( "%s/forms/edit?select_box_options=add&form_id=%i&field_index=%i" % \ +# (self.url, form_id, index)) +# #data = self.last_page() +# #file( "rc.html", 'wb' ).write(data) +# tc.fv( "1", "field_%i_option_%i" % (index, option_index), option ) + 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/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 ) + self.home() + # Requests stuff + def create_request_type( self, name, desc, request_form_id, sample_form_id, states ): + self.home() + self.visit_url( "%s/admin/request_type?create=True" % self.url ) + self.check_page_for_string( 'Create a new request type' ) + tc.fv( "1", "name", name ) + tc.fv( "1", "description", desc ) + tc.fv( "1", "request_form_id", request_form_id ) + tc.fv( "1", "sample_form_id", sample_form_id ) + tc.fv( "1", "num_states", str( len( states ) ) ) + tc.submit( "define_states_button" ) + self.check_page_for_string( "Create %i states for the '%s' request type" % ( len(states), name )) + for index, state in enumerate(states): + 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( "Request type <b>%s</b> has been created" % name ) + def create_request( self, request_type_id, name, desc, library_id, fields ): + self.home() + self.visit_url( "%s/requests/new?create=True&select_request_type=%i" % (self.url, request_type_id) ) + self.check_page_for_string( 'Add a new request' ) + tc.fv( "1", "name", name ) + tc.fv( "1", "desc", desc ) + tc.fv( "1", "library_id", str(library_id) ) + for index, field_value in enumerate(fields): + tc.fv( "1", "field_%i" % index, field_value ) + tc.submit( "create_request_button" ) + def add_samples( self, request_id, request_name, samples ): + self.home() + self.visit_url( "%s/requests/list?sort=-create_time&operation=show_request&id=%s" % ( self.url, self.security.encode_id( request_id ) )) + self.check_page_for_string( 'Sequencing Request "%s"' % request_name ) + for sample_index, sample in enumerate(samples): + tc.submit( "add_sample_button" ) + sample_name, fields = sample + tc.fv( "1", "sample_%i_name" % sample_index, sample_name ) + for field_index, field_value in enumerate(fields): + tc.fv( "1", "sample_%i_field_%i" % ( sample_index, field_index ), field_value ) + tc.submit( "save_samples_button" ) + def submit_request( self, request_id, request_name ): + self.home() + self.visit_url( "%s/requests/submit_request?id=%i" % ( self.url, request_id )) + self.check_page_for_string( 'The request <b>%s</b> has been submitted.' % request_name ) + def add_bar_codes( self, request_id, request_name, bar_codes ): + self.home() + self.visit_url( "%s/requests_admin/bar_codes?request_id=%i" % (self.url, request_id) ) + self.check_page_for_string( 'Bar codes for Samples of Request "%s"' % request_name ) + for index, bar_code in enumerate(bar_codes): + tc.fv( "1", "sample_%i_bar_code" % index, bar_code ) + tc.submit( "save_bar_codes" ) + def change_sample_state( self, sample_name, sample_id, new_state_id, comment='' ): + self.home() + self.visit_url( "%s/requests_admin/show_events?sample_id=%i" % (self.url, sample_id) ) + self.check_page_for_string( 'Events for Sample "%s"' % sample_name ) + tc.fv( "1", "select_state", str(new_state_id) ) + tc.fv( "1", "comment", comment ) + tc.submit( "add_event_button" ) + # Address stuff + def create_address( self, address ): + self.home() + self.visit_url( "%s/user/new_address" % self.url ) + self.check_page_for_string( 'New address' ) + for name, value in address.iteritems(): + tc.fv( "1", name, value ) + tc.submit( "Save_button" ) # Library stuff def create_library( self, name='Library One', description='This is Library One' ): """Create a new library"""