comparison env/lib/python3.7/site-packages/bioblend/_tests/TestGalaxyLibraries.py @ 0:26e78fe6e8c4 draft

"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
author shellac
date Sat, 02 May 2020 07:14:21 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:26e78fe6e8c4
1 import os
2 import shutil
3 import tempfile
4
5 from . import GalaxyTestBase, test_util
6
7 FOO_DATA = 'foo\nbar\n'
8
9
10 class TestGalaxyLibraries(GalaxyTestBase.GalaxyTestBase):
11
12 def setUp(self):
13 super(TestGalaxyLibraries, self).setUp()
14 self.name = 'automated test library'
15 self.library = self.gi.libraries.create_library(self.name, description='automated test', synopsis='automated test synopsis')
16
17 def tearDown(self):
18 self.gi.libraries.delete_library(self.library['id'])
19
20 def test_create_library(self):
21 self.assertEqual(self.library['name'], self.name)
22 self.assertIsNotNone(self.library['id'])
23
24 def test_get_libraries(self):
25 library_data = self.gi.libraries.get_libraries(library_id=self.library['id'])[0]
26 self.assertTrue(library_data['name'] == self.name)
27 deleted_name = 'deleted test library'
28 deleted_library = self.gi.libraries.create_library(deleted_name, description='a deleted library', synopsis='automated test synopsis')
29 self.gi.libraries.delete_library(deleted_library['id'])
30 deleted_library_data = self.gi.libraries.get_libraries(library_id=deleted_library['id'], deleted=True)[0]
31 self.assertTrue(deleted_library_data['name'] == deleted_name)
32 all_non_deleted_libraries = self.gi.libraries.get_libraries(deleted=False)
33 self.assertTrue(any(l['id'] == self.library['id'] for l in all_non_deleted_libraries))
34 self.assertFalse(any(l['id'] == deleted_library['id'] for l in all_non_deleted_libraries))
35 all_deleted_libraries = self.gi.libraries.get_libraries(deleted=True)
36 self.assertFalse(any(l['id'] == self.library['id'] for l in all_deleted_libraries))
37 self.assertTrue(any(l['id'] == deleted_library['id'] for l in all_deleted_libraries))
38 all_libraries = self.gi.libraries.get_libraries(deleted=None)
39 self.assertTrue(any(l['id'] == self.library['id'] for l in all_libraries))
40 self.assertTrue(any(l['id'] == deleted_library['id'] for l in all_libraries))
41
42 def test_show_library(self):
43 library_data = self.gi.libraries.show_library(self.library['id'])
44 self.assertEqual(self.library['id'], library_data['id'])
45 self.assertEqual(self.library['name'], library_data['name'])
46
47 def test_upload_file_from_url(self):
48 pass
49
50 def test_upload_file_contents(self):
51 self.gi.libraries.upload_file_contents(self.library['id'], FOO_DATA)
52
53 def test_upload_file_from_local_path(self):
54 with tempfile.NamedTemporaryFile(mode='w', prefix='bioblend_test_') as f:
55 f.write(FOO_DATA)
56 f.flush()
57 self.gi.libraries.upload_file_from_local_path(self.library['id'], f.name)
58
59 def test_upload_file_from_server(self):
60 pass
61
62 def test_upload_from_galaxy_filesystem(self):
63 bnames = ['f%d.txt' % i for i in range(2)]
64 tempdir = tempfile.mkdtemp(prefix='bioblend_test_')
65 try:
66 fnames = [os.path.join(tempdir, _) for _ in bnames]
67 for fn in fnames:
68 with open(fn, 'w') as f:
69 f.write(FOO_DATA)
70 filesystem_paths = '\n'.join(fnames)
71 ret = self.gi.libraries.upload_from_galaxy_filesystem(self.library['id'], filesystem_paths)
72 for dataset_dict in ret:
73 dataset = self.gi.libraries.wait_for_dataset(self.library['id'], dataset_dict['id'])
74 self.assertEqual(dataset['state'], 'ok')
75 ret = self.gi.libraries.upload_from_galaxy_filesystem(self.library['id'], filesystem_paths, link_data_only='link_to_files')
76 for dataset_dict in ret:
77 dataset = self.gi.libraries.wait_for_dataset(self.library['id'], dataset_dict['id'])
78 self.assertEqual(dataset['state'], 'ok')
79 finally:
80 shutil.rmtree(tempdir)
81
82 def test_copy_from_dataset(self):
83 history = self.gi.histories.create_history()
84 dataset_id = self._test_dataset(history['id'])
85 self.gi.libraries.copy_from_dataset(self.library['id'], dataset_id, message='Copied from dataset')
86
87 @test_util.skip_unless_galaxy('release_17.09')
88 def test_update_dataset(self):
89 library_id = self.library["id"]
90 dataset1 = self.gi.libraries.upload_file_contents(library_id, FOO_DATA)
91 updated_dataset = self.gi.libraries.update_library_dataset(dataset1[0]['id'], name='Modified name', misc_info='Modified the name succesfully')
92 self.assertEqual(updated_dataset["name"], 'Modified name')
93 self.assertEqual(updated_dataset["misc_info"], 'Modified the name succesfully')
94
95 @test_util.skip_unless_galaxy('release_14.10')
96 def test_library_permissions(self):
97 current_user = self.gi.users.get_current_user()
98 user_id_list_new = [current_user['id']]
99 self.gi.libraries.set_library_permissions(self.library['id'], access_in=user_id_list_new, modify_in=user_id_list_new, add_in=user_id_list_new, manage_in=user_id_list_new)
100 ret = self.gi.libraries.get_library_permissions(self.library['id'])
101 self.assertEqual(set(_[1] for _ in ret['access_library_role_list']), set(user_id_list_new))
102 self.assertEqual(set(_[1] for _ in ret['modify_library_role_list']), set(user_id_list_new))
103 self.assertEqual(set(_[1] for _ in ret['add_library_item_role_list']), set(user_id_list_new))
104 self.assertEqual(set(_[1] for _ in ret['manage_library_role_list']), set(user_id_list_new))