PageRenderTime 71ms CodeModel.GetById 17ms app.highlight 47ms RepoModel.GetById 1ms app.codeStats 0ms

/test/functional/test_library_templates.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 740 lines | 660 code | 23 blank | 57 comment | 18 complexity | fde7ed76caaeb1b62259f37bbee4e6fd MD5 | raw file
  1from base.twilltestcase import TwillTestCase
  2from base.test_db_util import (
  3    get_user,
  4    get_private_role,
  5    get_form,
  6    get_library,
  7    get_folder,
  8    get_user_address,
  9    get_latest_ldda_by_name,
 10    get_latest_hda,
 11    mark_obj_deleted,
 12    refresh
 13)
 14import galaxy.model
 15
 16AddressField_form = None
 17CheckboxField_form = None
 18SelectField_form = None
 19TextArea_form = None
 20TextField_form = None
 21WorkflowField_form = None
 22address_field_name = checkbox_field_name = select_field_name = None
 23workflow_field_name = textfield_name = textarea_name = None
 24user_address1 = user_address2 = None
 25ldda1 = library1 = library2 = library3 = library4 = library5 = library6 = None
 26folder1 = folder2 = folder3 = folder4 = folder5 = folder6 = None
 27admin_user = None
 28regular_user1 = regular_user2 = regular_user3 = None
 29
 30
 31class TestLibraryFeatures( TwillTestCase ):
 32
 33    def test_000_initiate_users( self ):
 34        """Ensuring all required user accounts exist"""
 35        self.logout()
 36        self.login( email='test1@bx.psu.edu', username='regular-user1' )
 37        global regular_user1
 38        regular_user1 = get_user( 'test1@bx.psu.edu' )
 39        assert regular_user1 is not None, 'Problem retrieving user with email "test1@bx.psu.edu" from the database'
 40        global regular_user1_private_role
 41        regular_user1_private_role = get_private_role( regular_user1 )
 42        self.logout()
 43        self.login( email='test2@bx.psu.edu', username='regular-user2' )
 44        global regular_user2
 45        regular_user2 = get_user( 'test2@bx.psu.edu' )
 46        assert regular_user2 is not None, 'Problem retrieving user with email "test2@bx.psu.edu" from the database'
 47        global regular_user2_private_role
 48        regular_user2_private_role = get_private_role( regular_user2 )
 49        self.logout()
 50        self.login( email='test3@bx.psu.edu', username='regular-user3' )
 51        global regular_user3
 52        regular_user3 = get_user( 'test3@bx.psu.edu' )
 53        assert regular_user3 is not None, 'Problem retrieving user with email "test3@bx.psu.edu" from the database'
 54        global regular_user3_private_role
 55        regular_user3_private_role = get_private_role( regular_user3 )
 56        self.logout()
 57        self.login( email='test@bx.psu.edu', username='admin-user' )
 58        global admin_user
 59        admin_user = get_user( 'test@bx.psu.edu' )
 60        assert admin_user is not None, 'Problem retrieving user with email "test@bx.psu.edu" from the database'
 61        global admin_user_private_role
 62        admin_user_private_role = get_private_role( admin_user )
 63
 64    def test_005_create_library_templates( self ):
 65        """Testing creating several LibraryInformationTemplate form definitions"""
 66        # Logged in as admin_user
 67        for type in [ 'AddressField', 'CheckboxField', 'SelectField', 'TextArea', 'TextField', 'WorkflowField' ]:
 68            field_name = type.lower()
 69            form_desc = '%s description' % type
 70            num_options = 0
 71            if type == 'SelectField':
 72                # Pass number of options we want in our SelectField
 73                num_options = 2
 74            # Create form for library template
 75            self.create_form( name=type,
 76                              description=form_desc,
 77                              form_type=galaxy.model.FormDefinition.types.LIBRARY_INFO_TEMPLATE,
 78                              field_type=type,
 79                              num_options=num_options,
 80                              field_name=field_name )
 81        # Get all of the new form definitions for later use
 82        global AddressField_form
 83        AddressField_form = get_form( 'AddressField' )
 84        # NOTE: each of these names need to be the same as field_name defined above
 85        # for each type.
 86        global address_field_name
 87        address_field_name = 'addressfield'
 88
 89        global CheckboxField_form
 90        CheckboxField_form = get_form( 'CheckboxField' )
 91        global checkbox_field_name
 92        checkbox_field_name = 'checkboxfield'
 93
 94        global SelectField_form
 95        SelectField_form = get_form( 'SelectField' )
 96        global select_field_name
 97        select_field_name = 'selectfield'
 98
 99        global TextArea_form
