comparison env/lib/python3.7/site-packages/bioblend/_tests/TestGalaxyDatasetCollections.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 from bioblend.galaxy import dataset_collections as collections
2 from . import GalaxyTestBase
3
4
5 class TestGalaxyDatasetCollections(GalaxyTestBase.GalaxyTestBase):
6
7 def test_create_list_in_history(self):
8 history_id = self.gi.histories.create_history(name="TestDSListCreate")["id"]
9 dataset1_id = self._test_dataset(history_id)
10 dataset2_id = self._test_dataset(history_id)
11 dataset3_id = self._test_dataset(history_id)
12 collection_response = self.gi.histories.create_dataset_collection(
13 history_id=history_id,
14 collection_description=collections.CollectionDescription(
15 name="MyDatasetList",
16 elements=[
17 collections.HistoryDatasetElement(name="sample1", id=dataset1_id),
18 collections.HistoryDatasetElement(name="sample2", id=dataset2_id),
19 collections.HistoryDatasetElement(name="sample3", id=dataset3_id),
20 ]
21 )
22 )
23 self.assertEqual(collection_response["name"], "MyDatasetList")
24 self.assertEqual(collection_response["collection_type"], "list")
25 elements = collection_response["elements"]
26 self.assertEqual(len(elements), 3)
27 self.assertEqual(elements[0]["element_index"], 0)
28 self.assertEqual(elements[0]["object"]["id"], dataset1_id)
29 self.assertEqual(elements[1]["object"]["id"], dataset2_id)
30 self.assertEqual(elements[2]["object"]["id"], dataset3_id)
31 self.assertEqual(elements[2]["element_identifier"], "sample3")
32
33 def test_create_list_of_paired_datasets_in_history(self):
34 history_id = self.gi.histories.create_history(name="TestDSListCreate")["id"]
35 dataset1_id = self._test_dataset(history_id)
36 dataset2_id = self._test_dataset(history_id)
37 dataset3_id = self._test_dataset(history_id)
38 dataset4_id = self._test_dataset(history_id)
39 collection_response = self.gi.histories.create_dataset_collection(
40 history_id=history_id,
41 collection_description=collections.CollectionDescription(
42 name="MyListOfPairedDatasets",
43 type="list:paired",
44 elements=[
45 collections.CollectionElement(
46 name="sample1",
47 type="paired",
48 elements=[
49 collections.HistoryDatasetElement(name="forward", id=dataset1_id),
50 collections.HistoryDatasetElement(name="reverse", id=dataset2_id),
51 ]
52 ),
53 collections.CollectionElement(
54 name="sample2",
55 type="paired",
56 elements=[
57 collections.HistoryDatasetElement(name="forward", id=dataset3_id),
58 collections.HistoryDatasetElement(name="reverse", id=dataset4_id),
59 ]
60 ),
61 ]
62 )
63 )
64 self.assertEqual(collection_response["name"], "MyListOfPairedDatasets")
65 self.assertEqual(collection_response["collection_type"], "list:paired")
66 elements = collection_response["elements"]
67 self.assertEqual(len(elements), 2)
68 self.assertEqual(elements[0]["element_index"], 0)
69 created_pair1 = elements[0]["object"]
70 self.assertEqual(created_pair1["collection_type"], "paired")
71 self.assertEqual(len(created_pair1["elements"]), 2)
72 forward_element1 = created_pair1["elements"][0]
73 self.assertEqual(forward_element1["element_identifier"], "forward")
74 self.assertEqual(forward_element1["element_index"], 0)
75 forward_dataset1 = forward_element1["object"]
76 self.assertEqual(forward_dataset1["id"], dataset1_id)
77
78 self.assertEqual(elements[1]["element_index"], 1)
79 created_pair2 = elements[1]["object"]
80 self.assertEqual(created_pair2["collection_type"], "paired")
81 self.assertEqual(len(created_pair2["elements"]), 2)
82 reverse_element2 = created_pair2["elements"][1]
83 reverse_dataset2 = reverse_element2["object"]
84
85 self.assertEqual(reverse_element2["element_identifier"], "reverse")
86 self.assertEqual(reverse_element2["element_index"], 1)
87 self.assertEqual(reverse_dataset2["id"], dataset4_id)
88
89 def test_collections_in_history_index(self):
90 history_id = self.gi.histories.create_history(name="TestHistoryDSIndex")["id"]
91 history_dataset_collection = self._create_pair_in_history(history_id)
92 contents = self.gi.histories.show_history(history_id, contents=True)
93 self.assertEqual(len(contents), 3)
94 self.assertEqual(contents[2]["id"], history_dataset_collection["id"])
95 self.assertEqual(contents[2]["name"], "MyTestPair")
96 self.assertEqual(contents[2]["collection_type"], "paired")
97
98 def test_show_history_dataset_collection(self):
99 history_id = self.gi.histories.create_history(name="TestHistoryDSIndexShow")["id"]
100 history_dataset_collection = self._create_pair_in_history(history_id)
101 show_response = self.gi.histories.show_dataset_collection(history_id, history_dataset_collection["id"])
102 for key in ["collection_type", "elements", "name", "deleted", "visible"]:
103 self.assertIn(key, show_response)
104 self.assertFalse(show_response["deleted"])
105 self.assertTrue(show_response["visible"])
106
107 def test_delete_history_dataset_collection(self):
108 history_id = self.gi.histories.create_history(name="TestHistoryDSDelete")["id"]
109 history_dataset_collection = self._create_pair_in_history(history_id)
110 self.gi.histories.delete_dataset_collection(history_id, history_dataset_collection["id"])
111 show_response = self.gi.histories.show_dataset_collection(history_id, history_dataset_collection["id"])
112 self.assertTrue(show_response["deleted"])
113
114 def test_update_history_dataset_collection(self):
115 history_id = self.gi.histories.create_history(name="TestHistoryDSDelete")["id"]
116 history_dataset_collection = self._create_pair_in_history(history_id)
117 self.gi.histories.update_dataset_collection(history_id, history_dataset_collection["id"], visible=False)
118 show_response = self.gi.histories.show_dataset_collection(history_id, history_dataset_collection["id"])
119 self.assertFalse(show_response["visible"])
120
121 def _create_pair_in_history(self, history_id):
122 dataset1_id = self._test_dataset(history_id)
123 dataset2_id = self._test_dataset(history_id)
124 collection_response = self.gi.histories.create_dataset_collection(
125 history_id=history_id,
126 collection_description=collections.CollectionDescription(
127 name="MyTestPair",
128 type="paired",
129 elements=[
130 collections.HistoryDatasetElement(name="forward", id=dataset1_id),
131 collections.HistoryDatasetElement(name="reverse", id=dataset2_id),
132 ]
133 )
134 )
135 return collection_response