Esempio n. 1
0
    def test_create_sqlalchemy_jobstore_config_no_jobstore(self):
        config = SchedulerConfiguration()
        self.assertIsNotNone(config)

        data = {}
        config._create_sqlalchemy_jobstore_config(data)
        self.assertEquals(data['apscheduler.jobstores.sqlalchemy'], {'type': 'sqlalchemy'})
Esempio n. 2
0
    def test_create_threadpool_config_no_config(self):
        config = SchedulerConfiguration()
        self.assertIsNotNone(config)

        data = {}
        config._create_threadpool_config(data)
        self.assertEquals(data['apscheduler.executors.default'], {'class': 'apscheduler.executors.pool:ThreadPoolExecutor'})
Esempio n. 3
0
    def test_create_scheduler_config_unknown(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        console:
          scheduler:
            name: Scheduler1
            debug_level: 0
            add_listeners: True
            remove_all_jobs: True

            jobstore:
                name:   unknown

            threadpool:
                max_workers: 20

            processpool:
                max_workers: 5   

            job_defaults:
                coalesce: False
                max_instances: 3

        """, ConsoleConfiguration(), ".")

        console_config = yaml.get_section("console")

        scheduler_config = SchedulerConfiguration()
        scheduler_config.load_config_section(yaml, console_config, ".")

        config = scheduler_config.create_scheduler_config()
        self.assertIsNotNone(config)
Esempio n. 4
0
    def test_create_processpool_config_no_config(self):
        config = SchedulerConfiguration()
        self.assertIsNotNone(config)

        data = {}
        config._create_processpool_config(data)
        self.assertEquals(data['apscheduler.executors.processpool'],  {'type': 'processpool'})
Esempio n. 5
0
    def test_create_mongo_jobstore_config_no_jobstore(self):
        config = SchedulerConfiguration()
        self.assertIsNotNone(config)

        data = {}
        config._create_mongo_jobstore_config(data)
        self.assertEquals(data['apscheduler.jobstores.mongo'], {'type': 'mongodb'})
Esempio n. 6
0
    def test_create_job_defaults_config_no_config(self):
        config = SchedulerConfiguration()
        self.assertIsNotNone(config)

        data = {}
        config._create_job_defaults_config(data)
        self.assertEquals(data['apscheduler.job_defaults'],  {})
Esempio n. 7
0
    def test_with_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        console:
          scheduler:
            name: Scheduler1
            debug_level: 0
            add_listeners: True
            remove_all_jobs: True
            
            jobstore:
                name:   mongo
                
                mongo:
                    collection: example_jobs
    
                redis:
                    jobs_key: example.jobs
                    run_times_key: example.run_times
    
                sqlalchemy:
                    url: sqlite:///jobs.sqlite
    
            threadpool:
                max_workers: 20
        
            processpool:
                max_workers: 5   
        
            job_defaults:
                coalesce: False
                max_instances: 3
          
        """, ConsoleConfiguration(), ".")

        console_config = yaml.get_section("console")

        scheduler_config = SchedulerConfiguration()
        scheduler_config.load_config_section(yaml, console_config, ".")

        self.assertEqual("Scheduler1", scheduler_config.name)
        self.assertEqual(0, scheduler_config.debug_level)
        self.assertTrue(scheduler_config.add_listeners)
        self.assertTrue(scheduler_config.remove_all_jobs)

        self.assertIsNotNone(scheduler_config.jobstore)
        self.assertIsNotNone(scheduler_config.jobstore.storage)
        self.assertEqual("example_jobs", scheduler_config.jobstore.storage.collection)

        self.assertIsNotNone(scheduler_config.threadpool)
        self.assertEqual(20, scheduler_config.threadpool.max_workers)

        self.assertIsNotNone(scheduler_config.processpool)
        self.assertEqual(5, scheduler_config.processpool.max_workers)

        self.assertIsNotNone(scheduler_config.job_defaults)
        self.assertEqual(False, scheduler_config.job_defaults.coalesce)
        self.assertEqual(3, scheduler_config.job_defaults.max_instances)
