From 49fee79eb5dbe410f06c0edd4f99b32564da4676 Mon Sep 17 00:00:00 2001 From: John Davis Date: Fri, 11 Aug 2023 10:36:43 -0400 Subject: [PATCH] Resuse MockQuery and MockContext in other unit tests --- .../app_unittest_utils/tools_support.py | 3 ++ test/unit/app/jobs/test_job_wrapper.py | 38 ++----------------- 2 files changed, 7 insertions(+), 34 deletions(-) diff --git a/lib/galaxy/app_unittest_utils/tools_support.py b/lib/galaxy/app_unittest_utils/tools_support.py index 8f0ae30b5182..3c9b06259d02 100644 --- a/lib/galaxy/app_unittest_utils/tools_support.py +++ b/lib/galaxy/app_unittest_utils/tools_support.py @@ -143,6 +143,9 @@ def flush(self): def add(self, object): self.created_objects.append(object) + def commit(self): + pass + class MockQuery: def __init__(self, class_objects): diff --git a/test/unit/app/jobs/test_job_wrapper.py b/test/unit/app/jobs/test_job_wrapper.py index 1e5b6963a03f..5e664f323d59 100644 --- a/test/unit/app/jobs/test_job_wrapper.py +++ b/test/unit/app/jobs/test_job_wrapper.py @@ -7,7 +7,10 @@ Type, ) -from galaxy.app_unittest_utils.tools_support import UsesApp +from galaxy.app_unittest_utils.tools_support import ( + MockContext, + UsesApp, +) from galaxy.jobs import ( JobWrapper, TaskWrapper, @@ -134,39 +137,6 @@ def url_to_destination(self): pass -class MockContext: - def __init__(self, model_objects): - self.expunged_all = False - self.model_objects = model_objects - self.created_objects = [] - - def expunge_all(self): - self.expunged_all = True - - def query(self, clazz): - return MockQuery(self.model_objects.get(clazz)) - - def flush(self): - pass - - def commit(self): - pass - - def add(self, object): - self.created_objects.append(object) - - -class MockQuery: - def __init__(self, class_objects): - self.class_objects = class_objects - - def filter_by(self, **kwds): - return Bunch(first=lambda: None) - - def get(self, id): - return self.class_objects.get(id, None) - - class MockTool: def __init__(self, app): self.version_string_cmd = TEST_VERSION_COMMAND