From 02628a1c581ef96374bbaee64a37e349875d202f Mon Sep 17 00:00:00 2001 From: Caner Derici Date: Wed, 12 Oct 2022 09:04:34 -0600 Subject: [PATCH 1/2] Check arg to be a List[str] instead of any iterable for wait_for_idle --- juju/model.py | 6 ++++++ 1 file changed, 6 insertions(+) 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 From d3f72a885ad651534f82b48122824ce6c4cce078 Mon Sep 17 00:00:00 2001 From: Caner Derici Date: Wed, 12 Oct 2022 09:05:06 -0600 Subject: [PATCH 2/2] Add some unit tests for arg check for wait_for_idle --- tests/unit/test_model.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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()