Exemple #1
0
    def test_realname_queue(self):
        """ Should return the same name if not rename"""
        os.environ["QPANEL_CONFIG_FILE"] = os.path.join(
            self.configs_dir, 'config_default.ini')

        configuration = config.QPanelConfig()
        self.assertEqual(configuration.realname_queue("s_cl"), "s_cl")
Exemple #2
0
    def test_sample_file_configuration(self):
        os.environ["QPANEL_CONFIG_FILE"] = os.path.join(
            self.configs_dir, os.pardir, os.pardir, os.pardir, 'samples',
            'config.ini-dist')

        configuration = config.QPanelConfig()
        self.assertEqual(configuration.port_bind, 5000)
Exemple #3
0
def exists_job_onconfig(queuename, when, hour):
    """ Check if the params for configuration is present for reset_stats"""
    queues_for_reset = config.QPanelConfig().queues_for_reset_stats()
    entry = queues_for_reset.get(queuename)
    if entry and entry['when'] == when and entry['hour'] == hour:
        return True
    return False
Exemple #4
0
 def test_user_queues_without_section(self):
     os.environ["QPANEL_CONFIG_FILE"] = os.path.join(
         self.configs_dir, 'user_queues', 'no-section.ini')
     configuration = config.QPanelConfig()
     self.assertFalse(configuration.has_user_queues())
     self.assertEqual(configuration.queue_enables_for_username('nobody'),
                      [])
     self.assertTrue(
         configuration.enable_queue_for_user('nobody', 'testing'))
Exemple #5
0
 def test_use_config_ini_default(self):
     """
         This test only run if the config.ini in the root path
         is not present.
         This create a new file in this directory and test the
         configuration file.
     """
     if os.path.isfile(self.default_file_config) is False:
         file_sample = os.path.join(self.configs_dir, 'config_default.ini')
         copyfile(file_sample, self.default_file_config)
         configuration = config.QPanelConfig()
         os.remove(self.default_file_config)
         self.assertEqual(configuration.port_bind, 5010)
Exemple #6
0
def reset_stats_queue(queuename, when, hour):
    '''
        Reset stat for a queue on backend
        queuename: Name of queue to reset
        when, hour parameters for more easy
               control for exists_job_onconfig
    '''
    if not exists_job_onconfig(queuename, when, hour):
        return False
    cfg = config.QPanelConfig()
    b = backend.Backend()
    b.reset_stats(cfg.realname_queue(queuename))
    return True
Exemple #7
0
 def test_user_queues_with_config(self):
     os.environ["QPANEL_CONFIG_FILE"] = os.path.join(
         self.configs_dir, 'user_queues', 'section-with-config.ini')
     configuration = config.QPanelConfig()
     self.assertTrue(configuration.has_user_queues())
     self.assertEqual(len(configuration.get_items('user_queues')), 2)
     self.assertEqual(configuration.queue_enables_for_username('rodrigo'),
                      ['support', 'commercial'])
     self.assertEqual(configuration.queue_enables_for_username('ramirez'),
                      ['agents'])
     self.assertEqual(configuration.queue_enables_for_username('nobody'),
                      [])
     self.assertTrue(
         configuration.enable_queue_for_user('rodrigo', 'support'))
     self.assertFalse(
         configuration.enable_queue_for_user('nobody', 'testing'))
Exemple #8
0
def remove_jobs_not_config():
    """
        Remove jobs on queue but not present on config.
        Prevent when in job for reset a queue stats is scheduled but
        after your config is modified or deleted
    """
    scheduler = Scheduler(connection=Redis())
    queue_for_reset = config.QPanelConfig().queues_for_reset_stats()
    jobs = scheduler.get_jobs()
    for job in jobs:
        if 'reset_stats_queue' in job.func_name:
            delete = True
            for qr in queue_for_reset:
                if qr in queue_for_reset:
                    if (queue_for_reset[qr]['when'] == job.args[1]
                            and queue_for_reset[qr]['hour'] == job.args[2]):
                        delete = False
                if delete:
                    job.delete()
Exemple #9
0
# -*- coding: utf-8 -*-

#
# Copyright (C) 2015-2020 Rodrigo Ramírez Norambuena <*****@*****.**>
#

from qpanel import config, job, rq_worker

if __name__ == '__main__':
    """
        Simple program to run worker for reset stats of Queue

        If you are running the QPanel using a uwsgi script should use
        this script to run background process will be reset stats for
        the queues

        see samples/resetstats_supervisor.conf
    """

    cfg = config.QPanelConfig()

    if cfg.queues_for_reset_stats():
        if job.check_connect_redis():
            rq_worker.start_jobs()
        else:
            print("Error: There not connection to Redis")
            print("       Reset stats will not work\n")
Exemple #10
0
def enqueue_reset_stats():
    queues_for_reset = config.QPanelConfig().queues_for_reset_stats()
    for queue, val in queues_for_reset.items():
        job_reset_stats_queue(queue, val['when'], val['hour'])
Exemple #11
0
 def test_wrong_theme_config(self):
     os.environ["QPANEL_CONFIG_FILE"] = os.path.join(
         self.configs_dir, 'config_wrong_theme.ini')
     configuration = config.QPanelConfig()
     self.assertEqual(configuration.theme, 'qpanel')
Exemple #12
0
 def test_has_no_section(self):
     os.environ["QPANEL_CONFIG_FILE"] = os.path.join(
         self.configs_dir, 'config_default.ini')
     configuration = config.QPanelConfig()
     self.assertEqual(configuration.has_section('general_not_found'), False)
Exemple #13
0
 def test_configuration_without_fileconfig(self):
     if ('CI' in os.environ
             or os.path.isfile(self.default_file_config) is False):
         with self.assertRaises(config.NotConfigFileQPanel):
             config.QPanelConfig()
Exemple #14
0
 def test_configuration_file_enviroment_variable_not_found(self):
     os.environ["QPANEL_CONFIG_FILE"] = os.path.join(
         self.configs_dir, 'config_no_found')
     with self.assertRaises(config.NotConfigFileQPanel):
         config.QPanelConfig()
Exemple #15
0
 def test_configuration_file_enviroment_variable(self):
     os.environ["QPANEL_CONFIG_FILE"] = os.path.join(
         self.configs_dir, 'config_default.ini')
     configuration = config.QPanelConfig()
     self.assertEqual(configuration.port_bind, 5010)