diff --git a/pyproject.toml b/pyproject.toml index 47c59dd..267b12b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -78,6 +78,7 @@ __version__ = "{version}" [tool.pytest.ini_options] addopts = "--ignore-glob=*/version.py --ignore-glob=*data_dir/*" testpaths = "." +asyncio_default_fixture_loop_scope="function" [tool.black] line-length = 110 diff --git a/test-requirements.txt b/test-requirements.txt index 4b4429e..7637752 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -8,3 +8,4 @@ pre-commit boto3 botocore playwright +pytest-asyncio diff --git a/tests/test_lfa_scheduler_dashboard.py b/tests/test_lfa_scheduler_dashboard.py new file mode 100644 index 0000000..38bca9c --- /dev/null +++ b/tests/test_lfa_scheduler_dashboard.py @@ -0,0 +1,43 @@ +import os +from datetime import datetime + +import pytest + +# Objects to test instances against. +from rubin_scheduler.scheduler.features.conditions import Conditions +from rubin_scheduler.scheduler.schedulers.core_scheduler import CoreScheduler + +from schedview.app.scheduler_dashboard.scheduler_dashboard_app import LFASchedulerSnapshotDashboard + + +@pytest.mark.asyncio +async def test_get_scheduler_list(): + scheduler = LFASchedulerSnapshotDashboard() + scheduler.telescope = None + await scheduler.get_scheduler_list() + # No snapshots should be retreived if it isn't an LFA environment + # the dropdown has one empty option + assert len(scheduler.param.scheduler_fname.objects) >= 1 + + +@pytest.mark.asyncio +async def test_get_scheduler_list_in_USDF(): + scheduler = LFASchedulerSnapshotDashboard() + + scheduler.telescope = None + scheduler.pickles_date = datetime(2024, 10, 1, 21, 26, 23) + await scheduler.get_scheduler_list() + # make sure it's a LFA environment by checking + # the env variables needed for LFA mode are set + if os.environ.get("AWS_SHARED_CREDENTIALS_FILE") and os.environ.get("S3_ENDPOINT_URL"): + # at least one snapshot file should be retreived + # the dropdown should have one empty option + + # at least one snapshot + assert len(scheduler.param.scheduler_fname.objects) >= 2 + scheduler.scheduler_fname = scheduler.param["scheduler_fname"].objects[1] + scheduler.read_scheduler() + assert isinstance(scheduler._scheduler, CoreScheduler) + assert isinstance(scheduler._conditions, Conditions) + else: + # pass the test if it isn't an LFA environment + pass