# Path: tenable_io/api/models.py
# class Permissions(BaseModel):
# 
#     class Scan:
#         # Scan Permissions
#         PERMISSION_NO_ACCESS = 0
#         PERMISSION_CAN_VIEW = 16
#         PERMISSION_CAN_CONTROL = 32
#         PERMISSION_CAN_CONFIGURE = 64
# 
#     class Policy:
#         # Policy Permissions
#         PERMISSION_NO_ACCESS = 0
#         PERMISSION_CAN_USE = 16
#         PERMISSION_CAN_EDIT = 32
# 
#     class Scanner:
#         # Scanner Permissions
#         PERMISSION_NO_ACCESS = 0
#         PERMISSION_CAN_USE = 16
#         PERMISSION_CAN_MANAGE = 32
# 
#     class Agent:
#         # Agent Permissions
#         PERMISSION_NO_ACCESS = 0
#         PERMISSION_CAN_USE = 16
# 
#     class TargetGroup:
#         # Target Group Permissions
#         PERMISSION_NO_ACCESS = 0
#         PERMISSION_CAN_VIEW = 32
#         PERMISSION_CAN_SCAN = 64
# 
#     class User:
#         # User Roles
#         PERMISSION_BASIC = 16
#         PERMISSION_SCAN_OPERATOR = 24
#         PERMISSION_STANDARD = 32
#         PERMISSION_SCAN_MANAGER = 40
#         PERMISSION_ADMINISTRATOR = 64
# 
#     class Type:
#         # Types of Permissible entity
#         DEFAULT = u'default'
#         USER = u'user'
#         GROUP = u'group'
# 
#     def __init__(
#             self,
#             owner=None,
#             type=None,
#             permissions=None,
#             id=None,
#             name=None,
#     ):
#         self.owner = owner
#         self.type = type
#         self.permissions = permissions
#         self.id = id
#         self.name = name
# 
# class User:
#     # User Roles
#     PERMISSION_BASIC = 16
#     PERMISSION_SCAN_OPERATOR = 24
#     PERMISSION_STANDARD = 32
#     PERMISSION_SCAN_MANAGER = 40
#     PERMISSION_ADMINISTRATOR = 64
# 
# class UserKeys(BaseModel):
# 
#     def __init__(
#             self,
#             access_key=None,
#             secret_key=None,
#     ):
#         self.access_key = access_key
#         self.secret_key = secret_key
# 
#     @classmethod
#     def from_dict(cls, dict_):
#         # Because API uses camelCase for some reason; normalize to underscore here.
#         if 'accessKey' in dict_:
#             dict_['access_key'] = dict_.pop('accessKey')
#         if 'secretKey' in dict_:
#             dict_['secret_key'] = dict_.pop('secretKey')
#         return super(UserKeys, cls).from_dict(dict_)
# 
#     def as_payload(self, filter_=None):
#         # Because API uses camelCase for some reason; normalize to underscore here.
#         payload = self.as_payload(filter_)
#         if 'access_key' in payload:
#             payload['accessKey'] = payload.pop('access_key')
#         if 'secret_key' in payload:
#             payload['secretKey'] = payload.pop('secret_key')
#         return payload
# 
# class UserList(BaseModel):
# 
#     def __init__(
#             self,
#             users=None,
#     ):
#         self._users = None
#         self.users = users
# 
#     @property
#     def users(self):
#         return self._users
# 
#     @users.setter
#     @BaseModel._model_list(User)
#     def users(self, users):
#         self._users = users
# 
# class UserAuthorizations(BaseModel):
# 
#     def __init__(
#             self,
#             account_uuid=None,
#             user_uuid=None,
#             api_permitted=None,
#             password_permitted=None,
#             saml_permitted=None
#     ):
#         self.account_uuid = account_uuid
#         self.user_uuid = user_uuid
#         self.api_permitted = api_permitted
#         self.password_permitted = password_permitted
#         self.saml_permitted = saml_permitted
# 
# Path: tenable_io/api/users.py
# class UserCreateRequest(BaseRequest):
# 
#     def __init__(
#             self,
#             username=None,
#             password=None,
#             permissions=None,
#             name=None,
#             email=None,
#             type=None
#     ):
#         self.username = username
#         self.password = password
#         self.permissions = permissions
#         self.name = name
#         self.email = email
#         self.type = type
# 
# class UserEditRequest(BaseRequest):
# 
#     def __init__(
#             self,
#             permissions=None,
#             name=None,
#             email=None
#     ):
#         self.permissions = permissions
#         self.name = name
#         self.email = email
# 
# class UserAuthorizationsRequest(BaseRequest):
# 
#     def __init__(
#             self,
#             api_permitted=None,
#             password_permitted=None,
#             saml_permitted=None
#     ):
#         self.api_permitted = api_permitted
#         self.password_permitted = password_permitted
#         self.saml_permitted = saml_permitted
# 
# Path: tests/config.py
# class TenableIOTestConfig(object):
# 
#     @staticmethod
#     def get(key):
#         return config.get('tenable_io-test', key)


