Merge commit '19031b24b523c872c1ac367821dc60c950a09755' as 'modules/libjuju'
[osm/N2VC.git] / modules / libjuju / tests / integration / test_controller.py
1 import pytest
2 import uuid
3
4 from .. import base
5 from juju.controller import Controller
6 from juju.errors import JujuAPIError
7
8
9 @base.bootstrapped
10 @pytest.mark.asyncio
11 async def test_add_user(event_loop):
12 async with base.CleanController() as controller:
13 username = 'test{}'.format(uuid.uuid4())
14 await controller.add_user(username)
15 result = await controller.get_user(username)
16 res_ser = result.serialize()['results'][0].serialize()
17 assert res_ser['result'] is not None
18
19
20 @base.bootstrapped
21 @pytest.mark.asyncio
22 async def test_disable_enable_user(event_loop):
23 async with base.CleanController() as controller:
24 username = 'test-disable{}'.format(uuid.uuid4())
25 await controller.add_user(username)
26 await controller.disable_user(username)
27 result = await controller.get_user(username)
28 res_ser = result.serialize()['results'][0].serialize()
29 assert res_ser['result'].serialize()['disabled'] is True
30 await controller.enable_user(username)
31 result = await controller.get_user(username)
32 res_ser = result.serialize()['results'][0].serialize()
33 assert res_ser['result'].serialize()['disabled'] is False
34
35
36 @base.bootstrapped
37 @pytest.mark.asyncio
38 async def test_change_user_password(event_loop):
39 async with base.CleanController() as controller:
40 username = 'test-password{}'.format(uuid.uuid4())
41 await controller.add_user(username)
42 await controller.change_user_password(username, 'password')
43 try:
44 new_controller = Controller()
45 await new_controller.connect(
46 controller.connection.endpoint, username, 'password')
47 result = True
48 await new_controller.disconnect()
49 except JujuAPIError:
50 result = False
51 assert result is True
52
53
54 @base.bootstrapped
55 @pytest.mark.asyncio
56 async def test_grant(event_loop):
57 async with base.CleanController() as controller:
58 username = 'test-grant{}'.format(uuid.uuid4())
59 await controller.add_user(username)
60 await controller.grant(username, 'superuser')
61 result = await controller.get_user(username)
62 result = result.serialize()['results'][0].serialize()['result']\
63 .serialize()
64 assert result['access'] == 'superuser'
65 await controller.grant(username, 'login')
66 result = await controller.get_user(username)
67 result = result.serialize()['results'][0].serialize()['result']\
68 .serialize()
69 assert result['access'] == 'login'
70
71
72 @base.bootstrapped
73 @pytest.mark.asyncio
74 async def test_get_models(event_loop):
75 async with base.CleanController() as controller:
76 result = await controller.get_models()
77 assert isinstance(result.serialize()['user-models'], list)