X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=tests%2Fbase.py;h=e1ec45238228e284ba41294b6f08161d89cae0f9;hb=dbcac620b62e16f9e4b7a763e1400f2f3a79b285;hp=292d04a755257dc121135bf35048ed390818eaf7;hpb=0f8958d1a9861ca196c613c3f1940aa61c4ddc33;p=osm%2FN2VC.git diff --git a/tests/base.py b/tests/base.py index 292d04a..e1ec452 100644 --- a/tests/base.py +++ b/tests/base.py @@ -19,6 +19,19 @@ bootstrapped = pytest.mark.skipif( reason='bootstrapped Juju environment required') +class CleanController(): + def __init__(self): + self.controller = None + + async def __aenter__(self): + self.controller = Controller() + await self.controller.connect_current() + return self.controller + + async def __aexit__(self, exc_type, exc, tb): + await self.controller.disconnect() + + class CleanModel(): def __init__(self): self.controller = None @@ -31,6 +44,9 @@ class CleanModel(): model_name = 'model-{}'.format(uuid.uuid4()) self.model = await self.controller.add_model(model_name) + # save the model UUID in case test closes model + self.model_uuid = self.model.info.uuid + # Ensure that we connect to the new model by default. This also # prevents failures if test was started with no current model. self._patch_cm = mock.patch.object(JujuData, 'current_model', @@ -42,7 +58,7 @@ class CleanModel(): async def __aexit__(self, exc_type, exc, tb): self._patch_cm.stop() await self.model.disconnect() - await self.controller.destroy_model(self.model.info.uuid) + await self.controller.destroy_model(self.model_uuid) await self.controller.disconnect()