def query_user(self):
        """
        Launch request on "user" endpoint. Only for current App user.

        """

        request_model = User.get_request_model(self.backend.token)

        request = self.get(
            request_model['endpoint'],
            request_model['params'],
            request_model['projection']
        )

        if request:
            if request['_items']:
                user = User()

                user.create(
                    request['_items'][0]['_id'],
                    request['_items'][0],
                    request['_items'][0]['name']
                )

                data_manager.update_database('user', user)

            if 'OK' in request['_status']:
                data_manager.db_is_ready[request_model['endpoint']] = True
Ejemplo n.º 2
0
    def test_get_user_role(self):
        """Get User Role"""

        # User case
        user_test = User()
        user_test.create(
            '_id', {
                'is_admin': False,
                'can_submit_commands': False,
                'back_role_super_admin': False
            }, 'name')
        under_test = user_test.get_role()
        self.assertEqual('user', under_test)

        # Administrator case
        user_test = User()
        user_test.create(
            '_id', {
                'is_admin': True,
                'can_submit_commands': False,
                'back_role_super_admin': False
            }, 'name')
        under_test = user_test.get_role()
        self.assertEqual('administrator', under_test)

        # Power case
        user_test = User()
        user_test.create(
            '_id', {
                'is_admin': False,
                'can_submit_commands': True,
                'back_role_super_admin': False
            }, 'name')
        under_test = user_test.get_role()
        self.assertEqual('power', under_test)
    def test_get_user_role(self):
        """Get User Role"""

        # User case
        user_test = User()
        user_test.create(
            '_id',
            {'is_admin': False, 'can_submit_commands': False, 'back_role_super_admin': False},
            'name'
        )
        under_test = user_test.get_role()
        self.assertEqual('user', under_test)

        # Administrator case
        user_test = User()
        user_test.create(
            '_id',
            {'is_admin': True, 'can_submit_commands': False, 'back_role_super_admin': False},
            'name'
        )
        under_test = user_test.get_role()
        self.assertEqual('administrator', under_test)

        # Power case
        user_test = User()
        user_test.create(
            '_id',
            {'is_admin': False, 'can_submit_commands': True, 'back_role_super_admin': False},
            'name'
        )
        under_test = user_test.get_role()
        self.assertEqual('power', under_test)
    def query_user(self):
        """
        Launch request on "user" endpoint. Only for current App user.

        """

        request_model = User.get_request_model(self.backend.token)

        request = self.get(request_model['endpoint'], request_model['params'],
                           request_model['projection'])

        if request:
            if request['_items']:
                user = User()

                user.create(request['_items'][0]['_id'], request['_items'][0],
                            request['_items'][0]['name'])

                data_manager.update_database('user', user)

            if 'OK' in request['_status']:
                data_manager.db_is_ready[request_model['endpoint']] = True
import unittest2

from PyQt5.Qt import QApplication, Qt

from alignak_app.backend.datamanager import data_manager
from alignak_app.items.host import Host
from alignak_app.items.service import Service
from alignak_app.items.user import User
from alignak_app.utils.config import settings
from alignak_app.locales.locales import init_localization

settings.init_config()
init_localization()
app = QApplication(sys.argv)
user = User()
user.create('_id', {'name': 'name'}, 'name')
data_manager.database['user'] = user

from alignak_app.backend.datamanager import data_manager

from alignak_app.qobjects.service.services import ServicesQWidget


class TestServicesQWidget(unittest2.TestCase):
    """
        This file test methods of ServicesQWidget class object
    """

    # Host data test
    host_list = []
    for i in range(0, 10):
import unittest2

from PyQt5.Qt import QApplication, Qt

from alignak_app.backend.datamanager import data_manager
from alignak_app.items.host import Host
from alignak_app.items.service import Service
from alignak_app.items.user import User
from alignak_app.utils.config import settings
from alignak_app.locales.locales import init_localization

settings.init_config()
init_localization()
app = QApplication(sys.argv)
user = User()
user.create('_id', {'name': 'name'}, 'name')
data_manager.database['user'] = user

from alignak_app.backend.datamanager import data_manager

from alignak_app.qobjects.service.services import ServicesQWidget


class TestServicesQWidget(unittest2.TestCase):
    """
        This file test methods of ServicesQWidget class object
    """

    # Host data test
    host_list = []
    for i in range(0, 10):