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
Beispiel #2
0
    def test_get_request_user_model(self):
        """Get User Request Model"""

        under_test = User.get_request_model('')

        self.assertTrue('endpoint' in under_test)
        self.assertEqual('user', under_test['endpoint'])
        self.assertTrue('params' in under_test)
        self.assertTrue('projection' in under_test)
    def test_get_request_user_model(self):
        """Get User Request Model"""

        under_test = User.get_request_model('')

        self.assertTrue('endpoint' in under_test)
        self.assertEqual('user', under_test['endpoint'])
        self.assertTrue('params' in under_test)
        self.assertTrue('projection' in 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
Beispiel #5
0
class TestAlignakQWidget(unittest2.TestCase):
    """
        This file test methods of AlignakQWidget class object
    """

    settings.init_config()
    init_localization()
    app_backend.login()

    # User data test
    user = User()
    user_keys = User.get_request_model('test')['projection']
    user_data_test = {}
    for key in user_keys:
        if 'host_notifications_enabled' in key or 'service_notifications_enabled' in key:
            user_data_test[key] = True
        else:
            user_data_test[key] = 'test'
    user.create('_id', user_data_test, 'admin')

    @classmethod
    def setUpClass(cls):
        """Create QApplication"""
        try:
            cls.app = QApplication(sys.argv)
        except:
            pass

    def test_initialize_alignak_qwidget(self):
        """Initialize AlignakQWidget"""

        under_test = AlignakQWidget()

        self.assertIsNotNone(under_test.backend_connected)
        self.assertIsNotNone(under_test.status_btn)
        self.assertIsNotNone(under_test.status_dialog)
        self.assertIsNotNone(under_test.profile_btn)
        self.assertIsNotNone(under_test.profile_widget)
        self.assertFalse(under_test.refresh_timer.isActive())

        self.assertIsInstance(under_test, QWidget)

        data_manager.update_database('user', self.user)
        under_test.initialize()

        self.assertIsNotNone(under_test.backend_connected)
        self.assertIsNotNone(under_test.status_btn)
        self.assertFalse(under_test.status_btn.isEnabled())
        self.assertIsNotNone(under_test.status_dialog)
        self.assertIsNotNone(under_test.profile_btn)
        self.assertIsNotNone(under_test.profile_widget)
        self.assertTrue(under_test.refresh_timer.isActive())

    def test_update_status(self):
        """Update Alignak QWidget"""

        under_test = AlignakQWidget()
        under_test.initialize()

        self.assertFalse(under_test.status_btn.isEnabled())

        daemon_test = Daemon()
        daemon_test.create(
            '_id1',
            {
                'alive': True,
                'address': '127.0.0.1',
                'port': '8888',
                'reachable': True,
                'spare': True,
                'passive': True,
                'last_check': 123456789,
            },
            'arbiter'
        )
        data_manager.update_database('alignakdaemon', [daemon_test])
        under_test.update_status()

        # Status button is enabled when alignakdaemon is filled
        self.assertTrue(under_test.status_btn.isEnabled())