Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdbeek committed May 21, 2024
1 parent 592f709 commit 7f9a46c
Show file tree
Hide file tree
Showing 14 changed files with 102 additions and 85 deletions.
2 changes: 1 addition & 1 deletion test/unit/app/jobs/test_job_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_job_context_discover_outputs_flushes_once(mocker):
sa_session = app.model.context
# mocker is a pytest-mock fixture

u = model.User(email="[email protected]", password="password")
u = model.User(email="[email protected]", password="password", username="collection")
h = model.History(name="Test History", user=u)

tool = Tool(app)
Expand Down
6 changes: 3 additions & 3 deletions test/unit/app/jobs/test_rule_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ def __setup_fixtures(app):
# user1 has 3 jobs queued and 2 jobs running on cluster1 and one queued and
# on running job on local. user2 has a queued and running job on the cluster.
# user3 has no jobs.
user1 = model.User(email=USER_EMAIL_1, password="pass1")
user2 = model.User(email=USER_EMAIL_2, password="pass2")
user3 = model.User(email=USER_EMAIL_2, password="pass2")
user1 = model.User(email=USER_EMAIL_1, password="pass1", username="u1")
user2 = model.User(email=USER_EMAIL_2, password="pass2", username="u2")
user3 = model.User(email=USER_EMAIL_2, password="pass2", username="u3")

app.add(user1, user2, user3)

Expand Down
20 changes: 20 additions & 0 deletions test/unit/app/managers/test_JobConnectionsManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from galaxy.managers.job_connections import JobConnectionsManager
from galaxy.model import (
DatasetCollection,
History,
HistoryDatasetAssociation,
HistoryDatasetCollectionAssociation,
Job,
Expand All @@ -25,11 +27,19 @@ def job_connections_manager(sa_session) -> JobConnectionsManager:

# =============================================================================
def setup_connected_dataset(sa_session: galaxy_scoped_session):
history = History()
sa_session.add(history)
center_hda = HistoryDatasetAssociation(sa_session=sa_session, create_dataset=True)
input_hda = HistoryDatasetAssociation(sa_session=sa_session, create_dataset=True)
input_dc = DatasetCollection(collection_type="list")
input_hdca = HistoryDatasetCollectionAssociation()
input_hdca.collection = input_dc
output_hda = HistoryDatasetAssociation(sa_session=sa_session, create_dataset=True)
output_dc = DatasetCollection(collection_type="list")
output_hdca = HistoryDatasetCollectionAssociation()
output_hdca.collection = output_dc
history.stage_addition([center_hda, input_hda, input_hdca, output_hda, output_hdca])
history.add_pending_items()
input_job = Job()
output_job = Job()
input_job.add_output_dataset("output_hda", center_hda)
Expand All @@ -55,12 +65,22 @@ def setup_connected_dataset(sa_session: galaxy_scoped_session):


def setup_connected_dataset_collection(sa_session: galaxy_scoped_session):
history = History()
sa_session.add(history)
center_dc = DatasetCollection(collection_type="list")
center_hdca = HistoryDatasetCollectionAssociation()
center_hdca.collection = center_dc
input_hda1 = HistoryDatasetAssociation(sa_session=sa_session, create_dataset=True)
input_hda2 = HistoryDatasetAssociation(sa_session=sa_session, create_dataset=True)
input_dc = DatasetCollection(collection_type="list")
input_hdca = HistoryDatasetCollectionAssociation()
input_hdca.collection = input_dc
output_hda = HistoryDatasetAssociation(sa_session=sa_session, create_dataset=True)
output_dc = DatasetCollection(collection_type="list")
output_hdca = HistoryDatasetCollectionAssociation()
output_hdca.collection = output_dc
history.stage_addition([center_hdca, input_hda1, input_hda2, input_hdca, output_hda, output_hdca])
history.add_pending_items()
input_job = Job()
output_job = Job()
input_job.add_output_dataset_collection("output_hdca", center_hdca)
Expand Down
4 changes: 2 additions & 2 deletions test/unit/app/tools/test_error_reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_hda_security(self, tmp_path):
permissions = {access_action: [private_role], manage_action: [private_role]}
security_agent.set_all_dataset_permissions(hda.dataset, permissions)

other_user = model.User(email="[email protected]", password="mockpass2")
other_user = model.User(email="[email protected]", password="mockpass2", username="otheruser")
self._commit_objects([other_user])
security_agent = self.app.security_agent
email_path = self.email_path
Expand Down Expand Up @@ -125,7 +125,7 @@ def test_no_redact_user_details_in_bugreport(self, tmp_path):
)

def _setup_model_objects(self):
user = model.User(email=TEST_USER_EMAIL, password="mockpass")
user = model.User(email=TEST_USER_EMAIL, password="mockpass", username=TEST_USER_EMAIL.split("@")[0])
job = model.Job()
job.tool_id = "cat1"
job.history = model.History()
Expand Down
4 changes: 2 additions & 2 deletions test/unit/app/tools/test_history_imp_exp.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def t_data_path(name):
def _run_jihaw_cleanup(archive_dir, app=None):
app = app or _mock_app()
job = model.Job()
job.user = model.User(email="[email protected]", password="test")
job.user = model.User(email="[email protected]", password="test", username="test")
job.tool_stderr = ""
jiha = model.JobImportHistoryArchive(job=job, archive_dir=archive_dir)
app.model.context.current.add_all([job, jiha])
Expand Down Expand Up @@ -661,7 +661,7 @@ def _setup_history_for_export(history_name):
sa_session = app.model.context