import pytest
from random import randint
from tenable_io.api.models import Permissions, User, UserKeys, UserList, UserAuthorizations
from tenable_io.api.users import UserCreateRequest, UserEditRequest, UserAuthorizationsRequest
from tests.config import TenableIOTestConfig




def create_user(client, role):
    return client.users_api.create(UserCreateRequest(
        username='test_user_{}_{}@{}'.format(role, randint(0, 10000), TenableIOTestConfig.get('users_domain_name')),
        name='test_users',
        password='Sdk!Test1',
        permissions="{}".format(get_permission(role)),
        type='local',
        email='test_user_{}_{}@{}'.format(role, randint(0, 10000), TenableIOTestConfig.get('users_domain_name'))
    ))


def get_permission(role):
    if role == 'admin':
        return Permissions.User.PERMISSION_ADMINISTRATOR
    elif role == 'scan_manager':

# Path: tenable_io/api/models.py
# class Permissions(BaseModel):
# 
#     class Scan:
#         # Scan Permissions
#         PERMISSION_NO_ACCESS = 0
#         PERMISSION_CAN_VIEW = 16
#         PERMISSION_CAN_CONTROL = 32
#         PERMISSION_CAN_CONFIGURE = 64
# 
#     class Policy:
#         # Policy Permissions
#         PERMISSION_NO_ACCESS = 0
#         PERMISSION_CAN_USE = 16
#         PERMISSION_CAN_EDIT = 32
# 
#     class Scanner:
#         # Scanner Permissions
#         PERMISSION_NO_ACCESS = 0
#         PERMISSION_CAN_USE = 16
#         PERMISSION_CAN_MANAGE = 32
# 
#     class Agent:
#         # Agent Permissions
#         PERMISSION_NO_ACCESS = 0
#         PERMISSION_CAN_USE = 16
# 
#     class TargetGroup:
#         # Target Group Permissions
#         PERMISSION_NO_ACCESS = 0
#         PERMISSION_CAN_VIEW = 32
#         PERMISSION_CAN_SCAN = 64
# 
#     class User:
#         # User Roles
#         PERMISSION_BASIC = 16
#         PERMISSION_SCAN_OPERATOR = 24
#         PERMISSION_STANDARD = 32
#         PERMISSION_SCAN_MANAGER = 40
#         PERMISSION_ADMINISTRATOR = 64
# 
#     class Type:
#         # Types of Permissible entity
#         DEFAULT = u'default'
#         USER = u'user'
#         GROUP = u'group'
# 
#     def __init__(
#             self,
#             owner=None,
#             type=None,
#             permissions=None,
#             id=None,
#             name=None,
#     ):
#         self.owner = owner
#         self.type = type
#         self.permissions = permissions
#         self.id = id
#         self.name = name
# 
# class User:
#     # User Roles
#     PERMISSION_BASIC = 16
#     PERMISSION_SCAN_OPERATOR = 24
#     PERMISSION_STANDARD = 32
#     PERMISSION_SCAN_MANAGER = 40
#     PERMISSION_ADMINISTRATOR = 64
# 
# class UserKeys(BaseModel):
# 
#     def __init__(
#             self,
#             access_key=None,
#             secret_key=None,
#     ):
#         self.access_key = access_key
#         self.secret_key = secret_key
# 
#     @classmethod
#     def from_dict(cls, dict_):
#         # Because API uses camelCase for some reason; normalize to underscore here.
#         if 'accessKey' in dict_:
#             dict_['access_key'] = dict_.pop('accessKey')
#         if 'secretKey' in dict_:
#             dict_['secret_key'] = dict_.pop('secretKey')
#         return super(UserKeys, cls).from_dict(dict_)
# 
#     def as_payload(self, filter_=None):
#         # Because API uses camelCase for some reason; normalize to underscore here.
#         payload = self.as_payload(filter_)
#         if 'access_key' in payload:
#             payload['accessKey'] = payload.pop('access_key')
#         if 'secret_key' in payload:
#             payload['secretKey'] = payload.pop('secret_key')
#         return payload
# 
# class UserList(BaseModel):
# 
#     def __init__(
#             self,
#             users=None,
#     ):
#         self._users = None
#         self.users = users
# 
#     @property
#     def users(self):
#         return self._users
# 
#     @users.setter
#     @BaseModel._model_list(User)
#     def users(self, users):
#         self._users = users
# 
# class UserAuthorizations(BaseModel):
# 
#     def __init__(
#             self,
#             account_uuid=None,
#             user_uuid=None,
#             api_permitted=None,
#             password_permitted=None,
#             saml_permitted=None
#     ):
#         self.account_uuid = account_uuid
#         self.user_uuid = user_uuid
#         self.api_permitted = api_permitted
#         self.password_permitted = password_permitted
#         self.saml_permitted = saml_permitted
# 
# Path: tenable_io/api/users.py
# class UserCreateRequest(BaseRequest):
# 
#     def __init__(
#             self,
#             username=None,
#             password=None,
#             permissions=None,
#             name=None,
#             email=None,
#             type=None
#     ):
#         self.username = username
#         self.password = password
#         self.permissions = permissions
#         self.name = name
#         self.email = email
#         self.type = type
# 
# class UserEditRequest(BaseRequest):
# 
#     def __init__(
#             self,
#             permissions=None,
#             name=None,
#             email=None
#     ):
#         self.permissions = permissions
#         self.name = name
#         self.email = email
# 
# class UserAuthorizationsRequest(BaseRequest):
# 
#     def __init__(
#             self,
#             api_permitted=None,
#             password_permitted=None,
#             saml_permitted=None
#     ):
#         self.api_permitted = api_permitted
#         self.password_permitted = password_permitted
#         self.saml_permitted = saml_permitted
# 
# Path: tests/config.py
# class TenableIOTestConfig(object):
# 
#     @staticmethod
#     def get(key):
#         return config.get('tenable_io-test', key)


# Path: tests/integration/api/test_users.py
import pytest
from random import randint
from tenable_io.api.models import Permissions, User, UserKeys, UserList, UserAuthorizations
from tenable_io.api.users import UserCreateRequest, UserEditRequest, UserAuthorizationsRequest
from tests.config import TenableIOTestConfig





def create_user(client, role):
    return client.users_api.create(UserCreateRequest(
        username='test_user_{}_{}@{}'.format(role, randint(0, 10000), TenableIOTestConfig.get('users_domain_name')),
        name='test_users',
        password='Sdk!Test1',
        permissions="{}".format(get_permission(role)),
        type='local',
        email='test_user_{}_{}@{}'.format(role, randint(0, 10000), TenableIOTestConfig.get('users_domain_name'))
    ))


def get_permission(role):
    if role == 'admin':
        return Permissions.User.PERMISSION_ADMINISTRATOR
    elif role == 'scan_manager':

        return Permissions.User.PERMISSION_SCAN_MANAGER