forked from SatelliteQE/robottelo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_role.py
More file actions
76 lines (59 loc) · 2.32 KB
/
Copy pathuser_role.py
File metadata and controls
76 lines (59 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from fauxfactory import gen_alphanumeric
import pytest
class UserFactory:
"""Helper class for more complex operations with users that can be reused in fixtures."""
@staticmethod
def create_user(target_sat, **params):
"""Create and return a user object. Set the password if not specified.
Args:
target_sat: Satellite object
params: parameters passed to the User object
Returns:
User object
"""
params.setdefault('password', gen_alphanumeric())
user = target_sat.api.User(**params).create()
user.password = params['password']
return user
@pytest.fixture(scope='session')
def viewer_role(session_target_sat):
"""Viewer role."""
return session_target_sat.api.Role().search(query={'search': 'name="Viewer"'})[0]
@pytest.fixture(scope='class')
def class_user_password():
"""Generate a random password for a user, and capture it so a test has access to it"""
return gen_alphanumeric()
@pytest.fixture
def function_role(target_sat):
return target_sat.api.Role().create()
@pytest.fixture
def function_role_with_org(module_target_sat, module_org):
return module_target_sat.api.Role(organization=[module_org]).create()
@pytest.fixture(scope='module')
def module_user(module_target_sat, module_org, module_location):
return module_target_sat.api.User(
organization=[module_org], location=[module_location]
).create()
@pytest.fixture(scope='module')
def default_viewer_role(module_target_sat, module_org, default_location, viewer_role):
"""Custom user with viewer role for tests validating visibility of entities or fields created
by some other user. Created only when accessed, unlike `module_user`.
"""
return UserFactory.create_user(
target_sat=module_target_sat,
admin=False,
default_organization=module_org,
location=[default_location],
organization=[module_org],
role=[viewer_role],
)
@pytest.fixture(scope='module')
def module_user_viewer(module_target_sat, module_org, module_location, viewer_role):
"""Non-admin user with Viewer role."""
return UserFactory.create_user(
target_sat=module_target_sat,
admin=False,
location=[module_location],
organization=[module_org],
role=[viewer_role],
)