Esempio n. 8
0
    def test_create_scheduler_no_blocking(self):
        config = SchedulerConfiguration()
        config._blocking = False

        self.assertIsNotNone(config)
        scheduler = ProgramyScheduler(self._test_client, config)
        self.assertIsNotNone(scheduler)
        self.assertIsInstance(scheduler._scheduler, BackgroundScheduler)
Esempio n. 9
0
    def test_init_custom_config(self):
        config = SchedulerConfiguration()
        config._debug_level = logging.DEBUG
        config._add_listeners = True

        self.assertIsNotNone(config)
        scheduler = ProgramyScheduler(self._test_client, config)
        self.assertIsNotNone(scheduler)
        self.assertIsInstance(scheduler._scheduler, BackgroundScheduler)
Esempio n. 10
0
 def __init__(self, name):
     BaseContainerConfigurationData.__init__(self, name)
     self._description = 'ProgramY AIML2.0 Client'
     self._bot_configs = []
     self._bot_configs.append(BotConfiguration("bot"))
     self._bot_selector = None
     self._scheduler = SchedulerConfiguration()
     self._storage = StorageConfiguration()
     self._renderer = None
Esempio n. 11
0
    def test_create_threadpool_config(self):
        config = SchedulerConfiguration()
        self.assertIsNotNone(config)

        config._threadpool = SchedulerThreadPoolConfiguration()
        config._threadpool._max_workers = 3

        data = {}
        config._create_threadpool_config(data)
        self.assertEquals(data['apscheduler.executors.default'], {'class': 'apscheduler.executors.pool:ThreadPoolExecutor', 'max_workers': '3'})
Esempio n. 12
0
    def test_create_processpool_config(self):
        config = SchedulerConfiguration()
        self.assertIsNotNone(config)

        config._processpool = SchedulerProcessPoolConfiguration()
        config._processpool._max_workers = 3

        data = {}
        config._create_processpool_config(data)
        self.assertEquals(data['apscheduler.executors.processpool'],  {'max_workers': '3', 'type': 'processpool'})
Esempio n. 13
0
    def test_create_mongo_jobstore_config_no_storage_collection(self):
        config = SchedulerConfiguration()
        self.assertIsNotNone(config)

        config._jobstore = SchedulerJobStoreConfiguration()
        config._jobstore._name = "mongo"

        data = {}
        config._create_mongo_jobstore_config(data)
        self.assertEquals(data['apscheduler.jobstores.mongo'], {'type': 'mongodb'})
Esempio n. 14
0
    def test_create_redis_jobstore_config_no_storage(self):
        config = SchedulerConfiguration()
        self.assertIsNotNone(config)

        config._jobstore = SchedulerJobStoreConfiguration()
        config._jobstore._name = "redis"

        data = {}
        config._create_redis_jobstore_config(data)
        self.assertEquals(data['apscheduler.jobstores.redis'], {'type': 'redis'})
Esempio n. 15
0
    def test_create_sqlalchemy_jobstore_config_no_storage(self):
        config = SchedulerConfiguration()
        self.assertIsNotNone(config)

        config._jobstore = SchedulerJobStoreConfiguration()
        config._jobstore._name = "sqlalchemy"

        data = {}
        config._create_sqlalchemy_jobstore_config(data)
        self.assertEquals(data['apscheduler.jobstores.sqlalchemy'], {'type': 'sqlalchemy'})
Esempio n. 16
0
    def test_create_job_defaults_config(self):
        config = SchedulerConfiguration()
        self.assertIsNotNone(config)

        config._job_defaults = SchedulerJobDefaultsConfiguration()
        config._job_defaults._coalesce = 1
        config._job_defaults._max_instances = 3

        data = {}
        config._create_job_defaults_config(data)
        self.assertEquals(data['apscheduler.job_defaults'],  {'coalesce': '1', 'max_instances': '3'})
