root/galaxy-central/test/functional/test_forms_and_requests.py

リビジョン 2, 25.0 KB (コミッタ: hatakeyama, 14 年 前)

import galaxy-central

行番号 
1import galaxy.model
2from galaxy.model.orm import *
3from base.twilltestcase import *
4from base.test_db_util import *
5
6sample_states = [  ( 'New', 'Sample entered into the system' ),
7                   ( 'Received', 'Sample tube received' ),
8                   ( 'Done', 'Sequence run complete' ) ]
9address_dict = dict( short_desc="Office",
10                     name="James Bond",
11                     institution="MI6" ,
12                     address="MI6 Headquarters",
13                     city="London",
14                     state="London",
15                     postal_code="007",
16                     country="United Kingdom",
17                     phone="007-007-0007" )
18
19class TestFormsAndRequests( TwillTestCase ):
20    def test_000_initiate_users( self ):
21        """Ensuring all required user accounts exist"""
22        self.logout()
23        self.login( email='test1@bx.psu.edu', username='regular-user1' )
24        global regular_user1
25        regular_user1 = get_user( 'test1@bx.psu.edu' )
26        assert regular_user1 is not None, 'Problem retrieving user with email "test1@bx.psu.edu" from the database'
27        global regular_user1_private_role
28        regular_user1_private_role = get_private_role( regular_user1 )
29        self.logout()
30        self.login( email='test2@bx.psu.edu', username='regular-user2' )
31        global regular_user2
32        regular_user2 = get_user( 'test2@bx.psu.edu' )
33        assert regular_user2 is not None, 'Problem retrieving user with email "test2@bx.psu.edu" from the database'
34        global regular_user2_private_role
35        regular_user2_private_role = get_private_role( regular_user2 )
36        self.logout()
37        self.login( email='test3@bx.psu.edu', username='regular-user3' )
38        global regular_user3
39        regular_user3 = get_user( 'test3@bx.psu.edu' )
40        assert regular_user3 is not None, 'Problem retrieving user with email "test3@bx.psu.edu" from the database'
41        global regular_user3_private_role
42        regular_user3_private_role = get_private_role( regular_user3 )
43        self.logout()
44        self.login( email='test@bx.psu.edu', username='admin-user' )
45        global admin_user
46        admin_user = get_user( 'test@bx.psu.edu' )
47        assert admin_user is not None, 'Problem retrieving user with email "test@bx.psu.edu" from the database'
48        global admin_user_private_role
49        admin_user_private_role = get_private_role( admin_user )
50    def test_005_create_required_groups_and_roles( self ):
51        """Testing creating all required groups and roles for this script"""
52        # Logged in as admin_user
53        # Create role_one
54        name = 'Role One'
55        description = "This is Role One's description"
56        user_ids = [ str( admin_user.id ), str( regular_user1.id ), str( regular_user3.id ) ]
57        self.create_role( name=name,
58                          description=description,
59                          in_user_ids=user_ids,
60                          in_group_ids=[],
61                          create_group_for_role='no',
62                          private_role=admin_user.email )
63        # Get the role object for later tests
64        global role_one
65        role_one = get_role_by_name( name )
66        # Create group_one
67        name = 'Group One'
68        self.create_group( name=name, in_user_ids=[ str( regular_user1.id ) ], in_role_ids=[ str( role_one.id ) ] )
69        # Get the group object for later tests
70        global group_one
71        group_one = get_group_by_name( name )
72        assert group_one is not None, 'Problem retrieving group named "Group One" from the database'
73        # NOTE: To get this to work with twill, all select lists on the ~/admin/role page must contain at least
74        # 1 option value or twill throws an exception, which is: ParseError: OPTION outside of SELECT
75        # Due to this bug in twill, we create the role, we bypass the page and visit the URL in the
76        # associate_users_and_groups_with_role() method.
77        #
78        #create role_two
79        name = 'Role Two'
80        description = 'This is Role Two'
81        user_ids = [ str( admin_user.id ) ]
82        group_ids = [ str( group_one.id ) ]
83        private_role = admin_user.email
84        self.create_role( name=name,
85                          description=description,
86                          in_user_ids=user_ids,
87                          in_group_ids=group_ids,
88                          private_role=private_role )
89        # Get the role object for later tests
90        global role_two
91        role_two = get_role_by_name( name )
92        assert role_two is not None, 'Problem retrieving role named "Role Two" from the database'
93    def test_010_create_request_form( self ):
94        """Testing creating a request form definition, editing the name and description and adding fields"""
95        # Logged in as admin_user
96        # Create a form definition
97        tmp_name = "Temp form"
98        tmp_desc = "Temp form description"
99        form_type = galaxy.model.FormDefinition.types.REQUEST
100        self.create_form( name=tmp_name,
101                          desc=tmp_desc,
102                          form_type=form_type,
103                          num_fields=0,
104                          strings_displayed=[ 'Create a new form definition' ],
105                          strings_displayed_after_submit=[ tmp_name, tmp_desc, form_type ] )
106        tmp_form = get_form( tmp_name )
107        # Edit the name and description of the form definition, and add 3 fields.
108        new_name = "Request Form"
109        new_desc = "Request Form description"
110        global test_field_name1
111        test_field_name1 = 'Test field name one'
112        global test_field_name2
113        test_field_name2 = 'Test field name two'
114        global test_field_name3
115        test_field_name3 = 'Test field name three'
116        field_dicts = [ dict( name=test_field_name1,
117                             desc='Test field description one',
118                             type='SelectField',
119                             required='optional',
120                             selectlist=[ 'option1', 'option2' ] ),
121                        dict( name=test_field_name2,
122                              desc='Test field description two',
123                              type='AddressField',
124                              required='optional' ),
125                        dict( name=test_field_name3,
126                              desc='Test field description three',
127                              type='TextField',
128                              required='required' ) ]
129        self.edit_form( id=self.security.encode_id( tmp_form.current.id ),
130                        new_form_name=new_name,
131                        new_form_desc=new_desc,
132                        field_dicts=field_dicts,
133                        field_index=len( tmp_form.fields ),
134                        strings_displayed=[ 'Edit form definition "%s"' % tmp_name ],
135                        strings_displayed_after_submit=[ "The form '%s' has been updated with the changes." % new_name ] )
136        # Get the form_definition object for later tests
137        global form_one
138        form_one = get_form( new_name )
139        assert form_one is not None, 'Problem retrieving form named "%s" from the database' % new_name
140        assert len( form_one.fields ) == len( tmp_form.fields ) + len( field_dicts )
141    def test_015_create_sample_form( self ):
142        """Testing creating sample form definition"""
143        name = "Sample Form"
144        desc = "This is Form Two's description"
145        form_type = galaxy.model.FormDefinition.types.SAMPLE
146        form_layout_name = 'Layout Grid One'
147        self.create_form( name=name,
148                          desc=desc,
149                          form_type=form_type,
150                          form_layout_name=form_layout_name,
151                          strings_displayed=[ 'Create a new form definition' ],
152                          strings_displayed_after_submit=[ "The form '%s' has been updated with the changes." % name ] )
153        global form_two
154        form_two = get_form( name )
155        assert form_two is not None, "Error retrieving form %s from db" % name
156    def test_020_create_request_type( self ):
157        """Testing creating a request_type"""
158        request_form = get_form( form_one.name )
159        sample_form = get_form( form_two.name )
160        name = 'Test Requestype'
161        self.create_request_type( name,
162                                  "test sequencer configuration",
163                                  self.security.encode_id( request_form.id ),
164                                  self.security.encode_id( sample_form.id ),
165                                  sample_states,
166                                  strings_displayed=[ 'Create a new sequencer configuration' ],
167                                  strings_displayed_after_submit=[ "Sequencer configuration (%s) has been created" % name ] )
168        global request_type1
169        request_type1 = get_request_type_by_name( name )
170        assert request_type1 is not None, 'Problem retrieving sequencer configuration named "%s" from the database' % name
171        # Set permissions
172        permissions_in = [ k for k, v in galaxy.model.RequestType.permitted_actions.items() ]
173        permissions_out = []
174        # Role one members are: admin_user, regular_user1, regular_user3.  Each of these users will be permitted for
175        # REQUEST_TYPE_ACCESS on this request_type
176        self.request_type_permissions( self.security.encode_id( request_type1.id ),
177                                       request_type1.name,
178                                       str( role_one.id ),
179                                       permissions_in,
180                                       permissions_out )
181        # Make sure the request_type1 is not accessible by regular_user2 since regular_user2 does not have Role1.
182        self.logout()
183        self.login( email=regular_user2.email )
184        self.visit_url( '%s/requests_common/create_request?cntrller=requests&request_type=True' % self.url )
185        try:
186            self.check_page_for_string( 'There are no sequencer configurations created for a new request.' )
187            raise AssertionError, 'The request_type %s is accessible by %s when it should be restricted' % ( request_type1.name, regular_user2.email )
188        except:
189            pass
190        self.logout()
191        self.login( email=admin_user.email )
192    def test_025_create_request( self ):
193        """Testing creating a sequence run request"""
194        # logged in as admin_user
195        # Create a user_address
196        self.logout()
197        self.login( email=regular_user1.email )
198        self.add_user_address( regular_user1.id, address_dict )
199        global user_address1
200        user_address1 = get_user_address( regular_user1, address_dict[ 'short_desc' ] )
201        # Set field values - the tuples in the field_values list include the field_value, and True if refresh_on_change
202        # is required for that field.
203        field_value_tuples = [ ( 'option1', False ), ( str( user_address1.id ), True ), ( 'field three value', False ) ]
204        # Create the request
205        name = 'Request One'
206        desc = 'Request One Description'
207        self.create_request( cntrller='requests',
208                             request_type_id=self.security.encode_id( request_type1.id ),
209                             name=name,
210                             desc=desc,
211                             field_value_tuples=field_value_tuples,
212                             strings_displayed=[ 'Create a new sequencing request',
213                                                 test_field_name1,
214                                                 test_field_name2,
215                                                 test_field_name3 ],
216                             strings_displayed_after_submit=[ name, desc ] )
217        global request_one
218        request_one = get_request_by_name( name )       
219        # Make sure the request's state is now set to NEW
220        assert request_one.state is not request_one.states.NEW, "The state of the request '%s' should be set to '%s'" \
221            % ( request_one.name, request_one.states.NEW )
222        # Sample fields - the tuple represents a sample name and a list of sample form field values
223        sample_value_tuples = [ ( 'Sample One', [ 'S1 Field 0 Value' ] ),
224                                ( 'Sample Two', [ 'S2 Field 0 Value' ] ) ]
225        strings_displayed_after_submit = [ 'Unsubmitted' ]
226        for sample_name, field_values in sample_value_tuples:
227            strings_displayed_after_submit.append( sample_name )
228            for field_value in field_values:
229                strings_displayed_after_submit.append( field_value )
230        # Add samples to the request
231        self.add_samples( cntrller='requests',
232                          request_id=self.security.encode_id( request_one.id ),
233                          request_name=request_one.name,
234                          sample_value_tuples=sample_value_tuples,
235                          strings_displayed=[ 'Sequencing Request "%s"' % request_one.name,
236                                              'There are no samples.' ],
237                          strings_displayed_after_submit=strings_displayed_after_submit )
238    def test_030_edit_basic_request_info( self ):
239        """Testing editing the basic information of a sequence run request"""
240        # logged in as regular_user1
241        fields = [ 'option2', str( user_address1.id ), 'field three value (edited)' ]
242        new_name=request_one.name + ' (Renamed)'
243        new_desc=request_one.desc + ' (Re-described)'
244        self.edit_basic_request_info( request_id=self.security.encode_id( request_one.id ),
245                                      cntrller='requests',
246                                      name=request_one.name,
247                                      new_name=new_name,
248                                      new_desc=new_desc,
249                                      new_fields=fields,
250                                      strings_displayed=[ 'Edit sequencing request "%s"' % request_one.name ],
251                                      strings_displayed_after_submit=[ new_name, new_desc ] )
252        refresh( request_one )
253        # check if the request is showing in the 'new' filter
254        self.check_request_grid( cntrller='requests',
255                                 state=request_one.states.NEW,
256                                 strings_displayed=[ request_one.name ] )
257    def test_035_submit_request( self ):
258        """Testing editing a sequence run request"""
259        # logged in as regular_user1
260        self.submit_request( cntrller='requests',
261                             request_id=self.security.encode_id( request_one.id ),
262                             request_name=request_one.name,
263                             strings_displayed_after_submit=[ 'The request has been submitted.' ] )
264        refresh( request_one )
265        # Make sure the request is showing in the 'submitted' filter
266        self.check_request_grid( cntrller='requests',
267                                 state=request_one.states.SUBMITTED,
268                                 strings_displayed=[ request_one.name ] )
269        # Make sure the request's state is now set to 'submitted'
270        assert request_one.state is not request_one.states.SUBMITTED, "The state of the request '%s' should be set to '%s'" \
271            % ( request_one.name, request_one.states.SUBMITTED )
272    def test_040_request_lifecycle( self ):
273        """Testing request life-cycle as it goes through all the states"""
274        # logged in as regular_user1
275        self.logout()
276        self.login( email=admin_user.email )
277        self.check_request_grid( cntrller='requests_admin',
278                                 state=request_one.states.SUBMITTED,
279                                 strings_displayed=[ request_one.name ] )
280        self.visit_url( "%s/requests_common/manage_request?cntrller=requests&id=%s" % ( self.url, self.security.encode_id( request_one.id ) ) )
281        self.check_page_for_string( 'Sequencing Request "%s"' % request_one.name )
282        # Set bar codes for the samples
283        bar_codes = [ '1234567890', '0987654321' ]
284        strings_displayed_after_submit=[ 'Changes made to the samples are saved.' ]
285        for bar_code in bar_codes:
286            strings_displayed_after_submit.append( bar_code )
287        self.add_bar_codes( request_id=self.security.encode_id( request_one.id ),
288                            request_name=request_one.name,
289                            bar_codes=bar_codes,
290                            samples=request_one.samples,
291                            strings_displayed_after_submit=strings_displayed_after_submit )
292        # Change the states of all the samples of this request to ultimately be COMPLETE
293        self.change_sample_state( request_id=self.security.encode_id( request_one.id ),
294                                  request_name=request_one.name,
295                                  sample_names=[ sample.name for sample in request_one.samples ],
296                                  sample_ids=[ sample.id for sample in request_one.samples ],
297                                  new_sample_state_id=request_type1.states[1].id,
298                                  new_state_name=request_type1.states[1].name )
299        self.change_sample_state( request_id=self.security.encode_id( request_one.id ),
300                                  request_name=request_one.name,
301                                  sample_names=[ sample.name for sample in request_one.samples ],
302                                  sample_ids=[ sample.id for sample in request_one.samples ],
303                                  new_sample_state_id=request_type1.states[2].id,
304                                  new_state_name=request_type1.states[2].name )
305        refresh( request_one )
306        self.logout()
307        self.login( email=regular_user1.email )
308        # check if the request's state is now set to 'complete'
309        self.check_request_grid( cntrller='requests',
310                                 state='Complete',
311                                 strings_displayed=[ request_one.name ] )
312        assert request_one.state is not request_one.states.COMPLETE, "The state of the request '%s' should be set to '%s'" \
313            % ( request_one.name, request_one.states.COMPLETE )
314       
315    def test_045_admin_create_request_on_behalf_of_regular_user( self ):
316        """Testing creating and submitting a request as an admin on behalf of a regular user"""
317        # Logged in as regular_user1
318        self.logout()
319        self.login( email=admin_user.email )
320        # Create the request
321        name = "RequestTwo"
322        desc = 'Request Two Description'
323        # Set field values - the tuples in the field_values list include the field_value, and True if refresh_on_change
324        # is required for that field.
325        field_value_tuples = [ ( 'option2', False ), ( str( user_address1.id ), True ), ( 'field_2_value', False ) ]
326        self.create_request( cntrller='requests_admin',
327                             request_type_id=self.security.encode_id( request_type1.id ),
328                             other_users_id=self.security.encode_id( regular_user1.id ),
329                             name=name,
330                             desc=desc,
331                             field_value_tuples=field_value_tuples,
332                             strings_displayed=[ 'Create a new sequencing request',
333                                                 test_field_name1,
334                                                 test_field_name2,
335                                                 test_field_name3 ],
336                             strings_displayed_after_submit=[ "The request has been created" ] )
337        global request_two
338        request_two = get_request_by_name( name )     
339        # Make sure the request is showing in the 'new' filter
340        self.check_request_grid( cntrller='requests_admin',
341                                 state=request_two.states.NEW,
342                                 strings_displayed=[ request_two.name ] )
343        # Make sure the request's state is now set to 'new'
344        assert request_two.state is not request_two.states.NEW, "The state of the request '%s' should be set to '%s'" \
345            % ( request_two.name, request_two.states.NEW )
346        # Sample fields - the tuple represents a sample name and a list of sample form field values
347        sample_value_tuples = [ ( 'Sample One', [ 'S1 Field 0 Value' ] ),
348                                ( 'Sample Two', [ 'S2 Field 0 Value' ] ) ]
349        strings_displayed_after_submit = [ 'Unsubmitted' ]
350        for sample_name, field_values in sample_value_tuples:
351            strings_displayed_after_submit.append( sample_name )
352            for field_value in field_values:
353                strings_displayed_after_submit.append( field_value )
354        # Add samples to the request
355        self.add_samples( cntrller='requests_admin',
356                          request_id=self.security.encode_id( request_two.id ),
357                          request_name=request_two.name,
358                          sample_value_tuples=sample_value_tuples,
359                          strings_displayed=[ 'Sequencing Request "%s"' % request_two.name,
360                                              'There are no samples.' ],
361                          strings_displayed_after_submit=strings_displayed_after_submit )
362        # Submit the request
363        self.submit_request( cntrller='requests_admin',
364                             request_id=self.security.encode_id( request_two.id ),
365                             request_name=request_two.name,
366                             strings_displayed_after_submit=[ 'The request has been submitted.' ] )
367        refresh( request_two )
368        # Make sure the request is showing in the 'submitted' filter
369        self.check_request_grid( cntrller='requests_admin',
370                                 state=request_two.states.SUBMITTED,
371                                 strings_displayed=[ request_two.name ] )
372        # Make sure the request's state is now set to 'submitted'
373        assert request_two.state is not request_two.states.SUBMITTED, "The state of the request '%s' should be set to '%s'" \
374            % ( request_two.name, request_two.states.SUBMITTED )
375        # Make sure both requests are showing in the 'All' filter
376        self.check_request_grid( cntrller='requests_admin',
377                                 state='All',
378                                 strings_displayed=[ request_one.name, request_two.name ] )
379    def test_050_reject_request( self ):
380        """Testing rejecting a request"""
381        # Logged in as admin_user
382        self.reject_request( request_id=self.security.encode_id( request_two.id ),
383                             request_name=request_two.name,
384                             comment="Rejection test comment",
385                             strings_displayed=[ 'Reject Sequencing Request "%s"' % request_two.name ],
386                             strings_displayed_after_submit=[ 'Request (%s) has been rejected.' % request_two.name ] )
387        refresh( request_two )
388        # Make sure the request is showing in the 'rejected' filter
389        self.check_request_grid( cntrller='requests_admin',
390                                 state=request_two.states.REJECTED,
391                                 strings_displayed=[ request_two.name ] )
392        # Make sure the request's state is now set to REJECTED
393        assert request_two.state is not request_two.states.REJECTED, "The state of the request '%s' should be set to '%s'" \
394            % ( request_two.name, request_two.states.REJECTED )
395    def test_055_reset_data_for_later_test_runs( self ):
396        """Reseting data to enable later test runs to pass"""
397        # Logged in as admin_user
398        ##################
399        # Delete request_type permissions
400        ##################
401        for request_type in [ request_type1 ]:
402            delete_request_type_permissions( request_type.id )
403        ##################
404        # Mark all request_types deleted
405        ##################
406        for request_type in [ request_type1 ]:
407            mark_obj_deleted( request_type )
408        ##################
409        # Mark all requests deleted
410        ##################
411        for request in [ request_one, request_two ]:
412            mark_obj_deleted( request )
413        ##################
414        # Mark all forms deleted
415        ##################
416        for form in [ form_one, form_two ]:
417            self.mark_form_deleted( self.security.encode_id( form.current.id ) )
418        ##################
419        # Mark all user_addresses deleted
420        ##################
421        for user_address in [ user_address1 ]:
422            mark_obj_deleted( user_address )
423        ##################
424        # Delete all non-private roles
425        ##################
426        for role in [ role_one, role_two ]:
427            self.mark_role_deleted( self.security.encode_id( role.id ), role.name )
428            self.purge_role( self.security.encode_id( role.id ), role.name )
429            # Manually delete the role from the database
430            refresh( role )
431            delete( role )
432        ##################
433        # Delete all groups
434        ##################
435        for group in [ group_one ]:
436            self.mark_group_deleted( self.security.encode_id( group.id ), group.name )
437            self.purge_group( self.security.encode_id( group.id ), group.name )
438            # Manually delete the group from the database
439            refresh( group )
440            delete( group )
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。