From a800f5c2d36b1e1081fef22f6cdc56ae51983ea5 Mon Sep 17 00:00:00 2001 From: jbannister Date: Sat, 2 Oct 2021 12:05:37 +0100 Subject: [PATCH] fix: use correct default scheduler mongo database --- notebooker/web/app.py | 2 +- tests/conftest.py | 2 -- tests/integration/web/test_app.py | 19 +++++++++++++++++++ tests/integration/web/test_scheduling.py | 2 ++ 4 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 tests/integration/web/test_app.py diff --git a/notebooker/web/app.py b/notebooker/web/app.py index 2fad259c..8cc976be 100644 --- a/notebooker/web/app.py +++ b/notebooker/web/app.py @@ -99,7 +99,7 @@ def setup_scheduler(flask_app, web_config): serializer = get_serializer_from_cls(web_config.SERIALIZER_CLS, **web_config.SERIALIZER_CONFIG) if isinstance(serializer, MongoResultSerializer): client = serializer.get_mongo_connection() - database = web_config.SCHEDULER_MONGO_DATABASE or serializer.mongo_host + database = web_config.SCHEDULER_MONGO_DATABASE or serializer.database_name collection = web_config.SCHEDULER_MONGO_COLLECTION or f"{serializer.result_collection_name}_scheduler" jobstores = {"mongo": MongoDBJobStore(database=database, collection=collection, client=client)} else: diff --git a/tests/conftest.py b/tests/conftest.py index e8287fb6..2bdd406a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -81,8 +81,6 @@ def webapp_config(mongo_host, test_db_name, test_lib_name, template_dir, cache_d }, PY_TEMPLATE_BASE_DIR=workspace.workspace, PY_TEMPLATE_SUBDIR="templates", - SCHEDULER_MONGO_COLLECTION=test_lib_name, - SCHEDULER_MONGO_DATABASE=test_db_name, ) diff --git a/tests/integration/web/test_app.py b/tests/integration/web/test_app.py new file mode 100644 index 00000000..f7c2fca5 --- /dev/null +++ b/tests/integration/web/test_app.py @@ -0,0 +1,19 @@ +import mock + +from notebooker.web.app import setup_scheduler + + +def test_setup_scheduler_disabled(flask_app, webapp_config): + webapp_config.DISABLE_SCHEDULER = True + app = setup_scheduler(flask_app, webapp_config) + assert app.apscheduler is None + + +def test_setup_scheduler(flask_app, webapp_config, test_db_name, test_lib_name): + webapp_config.DISABLE_SCHEDULER = False + scheduler_coll = f"{test_lib_name}_scheduler" + with mock.patch("notebooker.web.app.BackgroundScheduler") as sched: + with mock.patch("notebooker.web.app.MongoDBJobStore") as jobstore: + app = setup_scheduler(flask_app, webapp_config) + assert app.apscheduler is not None + jobstore.assert_called_with(database=test_db_name, collection=scheduler_coll, client=mock.ANY) diff --git a/tests/integration/web/test_scheduling.py b/tests/integration/web/test_scheduling.py index 70b88c03..f7fd2e4a 100644 --- a/tests/integration/web/test_scheduling.py +++ b/tests/integration/web/test_scheduling.py @@ -110,10 +110,12 @@ def test_delete_scheduled_jobs(flask_app, setup_workspace): def test_scheduler_runs_notebooks(flask_app, setup_workspace): with flask_app.test_client() as client: + def fake_post(url, params): path = url.replace("http://", "").split("/", 1)[1] client.post(f"/{path}?{params}") return mock.MagicMock() + with mock.patch("notebooker.web.scheduler.requests.post", side_effect=fake_post): rv = client.get("/core/get_all_available_results?limit=50") assert len(json.loads(rv.data)) == 0