Skip to content

Commit

Permalink
Merge pull request #55 from man-group/feature/scheduling
Browse files Browse the repository at this point in the history
fix: use correct default scheduler mongo database
  • Loading branch information
jonbannister authored Oct 2, 2021
2 parents 8df0066 + a800f5c commit 6caf2bb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion notebooker/web/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 0 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)


Expand Down
19 changes: 19 additions & 0 deletions tests/integration/web/test_app.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions tests/integration/web/test_scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6caf2bb

Please sign in to comment.