100        TextArea_form = get_form( 'TextArea' )
101        global textarea_name
102        textarea_name = 'textarea'
103
104        global TextField_form
105        TextField_form = get_form( 'TextField' )
106        global textfield_name
107        textfield_name = 'textfield'
108
109        global WorkflowField_form
110        WorkflowField_form = get_form( 'WorkflowField' )
111        global workflow_field_name
112        workflow_field_name = 'workflowfield'
113
114    def test_010_create_libraries( self ):
115        """Testing creating a new library for each template"""
116        # Logged in as admin_user
117        # library1 -> AddressField
118        # library2 -> CheckboxField
119        # library3 -> SelectField
120        # library4 -> TextArea
121        # library5 -> TextField
122        # library6 -> WorkflowField
123        for index, form in enumerate( [ AddressField_form, CheckboxField_form, SelectField_form, TextArea_form, TextField_form, WorkflowField_form ] ):
124            name = 'library%s' % str( index + 1 )
125            description = '%s description' % name
126            synopsis = '%s synopsis' % name
127            self.create_library( name=name, description=description, synopsis=synopsis )
128        # Get the libraries for later use
129        global library1
130        library1 = get_library( 'library1', 'library1 description', 'library1 synopsis' )
131        global library2
132        library2 = get_library( 'library2', 'library2 description', 'library2 synopsis' )
133        global library3
134        library3 = get_library( 'library3', 'library3 description', 'library3 synopsis' )
135        global library4
136        library4 = get_library( 'library4', 'library4 description', 'library4 synopsis' )
137        global library5
138        library5 = get_library( 'library5', 'library5 description', 'library5 synopsis' )
139        global library6
140        library6 = get_library( 'library6', 'library6 description', 'library6 synopsis' )
141
142    def test_015_add_template_to_library1( self ):
143        """Testing add an inheritable template containing an AddressField to library1"""
144        # Logged in as admin_user
145        # Add a template containing an AddressField to library1
146        self.add_template( cntrller='library_admin',
147                           item_type='library',
148                           form_type=galaxy.model.FormDefinition.types.LIBRARY_INFO_TEMPLATE.replace( ' ', '+' ),
149                           form_id=self.security.encode_id( AddressField_form.id ),
150                           form_name=AddressField_form.name,
151                           library_id=self.security.encode_id( library1.id ) )
152
153    def test_020_add_folder_to_library1( self ):
154        """Testing adding a folder to library1"""
155        # Logged in as admin_user
156        # Add a folder to library1
157        folder = library1.root_folder
158        name = "folder"
159        description = "folder description"
160        self.add_folder( 'library_admin',
161                         self.security.encode_id( library1.id ),
162                         self.security.encode_id( folder.id ),
163                         name=name,
164                         description=description )
165        global folder1
166        folder1 = get_folder( folder.id, name, description )
167
168    def test_025_check_library1( self ):
169        """Checking library1 and its root folder"""
170        # Logged in as admin_user
171        self.browse_library( cntrller='library_admin',
172                             library_id=self.security.encode_id( library1.id ),
173                             strings_displayed=[ folder1.name, folder1.description ] )
174        # Make sure the template and contents were inherited to folder1
175        self.folder_info( cntrller='library_admin',
176                          folder_id=self.security.encode_id( folder1.id ),
177                          library_id=self.security.encode_id( library1.id ),
178                          template_refresh_field_name=address_field_name,
179                          strings_displayed=[ AddressField_form.name,
180                                              'This is an inherited template and is not required to be used with this folder' ] )
181
182    def test_030_add_dataset_to_folder1( self ):
183        """Testing adding a ldda1 to folder1, and adding a new UserAddress on the upload form."""
184        # Logged in as admin_user
185        # The AddressField template should be inherited to the library dataset upload form.  Passing
186        # the value 'new' should submit the form via refresh_on_change and allow new UserAddress information
187        # to be posted as part of the upload.
188        filename = '1.bed'
189        ldda_message = '1.bed message'
190        short_desc = 'Office'
191        self.upload_library_dataset( cntrller='library_admin',
192                                     library_id=self.security.encode_id( library1.id ),
193                                     folder_id=self.security.encode_id( folder1.id ),
194                                     filename=filename,
195                                     file_type='bed',
196                                     dbkey='hg18',
197                                     template_refresh_field_name=address_field_name,
198                                     ldda_message=ldda_message,
199                                     template_refresh_field_contents='new',
200                                     template_fields=[ ( '%s_short_desc' % address_field_name, short_desc ),
201                                                       ( '%s_name' % address_field_name, 'Dick' ),
202                                                       ( '%s_institution' % address_field_name, 'PSU' ),
203                                                       ( '%s_address' % address_field_name, '32 O Street' ),
204                                                       ( '%s_city' % address_field_name, 'Anywhere' ),
205                                                       ( '%s_state' % address_field_name, 'AK' ),
206                                                       ( '%s_postal_code' % address_field_name, '0000000' ),
207                                                       ( '%s_country' % address_field_name, 'USA' ) ],
208                                     strings_displayed=[ 'Upload files' ] )
209        global user_address1
210        user_address1 = get_user_address( admin_user, short_desc )
211        assert user_address1 is not None, 'Problem retrieving user_address1 from the database'
212        global ldda1
213        ldda1 = get_latest_ldda_by_name( filename )
214        assert ldda1 is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda1 from the database'
215        self.browse_library( cntrller='library_admin',
216                             library_id=self.security.encode_id( library1.id ),
217                             strings_displayed=[ ldda1.name, ldda1.message, 'bed' ] )
218        # Make sure the library template contents were correctly saved
219        self.ldda_edit_info( 'library_admin',
220                             self.security.encode_id( library1.id ),
221                             self.security.encode_id( folder1.id ),
222                             self.security.encode_id( ldda1.id ),
223                             ldda1.name,
224                             strings_displayed=[ 'Dick' ] )
225
226    def test_035_edit_contents_of_ldda1_tempplate( self ):
227        """Testing editing the contents of ldda1 AddressField template by adding a new user_address"""
228        short_desc = 'Home'
229        # Now add a new user_address to ldda1
230        self.ldda_edit_info( 'library_admin',
231                             self.security.encode_id( library1.id ),
232                             self.security.encode_id( folder1.id ),
233                             self.security.encode_id( ldda1.id ),
234                             ldda1.name,
235                             template_refresh_field_name=address_field_name,
236                             template_refresh_field_contents='new',
237                             template_fields=[ ( '%s_short_desc' % address_field_name, short_desc ),
238                                               ( '%s_name' % address_field_name, 'Richard' ),
239                                               ( '%s_institution' % address_field_name, 'PSU' ),
240                                               ( '%s_address' % address_field_name, '32 O Street' ),
241                                               ( '%s_city' % address_field_name, 'Anywhere' ),
242                                               ( '%s_state' % address_field_name, 'AK' ),
243                                               ( '%s_postal_code' % address_field_name, '0000000' ),
244                                               ( '%s_country' % address_field_name, 'USA' ) ],
245                             strings_displayed=[ short_desc ] )
246        global user_address2
247        user_address2 = get_user_address( admin_user, short_desc )
248        assert user_address2 is not None, 'Problem retrieving user_address2 from the database'
249
250    def test_040_edit_contents_of_folder1_template( self ):
251        """Testing editing the contents of folder1 AddressField template"""
252        # Make sure the template and contents were inherited to folder1
253        self.folder_info( cntrller='library_admin',
254                          folder_id=self.security.encode_id( folder1.id ),
255                          library_id=self.security.encode_id( library1.id ),
256                          template_refresh_field_name=address_field_name,
257                          template_refresh_field_contents=str( user_address2.id ),
258                          strings_displayed=[ AddressField_form.name,
259                                              'This is an inherited template and is not required to be used with this folder' ],
260                          strings_displayed_after_submit=[ 'Richard' ] )
261
262    def test_045_add_dataset_to_folder1( self ):
263        """Testing adding another ldda to folder1"""
264        # The upload form should now inherit user_address2 on the upload form
265        filename = '2.bed'
266        ldda_message = '2.bed message'
267        self.upload_library_dataset( cntrller='library_admin',
268                                     library_id=self.security.encode_id( library1.id ),
269                                     folder_id=self.security.encode_id( folder1.id ),
270                                     filename=filename,
271                                     file_type='bed',
272                                     dbkey='hg18',
273                                     template_refresh_field_name=address_field_name,
274                                     ldda_message=ldda_message,
275                                     strings_displayed=[ 'Upload files' ] )
276        # Make sure user_address2 is associated with ldda.
277        self.ldda_edit_info( cntrller='library_admin',
278                             library_id=self.security.encode_id( library1.id ),
279                             folder_id=self.security.encode_id( folder1.id ),
280                             ldda_id=self.security.encode_id( ldda1.id ),
281                             ldda_name=ldda1.name,
282                             template_refresh_field_name=address_field_name,
283                             strings_displayed=[ user_address2.desc ] )
284
285    def test_050_add_template_to_library2( self ):
286        """ Testing add an inheritable template containing an CheckboxField to library2"""
287        # Add a template containing an CheckboxField to library1
288        self.add_template( cntrller='library_admin',
289                           item_type='library',
290                           form_type=galaxy.model.FormDefinition.types.LIBRARY_INFO_TEMPLATE.replace( ' ', '+' ),
291                           form_id=self.security.encode_id( CheckboxField_form.id ),
292                           form_name=CheckboxField_form.name,
293                           library_id=self.security.encode_id( library2.id ) )
294        # Check the CheckboxField to make sure the template contents are inherited
295        self.library_info( 'library_admin',
296                            self.security.encode_id( library2.id ),
297                            template_fields=[ ( checkbox_field_name, '1' ) ] )
298
299    def test_055_add_folder2_to_library2( self ):
300        """Testing adding a folder to library2"""
301        # Logged in as admin_user
302        # Add a folder to library2
303        folder = library2.root_folder
304        name = "folder"
305        description = "folder description"
306        self.add_folder( 'library_admin',
307                         self.security.encode_id( library2.id ),
308                         self.security.encode_id( folder.id ),
309                         name=name,
310                         description=description )
311        global folder2
312        folder2 = get_folder( folder.id, name, description )
313
314    def test_060_check_library2( self ):
315        """Checking library2 and its root folder"""
316        # Logged in as admin_user
317        self.browse_library( cntrller='library_admin',
318                             library_id=self.security.encode_id( library2.id ),
319                             strings_displayed=[ folder2.name, folder2.description ] )
320
321    def test_065_save_folder2_inherited_template( self ):
322        """Saving the inherited template for folder2"""
323        # Logged in as admin_user
324        # Save the inherited template
325        self.folder_info( cntrller='library_admin',
326                          folder_id=self.security.encode_id( folder2.id ),
327                          library_id=self.security.encode_id( library2.id ),
328                          template_fields=[ ( checkbox_field_name, '1' ) ],
329                          strings_displayed=[ CheckboxField_form.name,
330                                              'This is an inherited template and is not required to be used with this folder' ] )
331
332    def test_070_add_ldda_to_folder2( self ):
333        """
334        Testing adding a new library dataset to library2's folder, making sure the CheckboxField is
335        checked on the upload form.
336        """
337        # Logged in as admin_user
338        filename = '1.bed'
339        ldda_message = '1.bed message'
340        self.upload_library_dataset( cntrller='library_admin',
341                                     library_id=self.security.encode_id( library2.id ),
342                                     folder_id=self.security.encode_id( folder2.id ),
343                                     filename=filename,
344                                     file_type='bed',
345                                     dbkey='hg18',
346                                     ldda_message=ldda_message,
347                                     strings_displayed=[ 'CheckboxField', 'checked' ] )
348        ldda = get_latest_ldda_by_name( filename )
349        assert ldda is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda from the database'
350        self.browse_library( cntrller='library_admin',
351                             library_id=self.security.encode_id( library2.id ),
352                             strings_displayed=[ ldda.name, ldda.message, 'bed' ] )
353        # Make sure the library template contents were correctly saved
354        self.ldda_edit_info( 'library_admin',
355                             self.security.encode_id( library2.id ),
356                             self.security.encode_id( folder2.id ),
357                             self.security.encode_id( ldda.id ),
358                             ldda.name,
359                             strings_displayed=[ 'CheckboxField', 'checked' ] )
360
361    def test_080_add_template_to_library3( self ):
362        """ Testing add an inheritable template containing an SelectField to library3"""
363        # Logged in as admin_user
364        self.add_template( cntrller='library_admin',
365                           item_type='library',
366                           form_type=galaxy.model.FormDefinition.types.LIBRARY_INFO_TEMPLATE.replace( ' ', '+' ),
367                           form_id=self.security.encode_id( SelectField_form.id ),
368                           form_name=SelectField_form.name,
369                           library_id=self.security.encode_id( library3.id ) )
370        # Select the 2nd option in the SelectField to make sure the template contents are inherited
371        # SelectField option names are zero-based
372        self.library_info( 'library_admin',
373                            self.security.encode_id( library3.id ),
374                            template_fields=[ ( select_field_name, 'Option1' ) ] )
375
376    def test_085_add_folder3_to_library3( self ):
377        """Testing adding a folder to library3"""
378        # Logged in as admin_user
379        # Add a folder to library3
380        folder = library3.root_folder
381        name = "folder"
382        description = "folder description"
383        self.add_folder( 'library_admin',
384                         self.security.encode_id( library3.id ),
385                         self.security.encode_id( folder.id ),
386                         name=name,
387                         description=description )
388        global folder3
389        folder3 = get_folder( folder.id, name, description )
390
391    def test_090_check_library3( self ):
392        """Checking library3 and its root folder"""
393        # Logged in as admin_user
394        self.browse_library( cntrller='library_admin',
395                             library_id=self.security.encode_id( library3.id ),
396                             strings_displayed=[ folder3.name, folder3.description ] )
397
398    def test_095_save_folder3_inherited_template( self ):
399        """Saving the inherited template for folder3"""
400        # Logged in as admin_user
401        # Save the inherited template
402        self.folder_info( cntrller='library_admin',
403                          folder_id=self.security.encode_id( folder3.id ),
404                          library_id=self.security.encode_id( library3.id ),
405                          template_fields=[ ( select_field_name, 'Option1' ) ],
406                          strings_displayed=[ SelectField_form.name,
407                                              'This is an inherited template and is not required to be used with this folder',
408                                              'Option1' ] )
409
410    def test_100_add_ldda_to_folder3( self ):
411        """
412        Testing adding a new library dataset to library3's folder, making sure the SelectField setting is correct on the upload form.
413        """
414        filename = '3.bed'
415        ldda_message = '3.bed message'
416        # Logged in as admin_user
417        self.upload_library_dataset( cntrller='library_admin',
418                                     library_id=self.security.encode_id( library3.id ),
419                                     folder_id=self.security.encode_id( folder3.id ),
420                                     filename=filename,
421                                     file_type='bed',
422                                     dbkey='hg18',
423                                     ldda_message=ldda_message,
424                                     strings_displayed=[ 'SelectField', 'selected>Option1' ] )
425        ldda = get_latest_ldda_by_name( filename )
426        assert ldda is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda from the database'
427        self.browse_library( cntrller='library_admin',
428                             library_id=self.security.encode_id( library3.id ),
429                             strings_displayed=[ ldda.name, ldda.message, 'bed' ] )
430        # Make sure the library template contents were correctly saved
431        self.ldda_edit_info( 'library_admin',
432                             self.security.encode_id( library3.id ),
433                             self.security.encode_id( folder3.id ),
434                             self.security.encode_id( ldda.id ),
435                             ldda.name,
436                             strings_displayed=[ 'SelectField', 'Option1' ] )
437        # Import a dataset from the current history
438        filename = '8.bed'
439        self.new_history( name='import with SelectField' )
440        self.upload_file( filename )
441        hda = get_latest_hda()
442        self.upload_library_dataset( cntrller='library_admin',
443                                     library_id=self.security.encode_id( library3.id ),
444                                     folder_id=self.security.encode_id( folder3.id ),
445                                     upload_option='import_from_history',
446                                     hda_ids=self.security.encode_id( hda.id ),
447                                     strings_displayed=[ '<select name="%s" last_selected_value="Option1">' % select_field_name ] )
448        ldda = get_latest_ldda_by_name( filename )
449        assert ldda is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda from the database'
450        self.browse_library( cntrller='library_admin',
451                             library_id=self.security.encode_id( library3.id ),
452                             strings_displayed=[ ldda.name, 'bed' ] )
453        # Make sure the library template contents were correctly saved
454        self.ldda_edit_info( 'library_admin',
455                             self.security.encode_id( library3.id ),
456                             self.security.encode_id( folder3.id ),
457                             self.security.encode_id( ldda.id ),
458                             ldda.name,
459                             strings_displayed=[ 'SelectField', 'Option1' ] )
460
461    def test_105_add_template_to_library4( self ):
462        """ Testing add an inheritable template containing an TextArea to library4"""
463        # Logged in as admin_user
464        # Add an inheritable template to library4
465        self.add_template( cntrller='library_admin',
466                           item_type='library',
467                           form_type=galaxy.model.FormDefinition.types.LIBRARY_INFO_TEMPLATE.replace( ' ', '+' ),
468                           form_id=self.security.encode_id( TextArea_form.id ),
469                           form_name=TextArea_form.name,
470                           library_id=self.security.encode_id( library4.id ) )
471        # Select the 2nd option in the SelectField to make sure the template contents are inherited
472        self.library_info( 'library_admin',
473                            self.security.encode_id( library4.id ),
474                            template_fields=[ ( textarea_name, 'This text should be inherited' ) ] )
475
476    def test_110_add_folder4_to_library4( self ):
477        """Testing adding a folder to library4"""
478        # Logged in as admin_user
479        # Add a folder to library4
480        folder = library4.root_folder
481        name = "folder"
482        description = "folder description"
483        self.add_folder( 'library_admin',
484                         self.security.encode_id( library4.id ),
485                         self.security.encode_id( folder.id ),
486                         name=name,
487                         description=description )
488        global folder4
489        folder4 = get_folder( folder.id, name, description )
490
491    def test_115_save_folder4_inherited_template( self ):
492        """Saving the inherited template for folder4"""
493        # Logged in as admin_user
494        # Save the inherited template
495        self.folder_info( cntrller='library_admin',
496                          folder_id=self.security.encode_id( folder4.id ),
497                          library_id=self.security.encode_id( library4.id ),
498                          template_fields=[ ( textarea_name, 'This text should be inherited' ) ],
499                          strings_displayed=[ TextArea_form.name,
500                                              'This is an inherited template and is not required to be used with this folder',
501                                              'This text should be inherited' ] )
502
503    def test_120_add_ldda_to_folder4( self ):
504        """
505        Testing adding a new library dataset to library4's folder, making sure the TextArea setting is correct on the upload form.
506        """
507        filename = '4.bed'
508        ldda_message = '4.bed message'
509        # Logged in as admin_user
510        self.upload_library_dataset( cntrller='library_admin',
511                                     library_id=self.security.encode_id( library4.id ),
512                                     folder_id=self.security.encode_id( folder4.id ),
513                                     filename=filename,
514                                     file_type='bed',
515                                     dbkey='hg18',
516                                     ldda_message=ldda_message,
517                                     strings_displayed=[ 'TextArea', 'This text should be inherited' ] )
518        ldda = get_latest_ldda_by_name( filename )
519        assert ldda is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda from the database'
520        self.browse_library( cntrller='library_admin',
521                             library_id=self.security.encode_id( library4.id ),
522                             strings_displayed=[ ldda.name, ldda.message, 'bed' ] )
523        # Make sure the library template contents were correctly saved
524        self.ldda_edit_info( 'library_admin',
525                             self.security.encode_id( library4.id ),
526                             self.security.encode_id( folder4.id ),
527                             self.security.encode_id( ldda.id ),
528                             ldda.name,
529                             strings_displayed=[ 'TextArea', 'This text should be inherited' ] )
530
531    def test_125_add_template_to_library5( self ):
532        """ Testing add an inheritable template containing an TextField to library5"""
533        # Add an inheritable template to library5
534        self.add_template( cntrller='library_admin',
535                           item_type='library',
536                           form_type=galaxy.model.FormDefinition.types.LIBRARY_INFO_TEMPLATE.replace( ' ', '+' ),
537                           form_id=self.security.encode_id( TextField_form.id ),
538                           form_name=TextField_form.name,
539                           library_id=self.security.encode_id( library5.id ) )
540        # Select the 2nd option in the SelectField to make sure the template contents are inherited
541        self.library_info( 'library_admin',
542                           self.security.encode_id( library5.id ),
543                           template_fields=[ ( textfield_name, 'This text should be inherited' ) ] )
544
545    def test_130_add_folder5_to_library5( self ):
546        """Testing adding a folder to library5"""
547        # Logged in as admin_user
548        # Add a folder to library5
549        folder = library5.root_folder
550        name = "folder"
551        description = "folder description"
552        self.add_folder( 'library_admin',
553                         self.security.encode_id( library5.id ),
554                         self.security.encode_id( folder.id ),
555                         name=name,
556                         description=description )
557        global folder5
558        folder5 = get_folder( folder.id, name, description )
559
560    def test_135_save_folder5_inherited_template( self ):
561        """Saving the inherited template for folder5"""
562        # Logged in as admin_user
563        # Save the inherited template
564        self.folder_info( cntrller='library_admin',
565                          folder_id=self.security.encode_id( folder5.id ),
566                          library_id=self.security.encode_id( library5.id ),
567                          template_fields=[ ( textfield_name, 'This text should be inherited' ) ],
568                          strings_displayed=[ TextField_form.name,
569                                              'This is an inherited template and is not required to be used with this folder',
570                                              'This text should be inherited' ] )
571
572    def test_140_add_ldda_to_folder5( self ):
573        """
574        Testing adding a new library dataset to library5's folder, making sure the TextField setting is correct on the upload form.
575        """
576        # Logged in as admin_user
577        filename = '5.bed'
578        ldda_message = '5.bed message'
579        self.upload_library_dataset( cntrller='library_admin',
580                                     library_id=self.security.encode_id( library5.id ),
581                                     folder_id=self.security.encode_id( folder5.id ),
582                                     filename=filename,
583                                     file_type='bed',
584                                     dbkey='hg18',
585                                     ldda_message=ldda_message,
586                                     strings_displayed=[ 'TextField', 'This text should be inherited' ] )
587        ldda = get_latest_ldda_by_name( filename )
588        assert ldda is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda from the database'
589        self.browse_library( cntrller='library_admin',
590                             library_id=self.security.encode_id( library5.id ),
591                             strings_displayed=[ ldda.name, ldda.message, 'bed' ] )
592        # Make sure the library template contents were correctly saved
593        self.ldda_edit_info( 'library_admin',
594                             self.security.encode_id( library5.id ),
595                             self.security.encode_id( folder5.id ),
596                             self.security.encode_id( ldda.id ),
597                             ldda.name,
598                             strings_displayed=[ 'TextField', 'This text should be inherited' ] )
599
600    def test_145_edit_library5_template_layout( self ):
601        """Test editing the layout of library5's template"""
602        # Currently there is only a TextField, and we'll add a TextArea.
603        self.edit_template( cntrller='library_admin',
604                            item_type='library',
605                            form_type=galaxy.model.FormDefinition.types.LIBRARY_INFO_TEMPLATE.replace( ' ', '+' ),
606                            library_id=self.security.encode_id( library5.id ),
607                            field_type='TextArea',
608                            field_label_1=TextArea_form.name,
609                            field_helptext_1='%s help' % TextArea_form.name,
610                            field_default_1='%s default' % TextArea_form.name )
611
612    def test_150_add_ldda_to_library5( self ):
613        """
614        Testing adding a new library dataset to library5's folder, making sure the TextField and new TextArea settings are correct on the upload form.
615        """
616        filename = '6.bed'
617        ldda_message = '6.bed message'
618        # Logged in as admin_user
619        self.upload_library_dataset( cntrller='library_admin',
620                                     library_id=self.security.encode_id( library5.id ),
621                                     folder_id=self.security.encode_id( library5.root_folder.id ),
622                                     filename=filename,
623                                     file_type='bed',
624                                     dbkey='hg18',
625                                     ldda_message=ldda_message,
626                                     strings_displayed=[ 'TextField',
627                                                         'This text should be inherited',
628                                                         'TextArea' ] )
629        ldda = get_latest_ldda_by_name( filename )
630        assert ldda is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda from the database'
631        self.browse_library( cntrller='library_admin',
632                             library_id=self.security.encode_id( library5.id ),
633                             strings_displayed=[ ldda.name, ldda.message, 'bed' ] )
634        # Make sure the library template contents were correctly saved
635        self.ldda_edit_info( 'library_admin',
636                             self.security.encode_id( library5.id ),
637                             self.security.encode_id( library5.root_folder.id ),
638                             self.security.encode_id( ldda.id ),
639                             ldda.name,
640                             strings_displayed=[ 'TextField',
641                                                 'This text should be inherited',
642                                                 'TextArea' ] )
643
644    def test_155_add_template_to_library6( self ):
645        """ Testing add an inheritable template containing an WorkflowField to library6"""
646        # Add an inheritable template to library6
647        # We won't select an option since we have no workflow to select
648        self.add_template( cntrller='library_admin',
649                           item_type='library',
650                           form_type=galaxy.model.FormDefinition.types.LIBRARY_INFO_TEMPLATE.replace( ' ', '+' ),
651                           form_id=self.security.encode_id( WorkflowField_form.id ),
652                           form_name=WorkflowField_form.name,
653                           library_id=self.security.encode_id( library6.id ) )
654
655    def test_160_add_folder6_to_library6( self ):
656        """Testing adding a folder to library6"""
657        # Logged in as admin_user
658        # Add a folder to library5
659        folder = library6.root_folder
660        name = "folder"
661        description = "folder description"
662        self.add_folder( 'library_admin',
663                         self.security.encode_id( library6.id ),
664                         self.security.encode_id( folder.id ),
665                         name=name,
666                         description=description )
667        global folder6
668        folder6 = get_folder( folder.id, name, description )
669
670    def test_165_save_folder6_inherited_template( self ):
671        """Saving the inherited template for folder6"""
672        # Logged in as admin_user
673        # Save the inherited template - we won't select an option since we have no workflow to select
674        self.folder_info( cntrller='library_admin',
675                          folder_id=self.security.encode_id( folder6.id ),
676                          library_id=self.security.encode_id( library6.id ),
677                          template_fields=[ ( workflow_field_name, 'none' ) ],
678                          strings_displayed=[ WorkflowField_form.name,
679                                              'This is an inherited template and is not required to be used with this folder',
680                                              'none' ] )
681
682    def test_170_add_ldda_to_folder6( self ):
683        """
684        Testing adding a new library dataset to library6's folder, making sure the WorkflowField setting is correct on the upload form.
685        """
686        # Logged in as admin_user
687        filename = '7.bed'
688        ldda_message = '7.bed message'
689        self.upload_library_dataset( cntrller='library_admin',
690                                     library_id=self.security.encode_id( library6.id ),
691                                     folder_id=self.security.encode_id( folder6.id ),
692                                     filename=filename,
693                                     file_type='bed',
694                                     dbkey='hg18',
695                                     ldda_message=ldda_message,
696                                     strings_displayed=[ 'WorkflowField', 'none' ] )
697        ldda = get_latest_ldda_by_name( filename )
698        assert ldda is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda from the database'
699        self.browse_library( cntrller='library_admin',
700                             library_id=self.security.encode_id( library6.id ),
701                             strings_displayed=[ ldda.name, ldda.message, 'bed' ] )
702        # Make sure the library template contents were correctly saved
703        self.ldda_edit_info( 'library_admin',
704                             self.security.encode_id( library6.id ),
705                             self.security.encode_id( folder6.id ),
706                             self.security.encode_id( ldda.id ),
707                             ldda.name,
708                             strings_displayed=[ 'WorkflowField', 'none' ] )
709
710    def test_999_reset_data_for_later_test_runs( self ):
711        """Reseting data to enable later test runs to pass"""
712        # Logged in as admin_user
713        ##################
714        # Delete all form definitions
715        ##################
716        for form in [ AddressField_form, CheckboxField_form, SelectField_form, TextArea_form, TextField_form, WorkflowField_form ]:
717            self.mark_form_deleted( self.security.encode_id( form.form_definition_current.id ) )
718        ##################
719        # Mark all user_addresses deleted
720        ##################
721        for user_address in [ user_address1, user_address2 ]:
722            mark_obj_deleted( user_address )
723        ##################
724        # Purge all libraries
725        ##################
726        for library in [ library1, library2, library3, library4, library5, library6 ]:
727            self.delete_library_item( 'library_admin',
728                                      self.security.encode_id( library.id ),
729                                      self.security.encode_id( library.id ),
730                                      library.name,
731                                      item_type='library' )
732            self.purge_library( self.security.encode_id( library.id ), library.name )
733        ##################
734        # Make sure all users are associated only with their private roles
735        ##################
736        for user in [ admin_user, regular_user1, regular_user2, regular_user3 ]:
737            refresh( user )
738            if len( user.roles) != 1:
739                raise AssertionError( '%d UserRoleAssociations are associated with %s ( should be 1 )' % ( len( user.roles ), user.email ) )
740        self.logout()