X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FN2VC.git;a=blobdiff_plain;f=modules%2Flibjuju%2Ftests%2Fintegration%2Ftest_controller.py;fp=modules%2Flibjuju%2Ftests%2Fintegration%2Ftest_controller.py;h=f3840cc4f6fd10c671753630cd8be185207fad26;hp=0000000000000000000000000000000000000000;hb=68858c1915122c2dbc8999a5cd3229694abf5f3a;hpb=032a71b2a6692b8b4e30f629a1f906d246f06736 diff --git a/modules/libjuju/tests/integration/test_controller.py b/modules/libjuju/tests/integration/test_controller.py new file mode 100644 index 0000000..f3840cc --- /dev/null +++ b/modules/libjuju/tests/integration/test_controller.py @@ -0,0 +1,77 @@ +import pytest +import uuid + +from .. import base +from juju.controller import Controller +from juju.errors import JujuAPIError + + +@base.bootstrapped +@pytest.mark.asyncio +async def test_add_user(event_loop): + async with base.CleanController() as controller: + username = 'test{}'.format(uuid.uuid4()) + await controller.add_user(username) + result = await controller.get_user(username) + res_ser = result.serialize()['results'][0].serialize() + assert res_ser['result'] is not None + + +@base.bootstrapped +@pytest.mark.asyncio +async def test_disable_enable_user(event_loop): + async with base.CleanController() as controller: + username = 'test-disable{}'.format(uuid.uuid4()) + await controller.add_user(username) + await controller.disable_user(username) + result = await controller.get_user(username) + res_ser = result.serialize()['results'][0].serialize() + assert res_ser['result'].serialize()['disabled'] is True + await controller.enable_user(username) + result = await controller.get_user(username) + res_ser = result.serialize()['results'][0].serialize() + assert res_ser['result'].serialize()['disabled'] is False + + +@base.bootstrapped +@pytest.mark.asyncio +async def test_change_user_password(event_loop): + async with base.CleanController() as controller: + username = 'test-password{}'.format(uuid.uuid4()) + await controller.add_user(username) + await controller.change_user_password(username, 'password') + try: + new_controller = Controller() + await new_controller.connect( + controller.connection.endpoint, username, 'password') + result = True + await new_controller.disconnect() + except JujuAPIError: + result = False + assert result is True + + +@base.bootstrapped +@pytest.mark.asyncio +async def test_grant(event_loop): + async with base.CleanController() as controller: + username = 'test-grant{}'.format(uuid.uuid4()) + await controller.add_user(username) + await controller.grant(username, 'superuser') + result = await controller.get_user(username) + result = result.serialize()['results'][0].serialize()['result']\ + .serialize() + assert result['access'] == 'superuser' + await controller.grant(username, 'login') + result = await controller.get_user(username) + result = result.serialize()['results'][0].serialize()['result']\ + .serialize() + assert result['access'] == 'login' + + +@base.bootstrapped +@pytest.mark.asyncio +async def test_get_models(event_loop): + async with base.CleanController() as controller: + result = await controller.get_models() + assert isinstance(result.serialize()['user-models'], list)