Skip to content

Commit

Permalink
Reduce duplication in test_model_store.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Jan 23, 2024
1 parent 9f467d4 commit e03b238
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions test/unit/data/model/test_model_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ def test_import_export_history_hidden_false_with_hidden_dataset():

u, h, d1, d2, j = _setup_simple_cat_job(app)
d2.visible = False
session = app.model.session
with transaction(session):
session.commit()
app.commit()

imported_history = _import_export_history(app, h, export_files="copy", include_hidden=False)
assert d1.dataset.get_size() == imported_history.datasets[0].get_size()
Expand All @@ -87,9 +85,7 @@ def test_import_export_history_hidden_true_with_hidden_dataset():

u, h, d1, d2, j = _setup_simple_cat_job(app)
d2.visible = False
session = app.model.session
with transaction(session):
session.commit()
app.commit()

imported_history = _import_export_history(app, h, export_files="copy", include_hidden=True)
assert d1.dataset.get_size() == imported_history.datasets[0].get_size()
Expand Down Expand Up @@ -251,8 +247,7 @@ def test_import_library_require_permissions():
root_folder = model.LibraryFolder(name="my library 1", description="folder description")
library.root_folder = root_folder
sa_session.add_all((library, root_folder))
with transaction(sa_session):
sa_session.commit()
app.commit()

temp_directory = mkdtemp()
with store.DirectoryModelExportStore(temp_directory, app=app) as export_store:
Expand Down Expand Up @@ -280,8 +275,7 @@ def test_import_export_library():
root_folder = model.LibraryFolder(name="my library 1", description="folder description")
library.root_folder = root_folder
sa_session.add_all((library, root_folder))
with transaction(sa_session):
sa_session.commit()
app.commit()

subfolder = model.LibraryFolder(name="sub folder 1", description="sub folder")
root_folder.add_folder(subfolder)
Expand All @@ -295,8 +289,7 @@ def test_import_export_library():
sa_session.add(ld)
sa_session.add(ldda)

with transaction(sa_session):
sa_session.commit()
app.commit()
assert len(root_folder.datasets) == 1
assert len(root_folder.folders) == 1

Expand Down Expand Up @@ -338,8 +331,7 @@ def test_import_export_invocation():
sa_session = app.model.context
h2 = model.History(user=workflow_invocation.user)
sa_session.add(h2)
with transaction(sa_session):
sa_session.commit()
app.commit()

import_model_store = store.get_import_model_store_for_directory(
temp_directory, app=app, user=workflow_invocation.user, import_options=store.ImportOptions()
Expand Down Expand Up @@ -1054,6 +1046,11 @@ def read_workflow_from_path(self, app, user, path, allow_in_directory=None):
class TestApp(GalaxyDataTestApp):
workflow_contents_manager = MockWorkflowContentsManager()

def commit(self):
session = self.model.session
with transaction(session):
session.commit()


def _mock_app(store_by=DEFAULT_OBJECT_STORE_BY):
app = TestApp()
Expand Down Expand Up @@ -1091,8 +1088,7 @@ def setup_fixture_context_with_history(
app, sa_session, user = setup_fixture_context_with_user(**kwd)
history = model.History(name=history_name, user=user)
sa_session.add(history)
with transaction(sa_session):
sa_session.commit()
app.commit()
return StoreFixtureContextWithHistory(app, sa_session, user, history)


Expand Down

0 comments on commit e03b238

Please sign in to comment.