Esempio n. 17
0
    def test_create_sqlalchemy_storage_config(self):
        config = SchedulerConfiguration()
        self.assertIsNotNone(config)

        config._jobstore = SchedulerJobStoreConfiguration()
        config._jobstore._name = "sqlalchemy"
        config._jobstore._storage = SchedulerSqlAlchemyJobStoreConfiguration()
        config._jobstore._storage._url = "sqlite://programy"

        data = {}
        config._create_sqlalchemy_jobstore_config(data)
        self.assertEquals(data['apscheduler.jobstores.sqlalchemy'], {'type': 'sqlalchemy', 'url': 'sqlite://programy'})
Esempio n. 18
0
    def test_create_scheduler_blocking_with_jobstore(self):
        config = SchedulerConfiguration()
        config._blocking = True

        config._jobstore = SchedulerJobStoreConfiguration()
        config._jobstore._name = "sqlalchemy"
        config._jobstore._storage = SchedulerSqlAlchemyJobStoreConfiguration()
        config._jobstore._storage._url = "sqlite:///programy.sqlite"

        scheduler = ProgramyScheduler(self._test_client, config)
        self.assertIsNotNone(scheduler)
        self.assertIsInstance(scheduler._scheduler, BlockingScheduler)
Esempio n. 19
0
    def test_create_redis_storage_config(self):
        config = SchedulerConfiguration()
        self.assertIsNotNone(config)

        config._jobstore = SchedulerJobStoreConfiguration()
        config._jobstore._name = "redis"
        config._jobstore._storage = SchedulerRedisJobStoreConfiguration()
        config._jobstore._storage._jobs_key = "job"
        config._jobstore._storage._run_times_key = "runtime"

        data = {}
        config._create_redis_jobstore_config(data)
        self.assertEquals(data['apscheduler.jobstores.redis'], {'jobs_key': 'job', 'run_times_key': 'runtime', 'type': 'redis'})
Esempio n. 20
0
    def __init__(self, name):
        BaseContainerConfigurationData.__init__(self, name)
        self._description = 'ProgramY AIML2.0 Client'
        self._renderer = self._get_renderer_class()
        self._scheduler = SchedulerConfiguration()
        self._storage = StorageConfiguration()
        self._email = EmailConfiguration()
        self._triggers = TriggerConfiguration()
        self._responder = PingResponderConfig()

        self._bot_selector = self._get_bot_selector_class()
        bot_config = BotConfiguration('bot')
        self._bot_configs = [bot_config]
Esempio n. 21
0
    def test_scheduler_listener(self):
        config = SchedulerConfiguration()
        self.assertIsNotNone(config)
        scheduler = ProgramyScheduler(self._test_client, config)
        self.assertIsNotNone(scheduler)

        scheduler_listener(JobExecutionEvent(apscheduler.events.EVENT_SCHEDULER_STARTED, 1, None, None))
Esempio n. 22
0
    def test_scheduler_listener_unknown_event(self):
        config = SchedulerConfiguration()
        self.assertIsNotNone(config)
        scheduler = ProgramyScheduler(self._test_client, config)
        self.assertIsNotNone(scheduler)

        scheduler_listener(JobExecutionEvent(-1, 1, None, None))
