PageRenderTime 83ms CodeModel.GetById 36ms app.highlight 39ms RepoModel.GetById 1ms app.codeStats 0ms

/test/functional/test_library_features.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 578 lines | 557 code | 2 blank | 19 comment | 15 complexity | 9c432bbb86e14a2a7796e4330d6eed6d MD5 | raw file
  1from base.twilltestcase import *
  2from base.test_db_util import *
  3
  4
  5# TODO: Functional tests start failing at 070, fix or eliminate rest of tests.
  6class TestLibraryFeatures( TwillTestCase ):
  7    def test_000_initiate_users( self ):
  8        """Ensuring all required user accounts exist"""
  9        self.logout()
 10        self.login( email='test1@bx.psu.edu', username='regular-user1' )
 11        global regular_user1
 12        regular_user1 = get_user( 'test1@bx.psu.edu' )
 13        assert regular_user1 is not None, 'Problem retrieving user with email "test1@bx.psu.edu" from the database'
 14        global regular_user1_private_role
 15        regular_user1_private_role = get_private_role( regular_user1 )
 16        self.logout()
 17        self.login( email='test2@bx.psu.edu', username='regular-user2' )
 18        global regular_user2
 19        regular_user2 = get_user( 'test2@bx.psu.edu' )
 20        assert regular_user2 is not None, 'Problem retrieving user with email "test2@bx.psu.edu" from the database'
 21        global regular_user2_private_role
 22        regular_user2_private_role = get_private_role( regular_user2 )
 23        self.logout()
 24        self.login( email='test3@bx.psu.edu', username='regular-user3' )
 25        global regular_user3
 26        regular_user3 = get_user( 'test3@bx.psu.edu' )
 27        assert regular_user3 is not None, 'Problem retrieving user with email "test3@bx.psu.edu" from the database'
 28        global regular_user3_private_role
 29        regular_user3_private_role = get_private_role( regular_user3 )
 30        self.logout()
 31        self.login( email='test@bx.psu.edu', username='admin-user' )
 32        global admin_user
 33        admin_user = get_user( 'test@bx.psu.edu' )
 34        assert admin_user is not None, 'Problem retrieving user with email "test@bx.psu.edu" from the database'
 35        global admin_user_private_role
 36        admin_user_private_role = get_private_role( admin_user )
 37    def test_005_create_libraries( self ):
 38        """Testing creating libraries used in this script, then renaming one of them"""
 39        # Logged in as admin_user
 40        for index in range( 0, 3 ):
 41            name = 'library%s' % str( index + 1 )
 42            description = '%s description' % name
 43            synopsis = '%s synopsis' % name
 44            self.create_library( name=name, description=description, synopsis=synopsis )
 45            self.browse_libraries_admin( strings_displayed=[ name, description ] )
 46        # Get the libraries for later use
 47        global library1
 48        library1 = get_library( 'library1', 'library1 description', 'library1 synopsis' )
 49        assert library1 is not None, 'Problem retrieving library (library1) from the database'
 50        global library2
 51        library2 = get_library( 'library2', 'library2 description', 'library2 synopsis' )
 52        assert library2 is not None, 'Problem retrieving library (library2) from the database'
 53        global library3
 54        library3 = get_library( 'library3', 'library3 description', 'library3 synopsis' )
 55        assert library3 is not None, 'Problem retrieving library (library3) from the database'
 56        # Rename the library
 57        new_name = "library1 new name"
 58        new_description = "library1 new description"
 59        new_synopsis = "library1 new synopsis"
 60        self.library_info( 'library_admin',
 61                            self.security.encode_id( library1.id ),
 62                            library1.name,
 63                            new_name=new_name,
 64                            new_description=new_description,
 65                            new_synopsis=new_synopsis )
 66        self.browse_libraries_admin( strings_displayed=[ new_name, new_description ] )
 67        # Reset the library back to the original name and description
 68        self.library_info( 'library_admin',
 69                            self.security.encode_id( library1.id ),
 70                            library1.name,
 71                            new_name=name,
 72                            new_description='library1 description',
 73                            new_synopsis='library1 synopsis' )
 74        refresh( library1 )
 75    def test_030_add_folder_to_library1( self ):
 76        """Testing adding a folder to a library1"""
 77        # logged in as admin_user
 78        root_folder = library1.root_folder
 79        name = "folder1"
 80        description = "folder1 description"
 81        self.add_folder( 'library_admin',
 82                         self.security.encode_id( library1.id ),
 83                         self.security.encode_id( library1.root_folder.id ),
 84                         name=name,
 85                         description=description )
 86        global folder1
 87        folder1 = get_folder( root_folder.id, name, description )
 88        assert folder1 is not None, 'Problem retrieving library folder named "%s" from the database' % name
 89        self.browse_library( cntrller='library_admin',
 90                             library_id=self.security.encode_id( library1.id ),
 91                             strings_displayed=[ folder1.name, folder1.description ] )
 92    def test_035_add_subfolder_to_folder( self ):
 93        """Testing adding a folder to a folder"""
 94        # logged in as admin_user
 95        name = "Folder One's Subfolder"
 96        description = "This is the Folder One's subfolder"
 97        self.add_folder( 'library_admin',
 98                         self.security.encode_id( library1.id ),
 99                         self.security.encode_id( folder1.id ),
100                         name=name,
101                         description=description )
102        global subfolder1
103        subfolder1 = get_folder( folder1.id, name, description )
104        assert subfolder1 is not None, 'Problem retrieving subfolder1 from the database'
105        self.browse_library( cntrller='library_admin',
106                             library_id=self.security.encode_id( library1.id ),
107                             strings_displayed=[ subfolder1.name, subfolder1.description ] )
108    def test_040_add_2nd_folder_to_library1( self ):
109        """Testing adding a 2nd folder to a library1"""
110        # logged in as admin_user
111        name = "folder2"
112        description = "folder2 description"
113        self.add_folder( 'library_admin',
114                         self.security.encode_id( library1.id ),
115                         self.security.encode_id( library1.root_folder.id ),
116                         name=name,
117                         description=description )
118        global folder2
119        folder2 = get_folder( library1.root_folder.id, name, description )
120        assert folder2 is not None, 'Problem retrieving library folder named "%s" from the database' % name
121        self.browse_library( cntrller='library_admin',
122                             library_id=self.security.encode_id( library1.id ),
123                             strings_displayed=[ folder2.name, folder2.description ] )
124    def test_045_add_public_dataset_to_folder2( self ):
125        """Testing adding a public dataset to folder2"""
126        # Logged in as admin_user
127        filename = '2.bed'
128        ldda_message = "Testing uploading %s" % filename
129        self.upload_library_dataset( cntrller='library_admin',
130                                     library_id=self.security.encode_id( library1.id ),
131                                     folder_id=self.security.encode_id( folder2.id ),
132                                     filename=filename,
133                                     file_type='bed',
134                                     dbkey='hg18',
135                                     ldda_message=ldda_message,
136                                     strings_displayed=[ 'Upload files' ] )
137        global ldda2
138        ldda2 = get_latest_ldda_by_name( filename )
139        assert ldda2 is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda2 from the database'
140        self.browse_library( cntrller='library_admin',
141                             library_id=self.security.encode_id( library1.id ),
142                             strings_displayed=[ ldda2.name, ldda2.message, 'bed' ] )
143    def test_050_add_2nd_public_dataset_to_folder2( self ):
144        """Testing adding a 2nd public dataset folder2"""
145        # Logged in as admin_user
146        filename='3.bed'
147        ldda_message = "Testing uploading %s" % filename
148        self.upload_library_dataset( cntrller='library_admin',
149                                     library_id=self.security.encode_id( library1.id ),
150                                     folder_id=self.security.encode_id( folder2.id ),
151                                     filename=filename,
152                                     file_type='bed',
153                                     dbkey='hg18',
154                                     ldda_message=ldda_message,
155                                     strings_displayed=[ 'Upload files' ] )
156        global ldda3
157        ldda3 = get_latest_ldda_by_name( filename )
158        assert ldda3 is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda3 from the database'
159        self.browse_library( cntrller='library_admin',
160                             library_id=self.security.encode_id( library1.id ),
161                             strings_displayed=[ ldda3.name, ldda3.message, 'bed' ] )
162    def test_055_copy_dataset_from_history_to_subfolder( self ):
163        """Testing copying a dataset from the current history to a subfolder"""
164        # logged in as admin_user
165        self.new_history()
166        filename = '4.bed'
167        self.upload_file( filename )
168        latest_hda = get_latest_hda()
169        self.upload_library_dataset( cntrller='library_admin',
170                                     library_id=self.security.encode_id( library1.id ),
171                                     folder_id=self.security.encode_id( subfolder1.id ),
172                                     upload_option='import_from_history',
173                                     hda_ids=self.security.encode_id( latest_hda.id ),
174                                     ldda_message='Imported from history',
175                                     strings_displayed=[ 'Active datasets in your current history' ] )
176        global ldda4
177        ldda4 = get_latest_ldda_by_name( filename )
178        assert ldda4 is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda4 from the database'
179        self.browse_library( cntrller='library_admin',
180                             library_id=self.security.encode_id( library1.id ),
181                             strings_displayed=[ ldda4.name, ldda4.message, 'bed' ] )
182    def test_060_editing_dataset_attribute_info( self ):
183        """Testing editing a library dataset's attribute information"""
184        # logged in as admin_user
185        new_ldda_name = '4.bed ( version 1 )'
186        self.ldda_edit_info( 'library_admin',
187                             self.security.encode_id( library1.id ),
188                             self.security.encode_id( subfolder1.id ),
189                             self.security.encode_id( ldda4.id ),
190                             ldda4.name,
191                             new_ldda_name=new_ldda_name )
192        refresh( ldda4 )
193        self.browse_library( cntrller='library_admin',
194                             library_id=self.security.encode_id( library1.id ),
195                             strings_displayed=[ new_ldda_name, ldda4.message ] )
196    def test_065_uploading_new_dataset_version( self ):
197        """Testing uploading a new version of a library dataset"""
198        # logged in as admin_user
199        filename = '4.bed'
200        ldda_message = 'Testing uploading a new version of a dataset'
201        self.upload_library_dataset( cntrller='library_admin',
202                                     library_id=self.security.encode_id( library1.id ),
203                                     folder_id=self.security.encode_id( subfolder1.id ),
204                                     replace_id=self.security.encode_id( ldda4.library_dataset.id ),
205                                     filename=filename,
206                                     file_type='auto',
207                                     dbkey='hg18',
208                                     ldda_message=ldda_message,
209                                     strings_displayed=[ 'Upload files', 'You are currently selecting a new file to replace' ] )
210        global ldda4_version2
211        ldda4_version2 = get_latest_ldda_by_name( filename )
212        assert ldda4_version2 is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda4_version2 from the database'
213        self.ldda_edit_info( 'library_admin',
214                             self.security.encode_id( library1.id ),
215                             self.security.encode_id( subfolder1.id ),
216                             self.security.encode_id( ldda4_version2.id ),
217                             ldda4_version2.name,
218                             strings_displayed=[ 'This is the latest version of this library dataset' ] )
219        # Check the previous version
220        self.ldda_edit_info( 'library_admin',
221                             self.security.encode_id( library1.id ),
222                             self.security.encode_id( subfolder1.id ),
223                             self.security.encode_id( ldda4.id ),
224                             ldda4.name,
225                             strings_displayed=[ 'This is an expired version of this library dataset' ] )
226        # Make sure ldda4 is no longer displayed in the library
227        self.browse_library( cntrller='library_admin',
228                             library_id=self.security.encode_id( library1.id ),
229                             strings_not_displayed=[ ldda4.name, ldda4.message ] )
230    def test_070_upload_directory_of_files_from_libraries_view( self ):
231        """Testing uploading a directory of files to a root folder from the Data Libraries view"""
232        # logged in as admin_user
233        # admin_user will not have the option to upload a directory of files from the
234        # Libraries view since a sub-directory named the same as their email is not contained
235        # in the configured user_library_import_dir ( in the test_data directory, only  regular_user1
236        # and regular_user3 have directories ).  We'll need to give these 2 user LIBRARY_ADD permission
237        # on library1 to test this feature.
238        permissions_in = [ 'LIBRARY_ADD' ]
239        permissions_out = [ 'LIBRARY_ACCESS', 'LIBRARY_MODIFY', 'LIBRARY_MANAGE' ]
240        role_ids = '%s,%s' % ( str( regular_user1_private_role.id ), str( regular_user3_private_role.id ) )
241        self.library_permissions( self.security.encode_id( library1.id ),
242                                  library1.name,
243                                  role_ids,
244                                  permissions_in,
245                                  permissions_out )
246        self.logout()
247        # Now that we have permissions set on the library, we can proceed to test uploading files
248        self.login( email=regular_user1.email )
249        ldda_message = 'Uploaded all files in test-data/users/test1...'
250        # Since regular_user1 does not have any sub-directories contained within her configured
251        # user_library_import_dir, the only option in her server_dir select list will be the
252        # directory named the same as her email
253        self.upload_library_dataset( cntrller='library',
254                                     library_id=self.security.encode_id( library1.id ),
255                                     folder_id=self.security.encode_id( library1.root_folder.id ),
256                                     upload_option='upload_directory',
257                                     server_dir=regular_user1.email,
258                                     ldda_message=ldda_message,
259                                     strings_displayed = [ "Upload a directory of files" ] )
260        self.logout()
261        self.login( regular_user3.email )
262        ldda_message = 'Uploaded all files in test-data/users/test3.../run1'
263        # Since regular_user2 has a subdirectory contained within her configured user_library_import_dir,
264        # she will have a "None" option in her server_dir select list
265        self.upload_library_dataset( cntrller='library',
266                                     library_id=self.security.encode_id( library1.id ),
267                                     folder_id=self.security.encode_id( library1.root_folder.id ),
268                                     upload_option='upload_directory',
269                                     server_dir='run1',
270                                     ldda_message=ldda_message,
271                                     strings_displayed=[ 'Upload a directory of files', '<option>None</option>' ] )
272    def test_075_download_archive_of_library_files( self ):
273        """Testing downloading an archive of files from library1"""
274        # logged in as regular_user3
275        self.logout()
276        self.login( email=admin_user.email )
277        filename = '1.bed'
278        self.upload_library_dataset( cntrller='library_admin',
279                                     library_id=self.security.encode_id( library1.id ),
280                                     folder_id=self.security.encode_id( library1.root_folder.id ),
281                                     filename=filename,
282                                     file_type='bed',
283                                     dbkey='hg18',
284                                     strings_displayed=[ 'Upload files' ] )
285        global ldda1
286        ldda1 = get_latest_ldda_by_name( filename )
287        assert ldda1 is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda1 from the database'
288        for format in ( 'tbz', 'tgz', 'zip' ):
289            archive = self.download_archive_of_library_files( cntrller='library',
290                                                              library_id=self.security.encode_id( library1.id ),
291                                                              ldda_ids=[ self.security.encode_id( ldda1.id ), self.security.encode_id( ldda2.id ) ],
292                                                              format=format )
293            self.check_archive_contents( archive, ( ldda1, ldda2 ) )
294            os.remove( archive )
295    def test_080_check_libraries_for_uploaded_directories_of_files( self ):
296        """Testing the results of uploading directories of files to library1"""
297        # We'll make sure the directories of files were uploaded in test_070... above.
298        # We do this here because the check would generally fail if we did it in the
299        # test_070... method since the files would not finish uploading before the check
300        # was done.  Hopefully doing the check here will allow for enough time...
301        ldda_message = 'Uploaded all files in test-data/users/test1...'
302        self.browse_library( 'library',
303                             self.security.encode_id( library1.id ),
304                             strings_displayed=[ 'fasta', ldda_message, '1.fasta' ] )
305        ldda_message = 'Uploaded all files in test-data/users/test3.../run1'
306        self.browse_library( 'library',
307                             self.security.encode_id( library1.id ),
308                             strings_displayed=[ 'fasta', ldda_message, '2.fasta' ] )
309    def test_085_mark_ldda2_deleted( self ):
310        """Testing marking ldda2 as deleted"""
311        # Logged in as admin_user
312        self.delete_library_item( 'library_admin',
313                                  self.security.encode_id( library1.id ),
314                                  self.security.encode_id( ldda2.library_dataset.id ),
315                                  ldda2.name,
316                                  item_type='library_dataset' )
317        self.browse_library( cntrller='library_admin',
318                             library_id=self.security.encode_id( library1.id ),
319                             strings_not_displayed=[ ldda2.name, ldda2.message ] )
320    def test_090_display_and_hide_deleted_ldda2( self ):
321        """Testing displaying and hiding a deleted ldda2"""
322        # Logged in as admin_user
323        self.browse_library( cntrller='library_admin',
324                             library_id=self.security.encode_id( library1.id ),
325                             show_deleted=True,
326                             strings_displayed=[ ldda2.name, ldda2.message ] )
327        self.browse_library( 'library_admin',
328                             self.security.encode_id( library1.id ),
329                             strings_not_displayed=[ ldda2.name, ldda2.message ] )
330    def test_095_mark_folder2_deleted( self ):
331        """Testing marking folder2 as deleted"""
332        # Logged in as admin_user
333        self.delete_library_item( 'library_admin',
334                                  self.security.encode_id( library1.id ),
335                                  self.security.encode_id( folder2.id ),
336                                  folder2.name,
337                                  item_type='folder' )
338        self.browse_library( cntrller='library_admin',
339                             library_id=self.security.encode_id( library1.id ),
340                             strings_not_displayed=[ folder2.name ] )
341    def test_100_mark_folder_undeleted( self ):
342        """Testing marking a library folder as undeleted"""
343        # Logged in as admin_user
344        self.undelete_library_item( 'library_admin',
345                                    self.security.encode_id( library1.id ),
346                                    self.security.encode_id( folder2.id ),
347                                    folder2.name,
348                                    item_type='folder' )
349        # 2.bed was deleted before the folder was deleted, so state should have been saved.  In order
350        # for 2.bed to be displayed, it would itself have to be marked undeleted.
351        self.browse_library( cntrller='library_admin',
352                             library_id=self.security.encode_id( library1.id ),
353                             strings_displayed=[ folder2.name ],
354                             strings_not_displayed=[ ldda2.name ] )
355    def test_105_mark_library_deleted( self ):
356        """Testing marking a library as deleted"""
357        # Logged in as admin_user
358        # First mark folder2 as deleted to further test state saving when we undelete the library
359        self.delete_library_item( 'library_admin',
360                                  self.security.encode_id( library1.id ),
361                                  self.security.encode_id( folder2.id ),
362                                  folder2.name,
363                                  item_type='folder' )
364        self.delete_library_item( 'library_admin',
365                                  self.security.encode_id( library1.id ),
366                                  self.security.encode_id( library1.id ),
367                                  library1.name,
368                                  item_type='library' )
369        self.browse_libraries_admin( strings_not_displayed=[ library1.name ] )
370        self.browse_libraries_admin( deleted=True, strings_displayed=[ library1.name ] )
371    def test_110_mark_library_undeleted( self ):
372        """Testing marking a library as undeleted"""
373        # Logged in as admin_user
374        self.undelete_library_item( 'library_admin',
375                                    self.security.encode_id( library1.id ),
376                                    self.security.encode_id( library1.id ),
377                                    library1.name,
378                                    item_type='library' )
379        self.browse_libraries_admin( strings_displayed=[ library1.name ] )
380        self.browse_library( cntrller='library_admin',
381                             library_id=self.security.encode_id( library1.id ),
382                             strings_displayed=[ library1.name ],
383                             strings_not_displayed=[ folder2.name ] )
384    def test_115_purge_library( self ):
385        """Testing purging a library"""
386        # Logged in as admin_user
387        self.delete_library_item( 'library_admin',
388                                  self.security.encode_id( library1.id ),
389                                  self.security.encode_id( library1.id ),
390                                  library1.name,
391                                  item_type='library' )
392        self.purge_library( self.security.encode_id( library1.id ), library1.name )
393        # Make sure the library was purged
394        refresh( library1 )
395        if not ( library1.deleted and library1.purged ):
396            raise AssertionError( 'The library id %s named "%s" has not been marked as deleted and purged.' % ( str( library1.id ), library1.name ) )
397        def check_folder( library_folder ):
398            for folder in library_folder.folders:
399                refresh( folder )
400                # Make sure all of the library_folders are purged
401                if not folder.purged:
402                    raise AssertionError( 'The library_folder id %s named "%s" has not been marked purged.' % ( str( folder.id ), folder.name ) )
403                check_folder( folder )
404            # Make sure all of the LibraryDatasets and associated objects are deleted
405            refresh( library_folder )
406            for library_dataset in library_folder.datasets:
407                refresh( library_dataset )
408                ldda = library_dataset.library_dataset_dataset_association
409                if ldda:
410                    refresh( ldda )
411                    if not ldda.deleted:
412                        raise AssertionError( 'The library_dataset_dataset_association id %s named "%s" has not been marked as deleted.' % \
413                                              ( str( ldda.id ), ldda.name ) )
414                    # Make sure all of the datasets have been deleted
415                    dataset = ldda.dataset
416                    refresh( dataset )
417                    if not dataset.deleted:
418                        raise AssertionError( 'The dataset with id "%s" has not been marked as deleted when it should have been.' % \
419                                              str( ldda.dataset.id ) )
420                if not library_dataset.deleted:
421                    raise AssertionError( 'The library_dataset id %s named "%s" has not been marked as deleted.' % \
422                                          ( str( library_dataset.id ), library_dataset.name ) )
423        check_folder( library1.root_folder )
424    def test_120_populate_public_library2( self ):
425        """Testing library datasets within a library"""
426        # Logged in as admin_user
427        # Add a folder named Three to library2 root
428        root_folder = library2.root_folder
429        name = "One"
430        description = "One description"
431        self.add_folder( 'library_admin',
432                         self.security.encode_id( library2.id ),
433                         self.security.encode_id( root_folder.id ),
434                         name=name,
435                         description=description )
436        global folder3
437        folder3 = get_folder( root_folder.id, name, description )
438        assert folder3 is not None, 'Problem retrieving library folder named "%s" from the database' % name
439        # Upload dataset 1.bed to folder One
440        filename = '1.bed'
441        ldda_message = "Testing uploading %s" % filename
442        self.upload_library_dataset( cntrller='library_admin',
443                                     library_id=self.security.encode_id( library2.id ),
444                                     folder_id=self.security.encode_id( folder3.id ),
445                                     filename=filename,
446                                     file_type='bed',
447                                     dbkey='hg18',
448                                     ldda_message=ldda_message,
449                                     strings_displayed=[ 'Upload files' ] )
450        global ldda5
451        ldda5 = get_latest_ldda_by_name( filename )
452        assert ldda5 is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda5 from the database'
453        # Add a sub-folder named Two to folder One
454        name = "Two"
455        description = "Two description"
456        self.add_folder( 'library_admin',
457                         self.security.encode_id( library2.id ),
458                         self.security.encode_id( folder3.id ),
459                         name=name,
460                         description=description )
461        global folder4
462        folder4 = get_folder( folder3.id, name, description )
463        assert folder4 is not None, 'Problem retrieving library folder named "%s" from the database' % name
464        # Upload dataset 2.bed to folder Two
465        filename = '2.bed'
466        ldda_message = "Testing uploading %s" % filename
467        self.upload_library_dataset( cntrller='library_admin',
468                                     library_id=self.security.encode_id( library2.id ),
469                                     folder_id=self.security.encode_id( folder4.id ),
470                                     filename=filename,
471                                     file_type='bed',
472                                     dbkey='hg18',
473                                     ldda_message=ldda_message,
474                                     strings_displayed=[ 'Upload files' ] )
475        global ldda6
476        ldda6 = get_latest_ldda_by_name( filename )
477        assert ldda6 is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda6 from the database'
478        # Add a folder named Three to library2 root
479        name = "Three"
480        description = "Three description"
481        self.add_folder( 'library_admin',
482                         self.security.encode_id( library2.id ),
483                         self.security.encode_id( root_folder.id ),
484                         name=name,
485                         description=description )
486        global folder5
487        folder5 = get_folder( root_folder.id, name, description )
488        assert folder5 is not None, 'Problem retrieving library folder named "%s" from the database' % name
489        # Upload dataset 3.bed to library2 root folder
490        filename = '3.bed'
491        ldda_message = "Testing uploading %s" % filename
492        self.upload_library_dataset( cntrller='library_admin',
493                                     library_id=self.security.encode_id( library2.id ),
494                                     folder_id=self.security.encode_id( root_folder.id ),
495                                     filename=filename,
496                                     file_type='bed',
497                                     dbkey='hg18',
498                                     ldda_message=ldda_message,
499                                     strings_displayed=[ 'Upload files' ] )
500        global ldda7
501        ldda7 = get_latest_ldda_by_name( filename )
502        assert ldda7 is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda7 from the database'
503    def test_125_move_dataset_within_library2( self ):
504        """Testing moving a dataset within library2"""
505        # Logged in as admin_user
506        # Move 3.bed to folder Three
507        self.move_library_item( cntrller='library_admin',
508                                item_type='ldda',
509                                item_id=self.security.encode_id( ldda7.id ),
510                                source_library_id=self.security.encode_id( library2.id ),
511                                make_target_current=True,
512                                target_folder_id=self.security.encode_id( folder5.id ),
513                                strings_displayed=[ 'Move data library items',
514                                                    '3.bed' ],
515                                strings_displayed_after_submit=[ '1 dataset moved to folder (Three) within data library (library2)' ] )
516    def test_130_move_folder_to_another_library( self ):
517        """Testing moving a folder to another library"""
518        # Logged in as admin_user
519        # Move folder Three which now includes 3.bed to library3
520        self.move_library_item( cntrller='library_admin',
521                                item_type='folder',
522                                item_id=self.security.encode_id( folder5.id ),
523                                source_library_id=self.security.encode_id( library2.id ),
524                                make_target_current=False,
525                                target_library_id=self.security.encode_id( library3.id ),
526                                target_folder_id=self.security.encode_id( library3.root_folder.id ),
527                                strings_displayed=[ 'Move data library items',
528                                                    'Three' ],
529                                strings_displayed_after_submit=[ 'Moved folder (Three) to folder (library3) within data library (library3)' ] )
530        # Make sure folder Three is not longer in library2
531        self.browse_library( cntrller='library_admin',
532                             library_id=self.security.encode_id( library2.id ),
533                             strings_displayed=[ folder4.name, folder4.description ],
534                             strings_not_displayed=[ folder5.name, folder5.description ] )
535        # Make sure folder Three was moved to library3
536        self.browse_library( cntrller='library_admin',
537                             library_id=self.security.encode_id( library3.id ),
538                             strings_displayed=[ folder5.name, folder5.description, ldda7.name ] )
539    def test_135_upload_unsorted_bam_to_library_using_file_path_with_link_to_file( self ):
540        """Test uploading 3unsorted.bam, using filesystem_paths option in combination with link_to_files"""
541        filename = '3unsorted.bam'
542        self.upload_library_dataset( cntrller='library_admin',
543                                     library_id=self.security.encode_id( library2.id ),
544                                     folder_id=self.security.encode_id( library2.root_folder.id ),
545                                     upload_option='upload_paths',
546                                     link_data_only='link_to_files',
547                                     filesystem_paths='test-data/3unsorted.bam' )
548        global ldda8
549        ldda8 = get_latest_ldda_by_name( filename )
550        assert ldda8 is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda8 from the database'
551        # The upload above should produce an error condition in the uploaded library dataset since
552        # the uploaded bam file is not sorted, and we are linking to the file.
553        self.ldda_info( cntrller='library_admin',
554                        library_id=self.security.encode_id( library2.id ),
555                        folder_id=self.security.encode_id( library2.root_folder.id ),
556                        ldda_id=self.security.encode_id( ldda8.id ),
557                        strings_displayed=[ 'The uploaded files need grooming, so change your <b>Copy data into Galaxy?</b> selection to be' ] )
558    def test_999_reset_data_for_later_test_runs( self ):
559        """Reseting data to enable later test runs to pass"""
560        # Logged in as admin_user
561        ##################
562        # Purge all libraries
563        ##################
564        for library in [ library1, library2, library3 ]:
565            self.delete_library_item( 'library_admin',
566                                      self.security.encode_id( library.id ),
567                                      self.security.encode_id( library.id ),
568                                      library.name,
569                                      item_type='library' )
570            self.purge_library( self.security.encode_id( library.id ), library.name )
571        ##################
572        # Make sure all users are associated only with their private roles
573        ##################
574        for user in [ admin_user, regular_user1, regular_user2, regular_user3 ]:
575            refresh( user )
576            if len( user.roles) != 1:
577                raise AssertionError( '%d UserRoleAssociations are associated with %s ( should be 1 )' % ( len( user.roles ), user.email ) )
578        self.logout()