Skip to content

Commit

Permalink
Add unit test; adjust tests to account for order-by columns
Browse files Browse the repository at this point in the history
  • Loading branch information
jdavcs committed Nov 27, 2023
1 parent 8361313 commit d695173
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions test/unit/data/test_galaxy_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,22 @@ def test_collections_in_library_folders(self):
# assert len(loaded_dataset_collection.datasets) == 2
# assert loaded_dataset_collection.collection_type == "pair"

# TODO breakup this test into separate tests that test the model's public attributes, not the internal query-building logic
def test_dataset_action_tuples(self):
u = model.User(email="foo", password="foo")
h1 = model.History(user=u)
hda1 = model.HistoryDatasetAssociation(history=h1, create_dataset=True, sa_session=self.model.session)
hda2 = model.HistoryDatasetAssociation(history=h1, create_dataset=True, sa_session=self.model.session)
r1 = model.Role()
dp1 = model.DatasetPermissions(action="action1", dataset=hda1.dataset, role=r1)
dp2 = model.DatasetPermissions(action=None, dataset=hda1.dataset, role=r1)
dp3 = model.DatasetPermissions(action="action3", dataset=hda1.dataset, role=r1)
c1 = model.DatasetCollection(collection_type="type1")
dce1 = model.DatasetCollectionElement(collection=c1, element=hda1)
dce2 = model.DatasetCollectionElement(collection=c1, element=hda2)
self.model.session.add_all([u, h1, hda1, hda2, r1, dp1, dp2, dp3, c1, dce1, dce2])
self.model.session.flush()
assert c1.dataset_action_tuples == [("action1", r1.id), ("action3", r1.id)]

def test_nested_collection_attributes(self):
u = model.User(email="[email protected]", password="password")
h1 = model.History(name="History 1", user=u)
Expand Down Expand Up @@ -399,25 +414,25 @@ def test_nested_collection_attributes(self):
)
result = self.model.session.execute(stmt).all()
assert [(r._fields) for r in result] == [
("element_identifier_0", "element_identifier_1", "extension", "state"),
("element_identifier_0", "element_identifier_1", "extension", "state"),
("element_identifier_0", "element_identifier_1", "extension", "state", "element_index", "element_index_1"),
("element_identifier_0", "element_identifier_1", "extension", "state", "element_index", "element_index_1"),
]

stmt = c2._build_nested_collection_attributes_stmt(
element_attributes=("element_identifier",), hda_attributes=("extension",), dataset_attributes=("state",)
)
result = self.model.session.execute(stmt).all()
assert result == [("inner_list", "forward", "bam", "new"), ("inner_list", "reverse", "txt", "new")]
assert result == [("inner_list", "forward", "bam", "new", 0, 0), ("inner_list", "reverse", "txt", "new", 0, 1)]

stmt = c2._build_nested_collection_attributes_stmt(return_entities=(model.HistoryDatasetAssociation,))
result = self.model.session.scalars(stmt).all()
assert result == [d1, d2]
result = self.model.session.execute(stmt).all()
assert result == [(d1, 0, 0), (d2, 0, 1)]

stmt = c2._build_nested_collection_attributes_stmt(
return_entities=(model.HistoryDatasetAssociation, model.Dataset)
)
result = self.model.session.execute(stmt).all()
assert result == [(d1, d1.dataset), (d2, d2.dataset)]
assert result == [(d1, d1.dataset, 0, 0), (d2, d2.dataset, 0, 1)]
# Assert properties that use _get_nested_collection_attributes return correct content
assert c2.dataset_instances == [d1, d2]
assert c2.dataset_elements == [dce1, dce2]
Expand All @@ -439,12 +454,8 @@ def test_nested_collection_attributes(self):

stmt = c4._build_nested_collection_attributes_stmt(element_attributes=("element_identifier",))
result = self.model.session.execute(stmt).all()
assert result == [("outer_list", "inner_list", "forward"), ("outer_list", "inner_list", "reverse")]
assert result == [("outer_list", "inner_list", "forward", 0, 0, 0), ("outer_list", "inner_list", "reverse", 0, 0, 1)]
assert c4.dataset_elements == [dce1, dce2]
assert c4.element_identifiers_extensions_and_paths == [
(("outer_list", "inner_list", "forward"), "bam", "mock_dataset_14.dat"),
(("outer_list", "inner_list", "reverse"), "txt", "mock_dataset_14.dat"),
]

def test_dataset_dbkeys_and_extensions_summary(self):
u = model.User(email="[email protected]", password="password")
Expand Down

0 comments on commit d695173

Please sign in to comment.