Adapt unit tests to copying HDAs when creating collections

This commit is contained in:
mvdbeek
2018-08-26 22:13:50 +02:00
parent ce892a028c
commit d4a80e61e1
2 changed files with 39 additions and 23 deletions
+4 -4
View File
@@ -44,7 +44,7 @@ class DatasetCollectionManagerTestCase(BaseTestCase, CreatesCollectionsMixin):
element_identifiers=element_identifiers)
self.assertIsInstance(hdca, model.HistoryDatasetCollectionAssociation)
self.assertEqual(hdca.name, 'test collection')
self.assertEqual(hdca.hid, 4)
self.assertEqual(hdca.hid, 7)
self.assertFalse(hdca.deleted)
self.assertTrue(hdca.visible)
@@ -61,19 +61,19 @@ class DatasetCollectionManagerTestCase(BaseTestCase, CreatesCollectionsMixin):
self.assertEqual(collection.elements[0].element_identifier, 'one')
self.assertEqual(collection.elements[0].element_index, 0)
self.assertEqual(collection.elements[0].element_type, 'hda')
self.assertEqual(collection.elements[0].element_object, hda1)
self.assertEqual(collection.elements[0].element_object.dataset, hda1.dataset)
self.assertIsInstance(collection.elements[1], model.DatasetCollectionElement)
self.assertEqual(collection.elements[1].element_identifier, 'two')
self.assertEqual(collection.elements[1].element_index, 1)
self.assertEqual(collection.elements[1].element_type, 'hda')
self.assertEqual(collection.elements[1].element_object, hda2)
self.assertEqual(collection.elements[1].element_object.dataset, hda2.dataset)
self.assertIsInstance(collection.elements[2], model.DatasetCollectionElement)
self.assertEqual(collection.elements[2].element_identifier, 'three')
self.assertEqual(collection.elements[2].element_index, 2)
self.assertEqual(collection.elements[2].element_type, 'hda')
self.assertEqual(collection.elements[2].element_object, hda3)
self.assertEqual(collection.elements[2].element_object.dataset, hda3.dataset)
self.log("should be able to create a new Collection via objects")
elements = dict(one=hda1, two=hda2, three=hda3)
@@ -59,7 +59,7 @@ class HistoryAsContainerTestCase(HistoryAsContainerBaseTestCase):
self.log("calling contents on an history with both hdas and collections should return both")
hdca = self.add_list_collection_to_history(history, hdas)
all_contents = list(self.contents_manager.contents(history))
self.assertEqual(all_contents, list(ordered_hda_contents) + [hdca])
self.assertEqual(all_contents, list(ordered_hda_contents) + hdca.dataset_instances + [hdca])
def test_contained(self):
user2 = self.user_manager.create(**user2_data)
@@ -70,8 +70,8 @@ class HistoryAsContainerTestCase(HistoryAsContainerBaseTestCase):
self.log("calling contained on an history with both hdas and collections should return only hdas")
hdas = [self.add_hda_to_history(history, name=('hda-' + str(x))) for x in range(3)]
self.add_list_collection_to_history(history, hdas)
self.assertEqual(list(self.contents_manager.contained(history)), hdas)
hdca = self.add_list_collection_to_history(history, hdas)
self.assertEqual(list(self.contents_manager.contained(history)), hdas + hdca.dataset_instances)
def test_subcontainers(self):
user2 = self.user_manager.create(**user2_data)
@@ -92,8 +92,12 @@ class HistoryAsContainerTestCase(HistoryAsContainerBaseTestCase):
contents = []
contents.extend([self.add_hda_to_history(history, name=('hda-' + str(x))) for x in range(3)])
contents.append(self.add_list_collection_to_history(history, contents[:3]))
contents.extend([self.add_hda_to_history(history, name=('hda-' + str(x))) for x in range(4, 6)])
for hda in contents[-1].dataset_instances:
contents.insert(-1, hda)
contents.extend([self.add_hda_to_history(history, name=('hda-' + str(x))) for x in range(7, 9)])
contents.append(self.add_list_collection_to_history(history, contents[4:6]))
for hda in contents[-1].dataset_instances:
contents.insert(-1, hda)
self.log("should be able to limit and offset")
results = self.contents_manager.contents(history)
@@ -110,16 +114,23 @@ class HistoryAsContainerTestCase(HistoryAsContainerBaseTestCase):
user2 = self.user_manager.create(**user2_data)
history = self.history_manager.create(name='history', user=user2)
contents = []
invisible = []
contents.extend([self.add_hda_to_history(history, name=('hda-' + str(x))) for x in range(3)])
contents.append(self.add_list_collection_to_history(history, contents[:3]))
contents.extend([self.add_hda_to_history(history, name=('hda-' + str(x))) for x in range(4, 6)])
contents.append(self.add_list_collection_to_history(history, contents[4:6]))
for hda in contents[-1].dataset_instances:
contents.insert(-1, hda)
invisible.append(hda)
contents.extend([self.add_hda_to_history(history, name=('hda-' + str(x))) for x in range(7, 9)])
contents.append(self.add_list_collection_to_history(history, contents[7:9]))
for hda in contents[-1].dataset_instances:
contents.insert(-1, hda)
invisible.append(hda)
self.log("should allow filter on deleted")
self.hda_manager.delete(contents[1])
self.hda_manager.delete(contents[4])
contents[6].deleted = True
deleted = [contents[1], contents[4], contents[6]]
self.hda_manager.delete(contents[6])
contents[8].deleted = True
deleted = [contents[1], contents[6], contents[8]]
self.app.model.context.flush()
# TODO: cross db compat?
@@ -136,9 +147,10 @@ class HistoryAsContainerTestCase(HistoryAsContainerBaseTestCase):
self.log("should allow filter on visible")
contents[2].visible = False
contents[5].visible = False
contents[6].visible = False
invisible = [contents[2], contents[5], contents[6]]
contents[7].visible = False
contents[8].visible = False
invisible.extend([contents[2], contents[7], contents[8]])
invisible.sort(key=lambda hda: hda.hid)
self.app.model.context.flush()
filters = [text('visible = 0')]
@@ -147,10 +159,10 @@ class HistoryAsContainerTestCase(HistoryAsContainerBaseTestCase):
filters=[HDA.visible == false()]), invisible)
filter_limited_contents = self.contents_manager.contents(history,
filters=[HDA.visible == false()], limit=2, offset=1)
self.assertEqual(filter_limited_contents, invisible[1:])
self.assertEqual(filter_limited_contents, invisible[1:3])
self.log("should allow filtering more than one attribute")
deleted_and_invisible = [contents[6]]
deleted_and_invisible = [contents[8]]
filters = [text('deleted = 1'), text('visible = 0')]
self.assertEqual(self.contents_manager.contents(history, filters=filters), deleted_and_invisible)
@@ -161,7 +173,7 @@ class HistoryAsContainerTestCase(HistoryAsContainerBaseTestCase):
self.assertEqual(offset_too_far, [])
self.log("should allow filtering more than one attribute")
deleted_and_invisible = [contents[6]]
deleted_and_invisible = [contents[8]]
# note the two syntaxes both work
self.assertEqual(self.contents_manager.contents(history,
filters=[text('deleted = 1'), text('visible = 0')]), deleted_and_invisible)
@@ -172,9 +184,9 @@ class HistoryAsContainerTestCase(HistoryAsContainerBaseTestCase):
self.assertEqual(offset_too_far, [])
self.log("should allow filtering using like")
# find 'hda-4'
self.assertEqual([contents[4]],
self.contents_manager.contents(history, filters=[HDA.name.like('%-4')]))
# find 'hda-0'
self.assertEqual([contents[0]],
self.contents_manager.contents(history, filters=[HDA.name.like('%-0'), text('visible = 1')]))
# the collections added above have the default name 'test collection'
self.assertEqual(self.contents_manager.subcontainers(history),
self.contents_manager.contents(history, filters=[HDA.name.like('%collect%')]))
@@ -185,8 +197,12 @@ class HistoryAsContainerTestCase(HistoryAsContainerBaseTestCase):
contents = []
contents.extend([self.add_hda_to_history(history, name=('hda-' + str(x))) for x in range(3)])
contents.append(self.add_list_collection_to_history(history, contents[:3]))
for hda in contents[-1].dataset_instances:
contents.insert(-1, hda)
contents.extend([self.add_hda_to_history(history, name=('hda-' + str(x))) for x in range(4, 6)])
contents.append(self.add_list_collection_to_history(history, contents[4:6]))
for hda in contents[-1].dataset_instances:
contents.insert(-1, hda)
self.log("should default to hid order_by")
self.assertEqual(self.contents_manager.contents(history), contents)
@@ -259,7 +275,7 @@ class HistoryAsContainerTestCase(HistoryAsContainerBaseTestCase):
HDA = self.hda_manager.model_class
self.assertEqual(self.contents_manager.contents_count(history, filters=[HDA.deleted == true()]), 3)
filters = [text('visible = 0')]
self.assertEqual(self.contents_manager.contents_count(history, filters=filters), 3)
self.assertEqual(self.contents_manager.contents_count(history, filters=filters), 8)
filters = [text('deleted = 1'), text('visible = 0')]
self.assertEqual(self.contents_manager.contents_count(history, filters=filters), 1)