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

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

import galaxy-central

行番号 
1from base.twilltestcase import *
2from base.test_db_util import *
3
4class TestLibraryFeatures( TwillTestCase ):
5    def test_000_initiate_users( self ):
6        """Ensuring all required user accounts exist"""
7        self.logout()
8        self.login( email='test1@bx.psu.edu', username='regular-user1' )
9        global regular_user1
10        regular_user1 = get_user( 'test1@bx.psu.edu' )
11        assert regular_user1 is not None, 'Problem retrieving user with email "test1@bx.psu.edu" from the database'
12        global regular_user1_private_role
13        regular_user1_private_role = get_private_role( regular_user1 )
14        self.logout()
15        self.login( email='test2@bx.psu.edu', username='regular-user2' )
16        global regular_user2
17        regular_user2 = get_user( 'test2@bx.psu.edu' )
18        assert regular_user2 is not None, 'Problem retrieving user with email "test2@bx.psu.edu" from the database'
19        global regular_user2_private_role
20        regular_user2_private_role = get_private_role( regular_user2 )
21        self.logout()
22        self.login( email='test3@bx.psu.edu', username='regular-user3' )
23        global regular_user3
24        regular_user3 = get_user( 'test3@bx.psu.edu' )
25        assert regular_user3 is not None, 'Problem retrieving user with email "test3@bx.psu.edu" from the database'
26        global regular_user3_private_role
27        regular_user3_private_role = get_private_role( regular_user3 )
28        self.logout()
29        self.login( email='test@bx.psu.edu', username='admin-user' )
30        global admin_user
31        admin_user = get_user( 'test@bx.psu.edu' )
32        assert admin_user is not None, 'Problem retrieving user with email "test@bx.psu.edu" from the database'
33        global admin_user_private_role
34        admin_user_private_role = get_private_role( admin_user )
35    def test_005_create_libraries( self ):
36        """Testing creating libraries used in this script, then renaming one of them"""
37        # Logged in as admin_user
38        for index in range( 0, 1 ):
39            name = 'library%s' % str( index + 1 )
40            description = '%s description' % name
41            synopsis = '%s synopsis' % name
42            self.create_library( name=name, description=description, synopsis=synopsis )
43            self.browse_libraries_admin( strings_displayed=[ name, description ] )
44        # Get the libraries for later use
45        global library1
46        library1 = get_library( 'library1', 'library1 description', 'library1 synopsis' )
47        assert library1 is not None, 'Problem retrieving library (library1) from the database'
48        # Rename the library
49        new_name = "library1 new name"
50        new_description = "library1 new description"
51        new_synopsis = "library1 new synopsis"
52        self.library_info( 'library_admin',
53                            self.security.encode_id( library1.id ),
54                            library1.name,
55                            new_name=new_name,
56                            new_description=new_description,
57                            new_synopsis=new_synopsis )
58        self.browse_libraries_admin( strings_displayed=[ new_name, new_description ] )
59        # Reset the library back to the original name and description
60        self.library_info( 'library_admin',
61                            self.security.encode_id( library1.id ),
62                            library1.name,
63                            new_name=name,
64                            new_description='library1 description',
65                            new_synopsis='library1 synopsis' )
66        refresh( library1 )
67    def test_030_add_folder_to_library1( self ):
68        """Testing adding a folder to a library1"""
69        # logged in as admin_user
70        root_folder = library1.root_folder
71        name = "folder1"
72        description = "folder1 description"
73        self.add_folder( 'library_admin',
74                         self.security.encode_id( library1.id ),
75                         self.security.encode_id( library1.root_folder.id ),
76                         name=name,
77                         description=description )
78        global folder1
79        folder1 = get_folder( root_folder.id, name, description )
80        assert folder1 is not None, 'Problem retrieving library folder named "%s" from the database' % name
81        self.browse_library( 'library_admin',
82                             self.security.encode_id( library1.id ),
83                             strings_displayed=[ folder1.name, folder1.description ] )
84    def test_035_add_subfolder_to_folder( self ):
85        """Testing adding a folder to a folder"""
86        # logged in as admin_user
87        name = "Folder One's Subfolder"
88        description = "This is the Folder One's subfolder"
89        self.add_folder( 'library_admin',
90                         self.security.encode_id( library1.id ),
91                         self.security.encode_id( folder1.id ),
92                         name=name,
93                         description=description )
94        global subfolder1
95        subfolder1 = get_folder( folder1.id, name, description )
96        assert subfolder1 is not None, 'Problem retrieving subfolder1 from the database'
97        self.browse_library( 'library_admin',
98                             self.security.encode_id( library1.id ),
99                             strings_displayed=[ subfolder1.name, subfolder1.description ] )
100    def test_040_add_2nd_folder_to_library1( self ):
101        """Testing adding a 2nd folder to a library1"""
102        # logged in as admin_user
103        name = "folder2"
104        description = "folder2 description"
105        self.add_folder( 'library_admin',
106                         self.security.encode_id( library1.id ),
107                         self.security.encode_id( library1.root_folder.id ),
108                         name=name,
109                         description=description )
110        global folder2
111        folder2 = get_folder( library1.root_folder.id, name, description )
112        assert folder2 is not None, 'Problem retrieving library folder named "%s" from the database' % name
113        self.browse_library( 'library_admin',
114                             self.security.encode_id( library1.id ),
115                             strings_displayed=[ folder2.name, folder2.description ] )
116    def test_045_add_public_dataset_to_folder2( self ):
117        """Testing adding a public dataset to folder2"""
118        # Logged in as admin_user
119        filename = '2.bed'
120        ldda_message = "Testing uploading %s" % filename
121        self.upload_library_dataset( cntrller='library_admin',
122                                     library_id=self.security.encode_id( library1.id ),
123                                     folder_id=self.security.encode_id( folder2.id ),
124                                     filename=filename,
125                                     file_type='bed',
126                                     dbkey='hg18',
127                                     ldda_message=ldda_message,
128                                     strings_displayed=[ 'Upload files' ] )
129        global ldda2
130        ldda2 = get_latest_ldda_by_name( filename )
131        assert ldda2 is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda2 from the database'
132        self.browse_library( 'library_admin',
133                             self.security.encode_id( library1.id ),
134                             strings_displayed=[ ldda2.name, ldda2.message, admin_user.email ] )
135    def test_050_add_2nd_public_dataset_to_folder2( self ):
136        """Testing adding a 2nd public dataset folder2"""
137        # Logged in as admin_user
138        filename='3.bed'
139        ldda_message = "Testing uploading %s" % filename
140        self.upload_library_dataset( cntrller='library_admin',
141                                     library_id=self.security.encode_id( library1.id ),
142                                     folder_id=self.security.encode_id( folder2.id ),
143                                     filename=filename,
144                                     file_type='bed',
145                                     dbkey='hg18',
146                                     ldda_message=ldda_message,
147                                     strings_displayed=[ 'Upload files' ] )
148        global ldda3
149        ldda3 = get_latest_ldda_by_name( filename )
150        assert ldda3 is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda3 from the database'
151        self.browse_library( 'library_admin',
152                             self.security.encode_id( library1.id ),
153                             strings_displayed=[ ldda3.name, ldda3.message, admin_user.email ] )
154    def test_055_copy_dataset_from_history_to_subfolder( self ):
155        """Testing copying a dataset from the current history to a subfolder"""
156        # logged in as admin_user
157        self.new_history()
158        filename = '4.bed'
159        self.upload_file( filename )
160        latest_hda = get_latest_hda()
161        self.upload_library_dataset( cntrller='library_admin',
162                                     library_id=self.security.encode_id( library1.id ),
163                                     folder_id=self.security.encode_id( subfolder1.id ),
164                                     upload_option='import_from_history',
165                                     hda_ids=self.security.encode_id( latest_hda.id ),
166                                     ldda_message='Imported from history',
167                                     strings_displayed=[ 'Active datasets in your current history' ] )
168        global ldda4
169        ldda4 = get_latest_ldda_by_name( filename )
170        assert ldda4 is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda4 from the database'
171        self.browse_library( 'library_admin',
172                             self.security.encode_id( library1.id ),
173                             strings_displayed=[ ldda4.name, ldda4.message, admin_user.email ] )
174    def test_060_editing_dataset_attribute_info( self ):
175        """Testing editing a library dataset's attribute information"""
176        # logged in as admin_user
177        new_ldda_name = '4.bed ( version 1 )'
178        self.ldda_edit_info( 'library_admin',
179                             self.security.encode_id( library1.id ),
180                             self.security.encode_id( subfolder1.id ),
181                             self.security.encode_id( ldda4.id ),
182                             ldda4.name,
183                             new_ldda_name=new_ldda_name )
184        refresh( ldda4 )
185        self.browse_library( 'library_admin',
186                             self.security.encode_id( library1.id ),
187                             strings_displayed=[ new_ldda_name, ldda4.message ] )
188    def test_065_uploading_new_dataset_version( self ):
189        """Testing uploading a new version of a library dataset"""
190        # logged in as admin_user
191        filename = '4.bed'
192        ldda_message = 'Testing uploading a new version of a dataset'
193        self.upload_library_dataset( cntrller='library_admin',
194                                     library_id=self.security.encode_id( library1.id ),
195                                     folder_id=self.security.encode_id( subfolder1.id ),
196                                     replace_id=self.security.encode_id( ldda4.library_dataset.id ),
197                                     filename=filename,
198                                     file_type='auto',
199                                     dbkey='hg18',
200                                     ldda_message=ldda_message,
201                                     strings_displayed=[ 'Upload files', 'You are currently selecting a new file to replace' ] )
202        global ldda4_version2
203        ldda4_version2 = get_latest_ldda_by_name( filename )
204        assert ldda4_version2 is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda4_version2 from the database'
205        self.ldda_edit_info( 'library_admin',
206                             self.security.encode_id( library1.id ),
207                             self.security.encode_id( subfolder1.id ),
208                             self.security.encode_id( ldda4_version2.id ),
209                             ldda4_version2.name,
210                             strings_displayed=[ 'This is the latest version of this library dataset' ] )
211        # Check the previous version
212        self.ldda_edit_info( 'library_admin',
213                             self.security.encode_id( library1.id ),
214                             self.security.encode_id( subfolder1.id ),
215                             self.security.encode_id( ldda4.id ),
216                             ldda4.name,
217                             strings_displayed=[ 'This is an expired version of this library dataset' ] )
218        # Make sure ldda4 is no longer displayed in the library
219        self.browse_library( 'library_admin',
220                             self.security.encode_id( library1.id ),
221                             strings_not_displayed=[ ldda4.name, ldda4.message ] )
222    def test_070_upload_directory_of_files_from_libraries_view( self ):
223        """Testing uploading a directory of files to a root folder from the Data Libraries view"""
224        # logged in as admin_user
225        # admin_user will not have the option to upload a directory of files from the
226        # Libraries view since a sub-directory named the same as their email is not contained
227        # in the configured user_library_import_dir ( in the test_data directory, only  regular_user1
228        # and regular_user3 have directories ).  We'll need to give these 2 user LIBRARY_ADD permission
229        # on library1 to test this feature.
230        permissions_in = [ 'LIBRARY_ADD' ]
231        permissions_out = [ 'LIBRARY_ACCESS', 'LIBRARY_MODIFY', 'LIBRARY_MANAGE' ]
232        role_ids = '%s,%s' % ( str( regular_user1_private_role.id ), str( regular_user3_private_role.id ) )
233        self.library_permissions( self.security.encode_id( library1.id ),
234                                  library1.name,
235                                  role_ids,
236                                  permissions_in,
237                                  permissions_out )
238        self.logout()
239        # Now that we have permissions set on the library, we can proceed to test uploading files
240        self.login( email=regular_user1.email )
241        ldda_message = 'Uploaded all files in test-data/users/test1...'
242        # Since regular_user1 does not have any sub-directories contained within her configured
243        # user_library_import_dir, the only option in her server_dir select list will be the
244        # directory named the same as her email
245        self.upload_library_dataset( cntrller='library',
246                                     library_id=self.security.encode_id( library1.id ),
247                                     folder_id=self.security.encode_id( library1.root_folder.id ),
248                                     upload_option='upload_directory',
249                                     server_dir=regular_user1.email,
250                                     ldda_message=ldda_message,
251                                     strings_displayed = [ "Upload a directory of files" ] )
252        self.browse_library( 'library',
253                             self.security.encode_id( library1.id ),
254                             strings_displayed=[ regular_user1.email, ldda_message, '1.fasta' ] )
255        self.logout()
256        self.login( regular_user3.email )
257        ldda_message = 'Uploaded all files in test-data/users/test3.../run1'
258        # Since regular_user2 has a subdirectory contained within her configured user_library_import_dir,
259        # she will have a "None" option in her server_dir select list
260        self.upload_library_dataset( cntrller='library',
261                                     library_id=self.security.encode_id( library1.id ),
262                                     folder_id=self.security.encode_id( library1.root_folder.id ),
263                                     upload_option='upload_directory',
264                                     server_dir='run1',
265                                     ldda_message=ldda_message,
266                                     strings_displayed=[ 'Upload a directory of files', '<option>None</option>' ] )
267        self.browse_library( 'library',
268                             self.security.encode_id( library1.id ),
269                             strings_displayed=[ regular_user3.email, ldda_message, '2.fasta' ] )
270    def test_075_download_archive_of_library_files( self ):
271        """Testing downloading an archive of files from library1"""
272        # logged in as regular_user3
273        self.logout()
274        self.login( email=admin_user.email )
275        filename = '1.bed'
276        self.upload_library_dataset( cntrller='library_admin',
277                                     library_id=self.security.encode_id( library1.id ),
278                                     folder_id=self.security.encode_id( library1.root_folder.id ),
279                                     filename=filename,
280                                     file_type='bed',
281                                     dbkey='hg18',
282                                     strings_displayed=[ 'Upload files' ] )
283        global ldda1
284        ldda1 = get_latest_ldda_by_name( filename )
285        assert ldda1 is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda1 from the database'
286        for format in ( 'tbz', 'tgz', 'zip' ):
287            archive = self.download_archive_of_library_files( cntrller='library',
288                                                              library_id=self.security.encode_id( library1.id ),
289                                                              ldda_ids=[ self.security.encode_id( ldda1.id ), self.security.encode_id( ldda2.id ) ],
290                                                              format=format )
291            self.check_archive_contents( archive, ( ldda1, ldda2 ) )
292            os.remove( archive )
293    def test_080_mark_ldda2_deleted( self ):
294        """Testing marking ldda2 as deleted"""
295        # Logged in as admin_user
296        self.delete_library_item( 'library_admin',
297                                  self.security.encode_id( library1.id ),
298                                  self.security.encode_id( ldda2.library_dataset.id ),
299                                  ldda2.name,
300                                  item_type='library_dataset' )
301        self.browse_library( 'library_admin',
302                             self.security.encode_id( library1.id ),
303                             strings_not_displayed=[ ldda2.name, ldda2.message ] )
304    def test_085_display_and_hide_deleted_ldda2( self ):
305        """Testing displaying and hiding a deleted ldda2"""
306        # Logged in as admin_user
307        self.browse_library( 'library_admin',
308                             self.security.encode_id( library1.id ),
309                             show_deleted=True,
310                             strings_displayed=[ ldda2.name, ldda2.message ] )
311        self.browse_library( 'library_admin',
312                             self.security.encode_id( library1.id ),
313                             strings_not_displayed=[ ldda2.name, ldda2.message ] )
314    def test_090_mark_folder2_deleted( self ):
315        """Testing marking folder2 as deleted"""
316        # Logged in as admin_user
317        self.delete_library_item( 'library_admin',
318                                  self.security.encode_id( library1.id ),
319                                  self.security.encode_id( folder2.id ),
320                                  folder2.name,
321                                  item_type='folder' )
322        self.browse_library( 'library_admin',
323                             self.security.encode_id( library1.id ),
324                             strings_not_displayed=[ folder2.name ] )
325    def test_095_mark_folder_undeleted( self ):
326        """Testing marking a library folder as undeleted"""
327        # Logged in as admin_user
328        self.undelete_library_item( 'library_admin',
329                                    self.security.encode_id( library1.id ),
330                                    self.security.encode_id( folder2.id ),
331                                    folder2.name,
332                                    item_type='folder' )
333        # 2.bed was deleted before the folder was deleted, so state should have been saved.  In order
334        # for 2.bed to be displayed, it would itself have to be marked undeleted.
335        self.browse_library( 'library_admin',
336                             self.security.encode_id( library1.id ),
337                             strings_displayed=[ folder2.name ],
338                             strings_not_displayed=[ ldda2.name ] )
339    def test_100_mark_library_deleted( self ):
340        """Testing marking a library as deleted"""
341        # Logged in as admin_user
342        # First mark folder2 as deleted to further test state saving when we undelete the library
343        self.delete_library_item( 'library_admin',
344                                  self.security.encode_id( library1.id ),
345                                  self.security.encode_id( folder2.id ),
346                                  folder2.name,
347                                  item_type='folder' )
348        self.delete_library_item( 'library_admin',
349                                  self.security.encode_id( library1.id ),
350                                  self.security.encode_id( library1.id ),
351                                  library1.name,
352                                  item_type='library' )
353        self.browse_libraries_admin( strings_not_displayed=[ library1.name ] )
354        self.browse_libraries_admin( deleted=True, strings_displayed=[ library1.name ] )
355    def test_105_mark_library_undeleted( self ):
356        """Testing marking a library as undeleted"""
357        # Logged in as admin_user
358        self.undelete_library_item( 'library_admin',
359                                    self.security.encode_id( library1.id ),
360                                    self.security.encode_id( library1.id ),
361                                    library1.name,
362                                    item_type='library' )
363        self.browse_libraries_admin( strings_displayed=[ library1.name ] )
364        self.browse_library( 'library_admin',
365                            self.security.encode_id( library1.id ),
366                            strings_displayed=[ library1.name ],
367                            strings_not_displayed=[ folder2.name ] )
368    def test_110_purge_library( self ):
369        """Testing purging a library"""
370        # Logged in as admin_user
371        self.delete_library_item( 'library_admin',
372                                  self.security.encode_id( library1.id ),
373                                  self.security.encode_id( library1.id ),
374                                  library1.name,
375                                  item_type='library' )
376        self.purge_library( self.security.encode_id( library1.id ), library1.name )
377        # Make sure the library was purged
378        refresh( library1 )
379        if not ( library1.deleted and library1.purged ):
380            raise AssertionError( 'The library id %s named "%s" has not been marked as deleted and purged.' % ( str( library1.id ), library1.name ) )
381        def check_folder( library_folder ):
382            for folder in library_folder.folders:
383                refresh( folder )
384                # Make sure all of the library_folders are purged
385                if not folder.purged:
386                    raise AssertionError( 'The library_folder id %s named "%s" has not been marked purged.' % ( str( folder.id ), folder.name ) )
387                check_folder( folder )
388            # Make sure all of the LibraryDatasets and associated objects are deleted
389            refresh( library_folder )
390            for library_dataset in library_folder.datasets:
391                refresh( library_dataset )
392                ldda = library_dataset.library_dataset_dataset_association
393                if ldda:
394                    refresh( ldda )
395                    if not ldda.deleted:
396                        raise AssertionError( 'The library_dataset_dataset_association id %s named "%s" has not been marked as deleted.' % \
397                                              ( str( ldda.id ), ldda.name ) )
398                    # Make sure all of the datasets have been deleted
399                    dataset = ldda.dataset
400                    refresh( dataset )
401                    if not dataset.deleted:
402                        raise AssertionError( 'The dataset with id "%s" has not been marked as deleted when it should have been.' % \
403                                              str( ldda.dataset.id ) )
404                if not library_dataset.deleted:
405                    raise AssertionError( 'The library_dataset id %s named "%s" has not been marked as deleted.' % \
406                                          ( str( library_dataset.id ), library_dataset.name ) )
407        check_folder( library1.root_folder )
408    def test_999_reset_data_for_later_test_runs( self ):
409        """Reseting data to enable later test runs to pass"""
410        # Logged in as admin_user
411        ##################
412        # Purge all libraries
413        ##################
414        for library in [ library1 ]:
415            self.delete_library_item( 'library_admin',
416                                      self.security.encode_id( library.id ),
417                                      self.security.encode_id( library.id ),
418                                      library.name,
419                                      item_type='library' )
420            self.purge_library( self.security.encode_id( library.id ), library.name )
421        ##################
422        # Make sure all users are associated only with their private roles
423        ##################
424        for user in [ admin_user, regular_user1, regular_user2, regular_user3 ]:
425            refresh( user )
426            if len( user.roles) != 1:
427                raise AssertionError( '%d UserRoleAssociations are associated with %s ( should be 1 )' % ( len( user.roles ), user.email ) )
428        self.logout()
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。