email = history_name.replace(" ", "-") + "[email protected]"
u = model.User(email=email, password="password")
u = model.User(email=email, password="password", username=email.split("@")[0])
h = model.History(name=history_name, user=u)

return app, sa_session, h
Expand Down
4 changes: 1 addition & 3 deletions test/unit/app/tools/test_toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,7 @@ def __test_workflow(self):
workflow = model.Workflow()
workflow.stored_workflow = stored_workflow
stored_workflow.latest_workflow = workflow
user = model.User()
user.email = "[email protected]"
user.password = "passw0rD1"
user = model.User(email="[email protected]", password="passw0rD1", username="test")
stored_workflow.user = user
self.app.model.context.add(workflow)
self.app.model.context.add(stored_workflow)
Expand Down
4 changes: 2 additions & 2 deletions test/unit/data/model/test_model_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def _import_library_target(target, work_directory):
with store.DirectoryModelExportStore(temp_directory, app=app, serialize_dataset_objects=True) as export_store:
persist_target_to_export_store(target, export_store, app.object_store, work_directory)

u = model.User(email="[email protected]", password="password")
u = model.User(email="[email protected]", password="password", username="library")

import_options = store.ImportOptions(allow_dataset_object_edit=True, allow_library_creation=True)
import_model_store = store.get_import_model_store_for_directory(
Expand All @@ -240,7 +240,7 @@ def _import_library_target(target, work_directory):
def _import_directory_to_history(app, target, work_directory):
sa_session = app.model.context

u = model.User(email="[email protected]", password="password")
u = model.User(email="[email protected]", password="password", username="collection")
import_history = model.History(name="Test History for Import", user=u)

sa_session = app.model.context
Expand Down
16 changes: 8 additions & 8 deletions test/unit/data/model/test_model_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def test_import_library_require_permissions():
app = _mock_app()
sa_session = app.model.context

u = model.User(email="[email protected]", password="password")
u = model.User(email="[email protected]", password="password", username="collection")

library = model.Library(name="my library 1", description="my library description", synopsis="my synopsis")
root_folder = model.LibraryFolder(name="my library 1", description="folder description")
Expand Down Expand Up @@ -340,7 +340,7 @@ def test_import_export_library():
app = _mock_app()
sa_session = app.model.context

u = model.User(email="[email protected]", password="password")
u = model.User(email="[email protected]", password="password", username="collection")

library = model.Library(name="my library 1", description="my library description", synopsis="my synopsis")
root_folder = model.LibraryFolder(name="my library 1", description="folder description")
Expand Down Expand Up @@ -684,7 +684,7 @@ def test_import_export_edit_collection():
app = _mock_app()
sa_session = app.model.context

u = model.User(email="[email protected]", password="password")
u = model.User(email="[email protected]", password="password", username="collection")
h = model.History(name="Test History", user=u)

c1 = model.DatasetCollection(collection_type="list", populated=False)
Expand Down Expand Up @@ -761,7 +761,7 @@ def test_import_export_composite_datasets():
app = _mock_app()
sa_session = app.model.context

u = model.User(email="[email protected]", password="password")
u = model.User(email="[email protected]", password="password", username="collection")
h = model.History(name="Test History", user=u)

d1 = _create_datasets(sa_session, h, 1, extension="html")[0]
Expand Down Expand Up @@ -804,7 +804,7 @@ def test_edit_metadata_files():
app = _mock_app(store_by="uuid")
sa_session = app.model.context

u = model.User(email="[email protected]", password="password")
u = model.User(email="[email protected]", password="password", username="collection")
h = model.History(name="Test History", user=u)

d1 = _create_datasets(sa_session, h, 1, extension="bam")[0]
Expand Down Expand Up @@ -910,7 +910,7 @@ def _assert_simple_cat_job_imported(imported_history, state="ok"):
def _setup_simple_cat_job(app, state="ok"):
sa_session = app.model.context

u = model.User(email="[email protected]", password="password")
u = model.User(email="[email protected]", password="password", username="collection")
h = model.History(name="Test History", user=u)

d1, d2 = _create_datasets(sa_session, h, 2)
Expand Down Expand Up @@ -966,7 +966,7 @@ def _setup_invocation(app):
def _setup_simple_collection_job(app, state="ok"):
sa_session = app.model.context

u = model.User(email="[email protected]", password="password")
u = model.User(email="[email protected]", password="password", username="collection")
h = model.History(name="Test History", user=u)

d1, d2, d3, d4 = _create_datasets(sa_session, h, 4)
Expand Down Expand Up @@ -1170,7 +1170,7 @@ def setup_fixture_context_with_user(
) -> StoreFixtureContextWithUser:
app = _mock_app(store_by=store_by)
sa_session = app.model.context
user = model.User(email=user_email, password="password")
user = model.User(email=user_email, password="password", username=user_email.split("@")[0])
return StoreFixtureContextWithUser(app=app, sa_session=sa_session, user=user)


Expand Down
Loading

0 comments on commit 7f9a46c

Please sign in to comment.