galaxy-dist commit d6a0dd8e55e2: Sample tracking functional tests refactored till add samples.
# HG changeset patch -- Bitbucket.org # Project galaxy-dist # URL http://bitbucket.org/galaxy/galaxy-dist/overview # User rc # Date 1289406533 18000 # Node ID d6a0dd8e55e2f7d2077bc282bca3e42d98fbb7f2 # Parent ecaf015e009a35a3cf421a87fbab1c5d0bbba5b4 Sample tracking functional tests refactored till add samples. Rest of the tests are disabled. --- a/test/functional/test_sample_tracking.py +++ b/test/functional/test_sample_tracking.py @@ -17,6 +17,9 @@ address_dict = dict( short_desc="Office" phone="007-007-0007" ) class TestFormsAndRequests( TwillTestCase ): + # + # ====== Setup Users, Groups & Roles required for this test suite ========= + # def test_000_initiate_users( self ): """Ensuring all required user accounts exist""" self.logout() @@ -50,9 +53,9 @@ class TestFormsAndRequests( TwillTestCas def test_005_create_required_groups_and_roles( self ): """Testing creating all required groups and roles for this script""" # Logged in as admin_user - # Create role_one - name = 'Role One' - description = "This is Role One's description" + # Create role1 + name = 'Role1' + description = "This is Role1's description" user_ids = [ str( admin_user.id ), str( regular_user1.id ), str( regular_user3.id ) ] self.create_role( name=name, description=description, @@ -61,25 +64,25 @@ class TestFormsAndRequests( TwillTestCas create_group_for_role='no', private_role=admin_user.email ) # Get the role object for later tests - global role_one - role_one = get_role_by_name( name ) - # Create group_one - name = 'Group One' - self.create_group( name=name, in_user_ids=[ str( regular_user1.id ) ], in_role_ids=[ str( role_one.id ) ] ) + global role1 + role1 = get_role_by_name( name ) + # Create group1 + name = 'Group1' + self.create_group( name=name, in_user_ids=[ str( regular_user1.id ) ], in_role_ids=[ str( role1.id ) ] ) # Get the group object for later tests - global group_one - group_one = get_group_by_name( name ) - assert group_one is not None, 'Problem retrieving group named "Group One" from the database' + global group1 + group1 = get_group_by_name( name ) + assert group1 is not None, 'Problem retrieving group named "Group1" from the database' # NOTE: To get this to work with twill, all select lists on the ~/admin/role page must contain at least # 1 option value or twill throws an exception, which is: ParseError: OPTION outside of SELECT # Due to this bug in twill, we create the role, we bypass the page and visit the URL in the # associate_users_and_groups_with_role() method. # - #create role_two - name = 'Role Two' - description = 'This is Role Two' + #create role2 + name = 'Role2' + description = 'This is Role2' user_ids = [ str( admin_user.id ) ] - group_ids = [ str( group_one.id ) ] + group_ids = [ str( group1.id ) ] private_role = admin_user.email self.create_role( name=name, description=description, @@ -87,11 +90,14 @@ class TestFormsAndRequests( TwillTestCas in_group_ids=group_ids, private_role=private_role ) # Get the role object for later tests - 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_request_form( self ): - """Testing creating a request form definition, editing the name and description and adding fields""" + global role2 + role2 = get_role_by_name( name ) + assert role2 is not None, 'Problem retrieving role named "Role2" from the database' + # + # ====== Form definition test methods ================================================ + # + def test_010_create_request_form_definition( self ): + """Testing creating a sequencing request form definition, editing the name and description and adding fields""" # Logged in as admin_user # Create a form definition tmp_name = "Temp form" @@ -107,23 +113,23 @@ class TestFormsAndRequests( TwillTestCas # 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', + global request_field_name1 + request_field_name1 = 'Request form field1' + global request_field_name2 + request_field_name2 = 'Request form field2' + global request_field_name3 + request_field_name3 = 'Request form field3' + field_dicts = [ dict( name=request_field_name1, + desc='Description of '+request_field_name1, type='SelectField', required='optional', selectlist=[ 'option1', 'option2' ] ), - dict( name=test_field_name2, - desc='Test field description two', + dict( name=request_field_name2, + desc='Description of '+request_field_name2, type='AddressField', required='optional' ), - dict( name=test_field_name3, - desc='Test field description three', + dict( name=request_field_name3, + desc='Description of '+request_field_name3, type='TextField', required='required' ) ] self.edit_form( id=self.security.encode_id( tmp_form.current.id ), @@ -134,48 +140,99 @@ class TestFormsAndRequests( TwillTestCas 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( new_name ) - 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""" + global request_form_definition1 + request_form_definition1 = get_form( new_name ) + assert request_form_definition1 is not None, 'Problem retrieving form named "%s" from the database' % new_name + assert len( request_form_definition1.fields ) == len( tmp_form.fields ) + len( field_dicts ) + # check form view + self.view_form( id=self.security.encode_id( request_form_definition1.current.id ), + form_name=new_name, + form_desc=new_desc, + form_type=form_type, + field_dicts=field_dicts ) + def test_015_create_sample_form_definition( self ): + """Testing creating sequencing sample form definition and adding fields""" name = "Sample Form" - desc = "This is Form Two's description" + desc = "This is Sample Form's description" form_type = galaxy.model.FormDefinition.types.SAMPLE - form_layout_name = 'Layout Grid One' + global sample_form_layout_grid_name + sample_form_layout_grid_name = 'Layout Grid1' self.create_form( name=name, desc=desc, form_type=form_type, - form_layout_name=form_layout_name, + form_layout_name=sample_form_layout_grid_name, + num_fields=0, 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 + tmp_form = get_form( name ) + # now add fields to the sample form definition + global sample_field_name1 + sample_field_name1 = 'Sample form field1' + global sample_field_name2 + sample_field_name2 = 'Sample form field2' + global sample_field_name3 + sample_field_name3 = 'Sample form field3' + field_dicts = [ dict( name=sample_field_name1, + desc='Description of '+sample_field_name1, + type='SelectField', + required='optional', + selectlist=[ 'option1', 'option2' ] ), + dict( name=sample_field_name2, + desc='Description of '+sample_field_name2, + type='TextField', + required='optional' ), + dict( name=sample_field_name3, + desc='Description of '+sample_field_name3, + type='TextField', + required='required' ) ] + self.edit_form( id=self.security.encode_id( tmp_form.current.id ), + new_form_name=name, + new_form_desc=desc, + 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 ] ) + global sample_form_definition1 + sample_form_definition1 = get_form( name ) + assert sample_form_definition1 is not None, "Error retrieving form %s from db" % name + print len( sample_form_definition1.fields ), len( field_dicts ) + print sample_form_definition1.fields + print field_dicts + assert len( sample_form_definition1.fields ) == len( field_dicts ) + # check form view + self.view_form( id=self.security.encode_id( sample_form_definition1.current.id ), + form_name=name, + form_desc=desc, + form_type=form_type, + form_layout_name=sample_form_layout_grid_name, + field_dicts=field_dicts ) 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' + name = 'Sequencer configuration1' self.create_request_type( name, "test sequencer configuration", - self.security.encode_id( request_form.id ), - self.security.encode_id( sample_form.id ), + self.security.encode_id( request_form_definition1.id ), + self.security.encode_id( sample_form_definition1.id ), sample_states, strings_displayed=[ 'Create a new sequencer configuration' ], strings_displayed_after_submit=[ "Sequencer configuration (%s) 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 + # check view + self.view_request_type( self.security.encode_id( request_type1.id ), + request_type1.name, + strings_displayed=[ request_form_definition1.name, + sample_form_definition1.name ], + sample_states=sample_states) # Set permissions permissions_in = [ k for k, v in galaxy.model.RequestType.permitted_actions.items() ] permissions_out = [] - # Role one members are: admin_user, regular_user1, regular_user3. Each of these users will be permitted for + # Role1 members are: admin_user, regular_user1, regular_user3. Each of these users will be permitted for # REQUEST_TYPE_ACCESS on this request_type self.request_type_permissions( self.security.encode_id( request_type1.id ), request_type1.name, - str( role_one.id ), + str( role1.id ), permissions_in, permissions_out ) # Make sure the request_type1 is not accessible by regular_user2 since regular_user2 does not have Role1. @@ -189,8 +246,11 @@ class TestFormsAndRequests( TwillTestCas pass self.logout() self.login( email=admin_user.email ) + # + # ====== Sequencing request test methods - User perspective ================ + # def test_025_create_request( self ): - """Testing creating a sequence run request""" + """Testing creating a sequencing request as a regular user""" # logged in as admin_user # Create a user_address self.logout() @@ -200,195 +260,223 @@ class TestFormsAndRequests( TwillTestCas 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 ) ] + field_value_tuples = [ ( 'option1', False ), ( str( user_address1.id ), True ), ( 'field3 value', False ) ] # Create the request - name = 'Request One' - desc = 'Request One Description' + name = 'Request1' + desc = 'Request1 Description' self.create_request( cntrller='requests', request_type_id=self.security.encode_id( request_type1.id ), name=name, desc=desc, field_value_tuples=field_value_tuples, strings_displayed=[ 'Create a new sequencing request', - test_field_name1, - test_field_name2, - test_field_name3 ], + request_field_name1, + request_field_name2, + request_field_name3 ], strings_displayed_after_submit=[ name, desc ] ) - global request_one - request_one = get_request_by_name( name ) + global request1 + request1 = get_request_by_name( name ) # 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 ) + assert request1.state is not request1.states.NEW, "The state of the request '%s' should be set to '%s'" \ + % ( request1.name, request1.states.NEW ) + # check request page + self.view_request( cntrller='requests', + request_id=self.security.encode_id( request1.id ), + strings_displayed=[ 'Sequencing request "%s"' % request1.name, + 'There are no samples.', + sample_form_layout_grid_name ], + strings_not_displayed=[ request1.states.SUBMITTED, + request1.states.COMPLETE, + request1.states.REJECTED ] ) + # check if the request is showing in the 'new' filter + self.check_request_grid( cntrller='requests', + state=request1.states.NEW, + strings_displayed=[ request1.name ] ) + self.view_request_history( cntrller='requests', + request_id=self.security.encode_id( request1.id ), + strings_displayed=[ 'History of Sequencing Request "%s"' % request1.name, + request1.states.NEW, + 'Request created' ], + strings_not_displayed=[ request1.states.SUBMITTED, + request1.states.COMPLETE, + request1.states.REJECTED ] ) + def test_030_edit_basic_request_info( self ): + """Testing editing the basic information of a sequencing request""" + # logged in as regular_user1 + fields = [ 'option2', str( user_address1.id ), 'field3 value (edited)' ] + new_name=request1.name + ' (Renamed)' + new_desc=request1.desc + ' (Re-described)' + self.edit_basic_request_info( request_id=self.security.encode_id( request1.id ), + cntrller='requests', + name=request1.name, + new_name=new_name, + new_desc=new_desc, + new_fields=fields, + strings_displayed=[ 'Edit sequencing request "%s"' % request1.name ], + strings_displayed_after_submit=[ new_name, new_desc ] ) + refresh( request1 ) + def test_035_add_samples_to_request( self ): + """Testing adding samples to request""" + # logged in as regular_user1 # 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' ] ) ] + sample_value_tuples = [ ( 'Sample1', [ 'option1', 'sample1 field2 value', 'sample1 field3 value' ] ), + ( 'Sample2', [ 'option2', 'sample2 field2 value', 'sample2 field3 value' ] ), + ( 'Sample3', [ 'option1', 'sample3 field2 value', 'sample3 field3 value' ] ) ] strings_displayed_after_submit = [ 'Unsubmitted' ] for sample_name, field_values in sample_value_tuples: strings_displayed_after_submit.append( sample_name ) # Add samples to the request self.add_samples( cntrller='requests', - request_id=self.security.encode_id( request_one.id ), - request_name=request_one.name, + request_id=self.security.encode_id( request1.id ), + request_name=request1.name, sample_value_tuples=sample_value_tuples, - strings_displayed=[ 'There are no samples.' ], + strings_displayed=[ 'Add Samples to Request "%s"' % request1.name, + '<input type="text" name="sample_0_name" value="Sample_1" size="10"/>' ], # sample name input field strings_displayed_after_submit=strings_displayed_after_submit ) - def test_030_edit_basic_request_info( self ): - """Testing editing the basic information of 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_basic_request_info( request_id=self.security.encode_id( request_one.id ), - cntrller='requests', - 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( 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 has been submitted.' ] ) - refresh( request_one ) - # 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 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_grid( cntrller='requests_admin', - state=request_one.states.SUBMITTED, - strings_displayed=[ request_one.name ] ) - self.visit_url( "%s/requests_common/view_request?cntrller=requests&id=%s" % ( self.url, self.security.encode_id( request_one.id ) ) ) - # TODO: add some string for checking on the page above... - # Set bar codes for the samples - bar_codes = [ '1234567890', '0987654321' ] - strings_displayed_after_submit=[ 'Changes made to the samples have been 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 - self.change_sample_state( request_id=self.security.encode_id( request_one.id ), - request_name=request_one.name, - sample_names=[ sample.name for sample in request_one.samples ], - sample_ids=[ sample.id for sample in request_one.samples ], - new_sample_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_names=[ sample.name for sample in request_one.samples ], - sample_ids=[ sample.id for sample in request_one.samples ], - new_sample_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( 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" - 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=self.security.encode_id( request_type1.id ), - other_users_id=self.security.encode_id( regular_user1.id ), - name=name, - desc=desc, - field_value_tuples=field_value_tuples, - strings_displayed=[ 'Create a new sequencing request', - test_field_name1, - test_field_name2, - test_field_name3 ], - strings_displayed_after_submit=[ "The request has been created." ] ) - global request_two - request_two = get_request_by_name( name ) - # 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 - 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 ) - # 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=[ '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 has been submitted.' ] ) - refresh( request_two ) - # 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 ) - # 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""" - # 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 (%s) has been rejected.' % request_two.name ] ) - refresh( request_two ) - # 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_040_edit_samples_of_new_request( self ): +# """Testing editing the sample information of new request1""" +# # logged in as regular_user1 +# pass +# 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( request1.id ), +# request_name=request1.name, +# strings_displayed_after_submit=[ 'The request has been submitted.' ] ) +# refresh( request1 ) +# # Make sure the request is showing in the 'submitted' filter +# self.check_request_grid( cntrller='requests', +# state=request1.states.SUBMITTED, +# strings_displayed=[ request1.name ] ) +# # Make sure the request's state is now set to 'submitted' +# assert request1.state is not request1.states.SUBMITTED, "The state of the request '%s' should be set to '%s'" \ +# % ( request1.name, request1.states.SUBMITTED ) +# def test_040_request_lifecycle( self ): +# """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_grid( cntrller='requests_admin', +# state=request1.states.SUBMITTED, +# strings_displayed=[ request1.name ] ) +# self.visit_url( "%s/requests_common/view_request?cntrller=requests&id=%s" % ( self.url, self.security.encode_id( request1.id ) ) ) +# # TODO: add some string for checking on the page above... +# # Set bar codes for the samples +# bar_codes = [ '1234567890', '0987654321' ] +# strings_displayed_after_submit=[ 'Changes made to the samples have been saved.' ] +# for bar_code in bar_codes: +# strings_displayed_after_submit.append( bar_code ) +# self.add_bar_codes( request_id=self.security.encode_id( request1.id ), +# request_name=request1.name, +# bar_codes=bar_codes, +# samples=request1.samples, +# strings_displayed_after_submit=strings_displayed_after_submit ) +# # Change the states of all the samples of this request to ultimately be COMPLETE +# self.change_sample_state( request_id=self.security.encode_id( request1.id ), +# request_name=request1.name, +# sample_names=[ sample.name for sample in request1.samples ], +# sample_ids=[ sample.id for sample in request1.samples ], +# new_sample_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( request1.id ), +# request_name=request1.name, +# sample_names=[ sample.name for sample in request1.samples ], +# sample_ids=[ sample.id for sample in request1.samples ], +# new_sample_state_id=request_type1.states[2].id, +# new_state_name=request_type1.states[2].name ) +# refresh( request1 ) +# self.logout() +# self.login( email=regular_user1.email ) +# # check if the request's state is now set to 'complete' +# self.check_request_grid( cntrller='requests', +# state='Complete', +# strings_displayed=[ request1.name ] ) +# assert request1.state is not request1.states.COMPLETE, "The state of the request '%s' should be set to '%s'" \ +# % ( request1.name, request1.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 = "Request2" +# desc = 'Request2 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=self.security.encode_id( request_type1.id ), +# other_users_id=self.security.encode_id( regular_user1.id ), +# name=name, +# desc=desc, +# field_value_tuples=field_value_tuples, +# strings_displayed=[ 'Create a new sequencing request', +# request_field_name1, +# request_field_name2, +# request_field_name3 ], +# strings_displayed_after_submit=[ "The request has been created." ] ) +# global request2 +# request2 = get_request_by_name( name ) +# # Make sure the request is showing in the 'new' filter +# self.check_request_grid( cntrller='requests_admin', +# state=request2.states.NEW, +# strings_displayed=[ request2.name ] ) +# # Make sure the request's state is now set to 'new' +# assert request2.state is not request2.states.NEW, "The state of the request '%s' should be set to '%s'" \ +# % ( request2.name, request2.states.NEW ) +# # Sample fields - the tuple represents a sample name and a list of sample form field values +# sample_value_tuples = [ ( 'Sample1', [ 'S1 Field 0 Value' ] ), +# ( 'Sample2', [ '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 ) +# # Add samples to the request +# self.add_samples( cntrller='requests_admin', +# request_id=self.security.encode_id( request2.id ), +# request_name=request2.name, +# sample_value_tuples=sample_value_tuples, +# strings_displayed=[ '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( request2.id ), +# request_name=request2.name, +# strings_displayed_after_submit=[ 'The request has been submitted.' ] ) +# refresh( request2 ) +# # Make sure the request is showing in the 'submitted' filter +# self.check_request_grid( cntrller='requests_admin', +# state=request2.states.SUBMITTED, +# strings_displayed=[ request2.name ] ) +# # Make sure the request's state is now set to 'submitted' +# assert request2.state is not request2.states.SUBMITTED, "The state of the request '%s' should be set to '%s'" \ +# % ( request2.name, request2.states.SUBMITTED ) +# # Make sure both requests are showing in the 'All' filter +# self.check_request_grid( cntrller='requests_admin', +# state='All', +# strings_displayed=[ request1.name, request2.name ] ) +# def test_050_reject_request( self ): +# """Testing rejecting a request""" +# # Logged in as admin_user +# self.reject_request( request_id=self.security.encode_id( request2.id ), +# request_name=request2.name, +# comment="Rejection test comment", +# strings_displayed=[ 'Reject Sequencing Request "%s"' % request2.name ], +# strings_displayed_after_submit=[ 'Request (%s) has been rejected.' % request2.name ] ) +# refresh( request2 ) +# # Make sure the request is showing in the 'rejected' filter +# self.check_request_grid( cntrller='requests_admin', +# state=request2.states.REJECTED, +# strings_displayed=[ request2.name ] ) +# # Make sure the request's state is now set to REJECTED +# assert request2.state is not request2.states.REJECTED, "The state of the request '%s' should be set to '%s'" \ +# % ( request2.name, request2.states.REJECTED ) def test_055_reset_data_for_later_test_runs( self ): """Reseting data to enable later test runs to pass""" # Logged in as admin_user + self.logout() + self.login( email=admin_user.email ) ################## # Delete request_type permissions ################## @@ -402,12 +490,12 @@ class TestFormsAndRequests( TwillTestCas ################## # Mark all requests deleted ################## - for request in [ request_one, request_two ]: + for request in [ request1 ]: mark_obj_deleted( request ) ################## # Mark all forms deleted ################## - for form in [ form_one, form_two ]: + for form in [ request_form_definition1, sample_form_definition1 ]: self.mark_form_deleted( self.security.encode_id( form.current.id ) ) ################## # Mark all user_addresses deleted @@ -417,18 +505,18 @@ class TestFormsAndRequests( TwillTestCas ################## # Delete all non-private roles ################## - for role in [ role_one, role_two ]: + for role in [ role1, role2 ]: self.mark_role_deleted( self.security.encode_id( role.id ), role.name ) self.purge_role( self.security.encode_id( role.id ), role.name ) # Manually delete the role from the database refresh( role ) - delete( role ) + delete_obj( role ) ################## # Delete all groups ################## - for group in [ group_one ]: + for group in [ group1 ]: self.mark_group_deleted( self.security.encode_id( group.id ), group.name ) self.purge_group( self.security.encode_id( group.id ), group.name ) # Manually delete the group from the database refresh( group ) - delete( group ) + delete_obj( group ) --- a/test/base/twilltestcase.py +++ b/test/base/twilltestcase.py @@ -870,6 +870,14 @@ class TwillTestCase( unittest.TestCase ) fname = self.write_temp_file( page ) errmsg = "no match to '%s'\npage content written to '%s'" % ( patt, fname ) raise AssertionError( errmsg ) + + def check_string_not_in_page( self, patt ): + """Checks to make sure 'patt' is NOT in the page.""" + page = self.last_page() + if page.find( patt ) != -1: + fname = self.write_temp_file( page ) + errmsg = "string (%s) incorrectly displayed in page.\npage content written to '%s'" % ( patt, fname ) + raise AssertionError( errmsg ) def write_temp_file( self, content, suffix='.html' ): fd, fname = tempfile.mkstemp( suffix=suffix, prefix='twilltestcase-' ) @@ -1330,6 +1338,9 @@ class TwillTestCase( unittest.TestCase ) if form_type == "Sequencing Sample Form": tc.submit( "add_layout_grid" ) tc.fv( "1", "grid_layout0", form_layout_name ) + # if not adding any fields at this time, remove the default empty field + if num_fields == 0: + tc.submit( "remove_button" ) # Add fields to the new form definition for index1 in range( num_fields ): field_name = 'field_name_%i' % index1 @@ -1357,9 +1368,8 @@ class TwillTestCase( unittest.TestCase ) else: tc.fv( "1", "field_type_0", field_type ) tc.fv( "1", field_default, field_default_contents ) + # All done... now save 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() @@ -1392,7 +1402,7 @@ class TwillTestCase( unittest.TestCase ) # 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.submit( "addoption_%i" % index ) tc.fv( "1", "field_%i_option_%i" % ( index, option_index ), option ) else: tc.fv( "1", field_type, field_type_value ) @@ -1400,6 +1410,22 @@ class TwillTestCase( unittest.TestCase ) for check_str in strings_displayed_after_submit: self.check_page_for_string( check_str ) self.home() + def view_form( self, id, form_type='', form_name='', form_desc='', form_layout_name='', field_dicts=[] ): + '''View form details''' + self.home() + self.visit_url( "%s/forms/manage?operation=view&id=%s" % ( self.url, id ) ) + self.check_page_for_string( form_type ) + self.check_page_for_string( form_name ) + self.check_page_for_string( form_desc ) + self.check_page_for_string( form_layout_name ) + for i, field_dict in enumerate( field_dicts ): + self.check_page_for_string( field_dict[ 'name' ] ) + self.check_page_for_string( field_dict[ 'desc' ] ) + self.check_page_for_string( field_dict[ 'type' ] ) + if field_dict[ 'type' ].lower() == 'selectfield': + for option_index, option in enumerate( field_dict[ 'selectlist' ] ): + self.check_page_for_string( option ) + self.home() def mark_form_deleted( self, form_id ): """Mark a form_definition as deleted""" self.home() @@ -1445,6 +1471,17 @@ 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 view_request_type( self, request_type_id, request_type_name, sample_states, strings_displayed=[] ): + '''View request_type details''' + self.home() + self.visit_url( "%s/requests_admin/browse_request_types?operation=view&id=%s" % ( self.url, request_type_id ) ) + self.check_page_for_string( 'Sequencer configuration information' ) + self.check_page_for_string( request_type_name ) + for name, desc in sample_states: + self.check_page_for_string( name ) + self.check_page_for_string( desc ) + for check_str in strings_displayed: + self.check_page_for_string( check_str ) def create_request( self, cntrller, request_type_id, name, desc, field_value_tuples, other_users_id='', strings_displayed=[], strings_displayed_after_submit=[] ): self.visit_url( "%s/requests_common/create_request?cntrller=%s" % ( self.url, cntrller ) ) @@ -1473,6 +1510,18 @@ class TwillTestCase( unittest.TestCase ) for check_str in strings_displayed_after_submit: self.check_page_for_string( check_str ) self.home() + def view_request( self, cntrller, request_id, strings_displayed=[], strings_not_displayed=[] ): + self.visit_url( "%s/%s/browse_requests?operation=view_request&id=%s" % ( self.url, cntrller, request_id ) ) + for check_str in strings_displayed: + self.check_page_for_string( check_str ) + for check_str in strings_not_displayed: + self.check_string_not_in_page( check_str ) + def view_request_history( self, cntrller, request_id, strings_displayed=[], strings_not_displayed=[] ): + self.visit_url( "%s/requests_common/request_events?cntrller=%s&id=%s" % ( self.url, cntrller, request_id ) ) + for check_str in strings_displayed: + self.check_page_for_string( check_str ) + for check_str in strings_not_displayed: + self.check_string_not_in_page( check_str ) def edit_basic_request_info( self, cntrller, request_id, name, new_name='', new_desc='', new_fields=[], strings_displayed=[], strings_displayed_after_submit=[] ): self.visit_url( "%s/requests_common/edit_basic_request_info?cntrller=%s&id=%s" % ( self.url, cntrller, request_id ) ) @@ -1489,40 +1538,22 @@ class TwillTestCase( unittest.TestCase ) 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_common/edit_samples?cntrller=%s&id=%s&editing_samples=False" % ( self.url, cntrller, request_id ) ) + url = "%s/requests_common/add_sample?cntrller=%s&request_id=%s&add_sample_button=Add+sample" % ( self.url, cntrller, request_id ) + self.visit_url( url ) 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/edit_samples?cntrller=%s&id=%s&editing_samples=False" % ( 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 edit_samples. - # 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 edit_samples - # # 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 ) + for sample_index, sample_info in enumerate( sample_value_tuples ): + sample_name = sample_info[0] + sample_field_values = sample_info[1] + tc.fv( "1", "sample_%i_name" % sample_index, sample_name ) + for field_index, field_value in enumerate( sample_field_values ): + tc.fv( "1", "sample_%i_field_%i" % ( sample_index, field_index ), field_value ) + # Do not click on Add sample button when all the sample have been added + if sample_index < len( sample_value_tuples ) - 1: + tc.submit( "add_sample_button" ) + # select the correct form before submitting it + tc.fv( "1", "copy_sample_index", "-1" ) + tc.submit( "save_samples_button" ) 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=[] ): --- a/templates/requests/common/edit_samples.mako +++ b/templates/requests/common/edit_samples.mako @@ -136,8 +136,10 @@ %endif <p/><div class="form-row"> + ## hidden element to make twill work. + <input type="hidden" name="hidden_input" value=""/> %if ( request.samples or current_samples ) and ( editing_samples or len( current_samples ) > len( request.samples ) ): - <input type="submit" name="add_sample_button" value="Add sample"/> + <input type="submit" name="add_sample_button" value="Add sample" /><input type="submit" name="save_samples_button" value="Save"/><input type="submit" name="cancel_changes_button" value="Cancel"/><div class="toolParamHelp" style="clear: both;">
participants (1)
-
commits-noreply@bitbucket.org