diff --git a/juju/model.py b/juju/model.py index 7f8d68021..fdb1973ee 100644 --- a/juju/model.py +++ b/juju/model.py @@ -2581,6 +2581,12 @@ async def wait_for_idle(self, apps=None, raise_on_error=True, raise_on_blocked=F timeout = timedelta(seconds=timeout) if timeout is not None else None idle_period = timedelta(seconds=idle_period) start_time = datetime.now() + # Type check against the common error of passing a str for apps + if apps is not None and (not isinstance(apps, list) or + any(not isinstance(o, str) + for o in apps)): + raise JujuError(f'Expected a List[str] for apps, given {apps}') + apps = apps or self.applications idle_times = {} last_log_time = None diff --git a/tests/unit/test_model.py b/tests/unit/test_model.py index 5a2d10fc6..07b9a4cad 100644 --- a/tests/unit/test_model.py +++ b/tests/unit/test_model.py @@ -11,7 +11,7 @@ from juju.model import Model from juju.application import Application from juju import jasyncio -from juju.errors import JujuConnectionError +from juju.errors import JujuConnectionError, JujuError def _make_delta(entity, type_, data=None): @@ -289,6 +289,21 @@ async def test_no_args(self): # no apps so should return right away await m.wait_for_idle(wait_for_active=True) + @pytest.mark.asyncio + async def test_apps_no_lst(self): + m = Model() + with self.assertRaises(JujuError): + # apps arg has to be a List[str] + await m.wait_for_idle(apps="should-be-list") + + with self.assertRaises(JujuError): + # apps arg has to be a List[str] + await m.wait_for_idle(apps=3) + + with self.assertRaises(JujuError): + # apps arg has to be a List[str] + await m.wait_for_idle(apps=[3]) + @pytest.mark.asyncio async def test_timeout(self): m = Model()