Esempio n. 23
0
    def test_with_no_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        bot:
        """, ConsoleConfiguration(), ".")

        console_config = yaml.get_section("console")

        scheduler_config = SchedulerConfiguration()
        scheduler_config.load_config_section(yaml, console_config, ".")

        self.assertIsNone(scheduler_config.name)
        self.assertEqual(0, scheduler_config.debug_level)
        self.assertFalse(scheduler_config.add_listeners)
        self.assertFalse(scheduler_config.remove_all_jobs)

        self.assertIsNone(scheduler_config.jobstore)
        self.assertIsNone(scheduler_config.threadpool)
        self.assertIsNone(scheduler_config.processpool)
        self.assertIsNone(scheduler_config.job_defaults)
Esempio n. 24
0
class ClientConfigurationData(BaseContainerConfigurationData):
    def __init__(self, name):
        BaseContainerConfigurationData.__init__(self, name)
        self._description = 'ProgramY AIML2.0 Client'
        self._bot_configs = []
        self._bot_configs.append(BotConfiguration("bot"))
        self._bot_selector = None
        self._renderer = None
        self._scheduler = SchedulerConfiguration()
        self._storage = StorageConfiguration()
        self._email = EmailConfiguration()
        self._triggers = TriggerConfiguration()

    @property
    def description(self):
        return self._description

    @property
    def configurations(self):
        return self._bot_configs

    @property
    def bot_selector(self):
        return self._bot_selector

    @property
    def scheduler(self):
        return self._scheduler

    @property
    def storage(self):
        return self._storage

    @property
    def renderer(self):
        return self._renderer

    @property
    def email(self):
        return self._email

    @property
    def triggers(self):
        return self._triggers

    def check_for_license_keys(self, license_keys):
        BaseContainerConfigurationData.check_for_license_keys(
            self, license_keys)

    def load_configuration(self,
                           configuration_file,
                           bot_root,
                           subs: Substitutions = None):
        client = configuration_file.get_section(self.section_name)
        if client is None:
            YLogger.error(
                None, 'Client section named [%s] not found, trying "client"',
                self.section_name)
            client = configuration_file.get_section('client')

        if client is not None:
            self.load_configuration_section(configuration_file, client,
                                            bot_root, subs)
        else:
            YLogger.error(None, 'No client section not found!')

    def load_configuration_section(self,
                                   configuration_file,
                                   section,
                                   bot_root,
                                   subs: Substitutions = None):

        assert (configuration_file is not None)

        if section is not None:
            self._description = configuration_file.get_option(
                section,
                "description",
                missing_value='ProgramY AIML2.0 Client',
                subs=subs)

            bot_names = configuration_file.get_multi_option(
                section, "bot", missing_value="bot", subs=subs)
            first = True
            for name in bot_names:
                if first is True:
                    config = self._bot_configs[0]
                    first = False

                else:
                    config = BotConfiguration(name)
                    self._bot_configs.append(config)

                config.load_configuration(configuration_file,
                                          bot_root,
                                          subs=subs)

            self._bot_selector = configuration_file.get_option(
                section,
                "bot_selector",
                missing_value="programy.clients.client.DefaultBotSelector",
                subs=subs)

            self._scheduler.load_config_section(configuration_file,
                                                section,
                                                bot_root,
                                                subs=subs)

            self._storage.load_config_section(configuration_file,
                                              section,
                                              bot_root,
                                              subs=subs)

            self._renderer = configuration_file.get_option(section,
                                                           "renderer",
                                                           subs=subs)

            self._email.load_config_section(configuration_file,
                                            section,
                                            bot_root,
                                            subs=subs)

            self._triggers.load_config_section(configuration_file,
                                               section,
                                               bot_root,
                                               subs=subs)

        else:
            YLogger.warning(
                self,
                "No bot name defined for client [%s], defaulting to 'bot'.",
                self.section_name)
            self._bot_configs[0]._section_name = "bot"
            self._bot_configs[0].load_configuration(configuration_file,
                                                    bot_root,
                                                    subs=subs)

    def to_yaml(self, data, defaults=True):

        assert (data is not None)

        if defaults is True:
            data['description'] = 'ProgramY AIML2.0 Client'
            data['bot'] = 'bot'
            data['bot_selector'] = "programy.clients.client.DefaultBotSelector"
            data['renderer'] = "programy.clients.render.text.TextRenderer"
        else:
            data['description'] = self._description
            data['bot'] = self._bot_configs[0].id
            data['bot_selector'] = self.bot_selector
            data['renderer'] = self.renderer

        data[self._scheduler.id] = {}
        self._scheduler.to_yaml(data[self._scheduler.id], defaults)

        data['email'] = {}
        self._email.to_yaml(data['email'], defaults)

        data['triggers'] = {}
        self._triggers.to_yaml(data['triggers'], defaults)
Esempio n. 25
0
    def test_defaults(self):
        config = SchedulerConfiguration()
        data = {}
        config.to_yaml(data, True)

        SchedulerConfigurationTests.assert_defaults(self, data)
Esempio n. 26
0
 def test_init_default_config(self):
     config = SchedulerConfiguration()
     self.assertIsNotNone(config)
     scheduler = ProgramyScheduler(self._test_client, config)
     self.assertIsNotNone(scheduler)
     self.assertIsInstance(scheduler._scheduler, BackgroundScheduler)
Esempio n. 27
0
 def test_scheduled_text(self):
     client = MockClient()
     scheduler1 = ProgramyScheduler(client, SchedulerConfiguration())
     scheduler1.scheduled("user1", "client1", "TEXT", "Hello")
     self.assertEquals("Hello", client._response)
Esempio n. 28
0
 def test_scheduled_srai(self):
     client = MockClient()
     scheduler1 = ProgramyScheduler(client, SchedulerConfiguration())
     scheduler1.scheduled("user1", "client1", "SRAI", "Hello")
     self.assertEquals("Mock Response", client._response)
Esempio n. 29
0
 def test_scheduled_unknown(self):
     client = MockClient()
     scheduler1 = ProgramyScheduler(client, SchedulerConfiguration())
     scheduler1.scheduled("user1", "client1", "UNKNOWN", "Hello")
     self.assertIsNone(client._response)
Esempio n. 30
0
class ClientConfigurationData(BaseContainerConfigurationData):

    def __init__(self, name):
        BaseContainerConfigurationData.__init__(self, name)
        self._description = 'ProgramY AIML2.0 Client'
        self._bot_configs = []
        self._bot_configs.append(BotConfiguration("bot"))
        self._bot_selector = None
        self._scheduler = SchedulerConfiguration()
        self._storage = StorageConfiguration()
        self._renderer = None

    @property
    def description(self):
        return self._description

    @property
    def configurations(self):
        return self._bot_configs

    @property
    def bot_selector(self):
        return self._bot_selector

    @property
    def scheduler(self):
        return self._scheduler

    @property
    def storage(self):
        return self._storage

    @property
    def renderer(self):
        return self._renderer

    def load_configuration(self, configuration_file, section, bot_root):

        assert(configuration_file is not None)

        if section is not None:
            self._description = configuration_file.get_option(section, "description", missing_value='ProgramY AIML2.0 Client')

            bot_names = configuration_file.get_multi_option(section, "bot", missing_value="bot")
            first = True
            for name in bot_names:
                if first is True:
                    config = self._bot_configs[0]
                    first = False
                else:
                    config = BotConfiguration(name)
                    self._bot_configs.append(config)
                config.load_configuration(configuration_file, bot_root)

            self._bot_selector = configuration_file.get_option(section, "bot_selector", missing_value="programy.clients.client.DefaultBotSelector")

            self._scheduler.load_config_section(configuration_file, section, bot_root)

            self._storage.load_config_section(configuration_file, section, bot_root)

            self._renderer = configuration_file.get_option(section, "renderer")

        else:
            YLogger.warning(self, "No bot name defined for client [%s], defaulting to 'bot'.", self.section_name)
            self._bot_configs[0]._section_name = "bot"
            self._bot_configs[0].load_configuration(configuration_file, bot_root)

    def to_yaml(self, data, defaults=True):

        assert (data is not None)

        if defaults is True:
            data['description'] = 'ProgramY AIML2.0 Client'
            data['bot'] = 'bot'
            data['bot_selector'] = "programy.clients.client.DefaultBotSelector"

            data[self._scheduler.id] = {}
            self._scheduler.to_yaml(data[self._scheduler.id], defaults)


            data['renderer'] = "programy.clients.render.text.TextRenderer"

        else:
            data['description'] = self._description
            data['bot'] = self._bot_configs[0].id
            data['bot_selector'] = self.bot_selector

            data[self._scheduler.id] = {}
            self._scheduler.to_yaml(data[self._scheduler.id], defaults)

            data['renderer'] = self.renderer