Ejemplo n.º 1
0
    def get_config_by_name(cls, file_format):
        file_format = file_format.lower()

        if file_format == 'yaml':
            return YamlConfigurationFile()
        elif file_format == 'json':
            return JSONConfigurationFile()
        elif file_format == 'xml':
            return XMLConfigurationFile()
        else:
            raise Exception("Unsupported configuration format:", file_format)
Ejemplo n.º 2
0
    def test_oob_processing(self):

        yaml = YamlConfigurationFile()
        self.load_os_specific_configuration(yaml, "test_brain.yaml", "test_brain.windows.yaml")

        brain_config = BrainConfiguration()
        brain_config.load_config_section(yaml, ".")

        brain = Brain(brain_config)

        self.assertEqual("", brain.process_oob(None, "console", "<oob></oob>"))
Ejemplo n.º 3
0
    def test_with_no_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        brain:
        """, ConsoleConfiguration(), ".")

        brain_config = yaml.get_section("brain")

        dynamic_config = BrainDynamicsConfiguration()
        dynamic_config.load_config_section(yaml, brain_config, ".")
Ejemplo n.º 4
0
    def test_with_no_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        bot:
        """, ConsoleConfiguration(), ".")

        bot_config = yaml.get_section("bot")

        splitter_config = BotSentenceSplitterConfiguration()
        splitter_config.load_config_section(yaml, bot_config, ".")
Ejemplo n.º 5
0
    def test_without_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        brain:
            tokenizer:
        """, ConsoleConfiguration(), ".")

        brain_config = yaml.get_section("brain")

        tokenizer_config = BrainTokenizerConfiguration()
        tokenizer_config.load_config_section(yaml, brain_config, ".")
Ejemplo n.º 6
0
    def test_with_file_no_config_no_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        brain:
            files:
        """, ConsoleConfiguration(), ".")

        brain_config = yaml.get_section("brain")
        self.assertIsNotNone(brain_config)
        files_config = yaml.get_section("files", brain_config)
        self.assertIsNone(files_config)
Ejemplo n.º 7
0
    def load_configuration(self, arguments, subs: Substitutions = None):

        category_path = os.path.dirname(__file__)
        pattern_path = os.path.dirname(
            __file__) + os.sep + "parser/pattern/pattern_nodes.conf"
        template_path = os.path.dirname(
            __file__) + os.sep + "parser/template/template_nodes.conf"

        client_config = self.get_client_configuration()
        self._configuration = ProgramyConfiguration(client_config)

        yaml_file = YamlConfigurationFile()
        yaml_file.load_from_text(
            """
console:
  description: Program-Y Console Client
  bot:  bot
  prompt: ">>>"

  storage:
      entities:
          categories: file
          template_nodes: file
          pattern_nodes: file

      stores:

          file:
              type:   file
              config:
                categories_storage:
                  dirs: %s
                  subdirs: true
                  extension: .aiml

                pattern_nodes_storage:
                  file: %s
                template_nodes_storage:
                  file: %s

#####################################################################################################
#

bot:
    brain: brain

    initial_question: Hi, how can I help you today?
    default_response: Sorry, I don't have an answer for that!
    exit_response: So long, and thanks for the fish!

    override_properties: true

        """ % (category_path, pattern_path, template_path), client_config, ".")
Ejemplo n.º 8
0
    def test_init_no_values(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        console:
        """, ConsoleConfiguration(), ".")

        config = ConsoleConfiguration()
        config.load_configuration(yaml, ".")

        self.assertIsNotNone(config.configurations)
        self.assertEqual(1, len(config.configurations))
Ejemplo n.º 9
0
 def test_init_with_brain_empty_children(self):
     with self.assertRaises(Exception):
         client_config = ClientConfiguration()
         yaml = YamlConfigurationFile(client_config)
         self.assertIsNotNone(yaml)
         yaml.load_from_text(
             """
         brain:
             files:
             services:
         bot:
         """, ".")
Ejemplo n.º 10
0
    def test_init(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
            slack:
              polling_interval: 1
        """, ConsoleConfiguration(), ".")

        slack_config = SlackConfiguration()
        slack_config.load_configuration(yaml, ".")

        self.assertEqual(1, slack_config.polling_interval)
Ejemplo n.º 11
0
    def test_with_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text(
            """
        bot:
            license_keys: $BOT_ROOT/config/license.keys
            prompt: ">>>"
            initial_question: Hi, how can I help you today?
            initial_question_srai: YINITIALQUESTION
            default_response: Sorry, I don't have an answer for that!
            default_response_srai: YDEFAULTRESPONSE
            empty_string: YEMPTY
            exit_response: So long, and thanks for the fish!
            exit_response_srai: YEXITRESPONSE
            override_properties: true
            max_question_recursion: 1000
            max_question_timeout: 60
            max_search_depth: 100
            max_search_timeout: 60
            spelling:
              classname: programy.spelling.norvig.NorvigSpellingChecker
              alphabet: 'abcdefghijklmnopqrstuvwxyz'
              corpus: $BOT_ROOT/corpus.txt
              check_before: true
              check_and_retry: true
        """, ConsoleConfiguration(), ".")

        bot_config = BotConfiguration()
        bot_config.load_configuration(yaml, ".")

        self.assertEqual("./config/license.keys", bot_config.license_keys)
        self.assertEqual(">>>", bot_config.prompt)
        self.assertEqual("Hi, how can I help you today?",
                         bot_config.initial_question)
        self.assertEqual("YINITIALQUESTION", bot_config.initial_question_srai)
        self.assertEqual("Sorry, I don't have an answer for that!",
                         bot_config.default_response)
        self.assertEqual("YDEFAULTRESPONSE", bot_config.default_response_srai)
        self.assertEqual("So long, and thanks for the fish!",
                         bot_config.exit_response)
        self.assertEqual("YEXITRESPONSE", bot_config.exit_response_srai)
        self.assertEqual("YEMPTY", bot_config.empty_string)
        self.assertEqual(bot_config.max_question_recursion, 1000)
        self.assertEqual(bot_config.max_question_timeout, 60)
        self.assertEqual(bot_config.max_search_depth, 100)
        self.assertEqual(bot_config.max_search_timeout, 60)
        self.assertTrue(bot_config.override_properties)

        self.assertIsNotNone(bot_config.spelling)
        self.assertEqual("programy.spelling.norvig.NorvigSpellingChecker",
                         bot_config.spelling.classname)
Ejemplo n.º 12
0
    def test_brain_init_with_config(self):

        yaml = YamlConfigurationFile()
        self.load_os_specific_configuration(yaml, "test_brain.yaml",
                                            "test_brain.windows.yaml")

        brain_config = BrainConfiguration()
        brain_config.load_config_section(yaml, ".")

        brain = Brain(brain_config)
        self.assertIsNotNone(brain)

        self.assertIsNotNone(brain.aiml_parser)
        self.assertIsNotNone(brain.denormals)
        self.assertIsNotNone(brain.normals)
        self.assertIsNotNone(brain.genders)
        self.assertIsNotNone(brain.persons)
        self.assertIsNotNone(brain.person2s)
        self.assertIsNotNone(brain.properties)
        self.assertIsNotNone(brain.rdf)
        self.assertIsNotNone(brain.sets)
        self.assertIsNotNone(brain.maps)
        self.assertIsNotNone(brain.preprocessors)
        self.assertIsNotNone(brain.postprocessors)
        self.assertIsNotNone(brain.authentication)
        self.assertIsNotNone(brain.authorisation)
        self.assertIsNotNone(brain.default_oob)
        self.assertIsNotNone(brain.oobs)

        if os.path.exists(brain_config.binaries.binary_filename):
            os.remove(brain_config.binaries.binary_filename)
        self.assertFalse(os.path.exists(brain_config.binaries.binary_filename))
        brain.save_binary(brain_config)
        self.assertTrue(os.path.exists(brain_config.binaries.binary_filename))
        brain.load_binary(brain_config)

        self.assertTrue(brain.authentication.authenticate("console"))
        self.assertTrue(brain.authentication.authenticate("someone"))

        self.assertTrue(brain.authorisation.authorise("console", "somthing"))
        self.assertTrue(brain.authorisation.authorise("someone", "other"))

        oob_content = ET.fromstring("<oob><something>other</something></oob>")
        self.assertEqual(
            "",
            brain.default_oob.process_out_of_bounds(None, "console",
                                                    oob_content))
        oob_content = ET.fromstring("<oob><dial>07777777777</dial></oob>")
        self.assertEqual(
            "",
            brain.oobs['dial'].process_out_of_bounds(None, "console",
                                                     oob_content))
Ejemplo n.º 13
0
    def test_oob_loading(self):

        yaml = YamlConfigurationFile()
        self.load_os_specific_configuration(yaml, "test_brain.yaml", "test_brain.windows.yaml")

        brain_config = BrainConfiguration()
        brain_config.load_config_section(yaml, ".")

        brain = Brain(brain_config)

        self.assertIsInstance(brain.default_oob, DefaultOutOfBandProcessor)
        self.assertIsInstance(brain.oobs['dial'], DialOutOfBandProcessor)
        self.assertIsInstance(brain.oobs['email'], EmailOutOfBandProcessor)
Ejemplo n.º 14
0
    def test_without_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        console:
        """, ConsoleConfiguration(), ".")

        bot_config = yaml.get_section("console")

        client_config = ClientConfigurationData("test")
        client_config.load_configuration(yaml, bot_config, ".")

        self.assertIsNone(client_config.license_keys)
Ejemplo n.º 15
0
    def test_oob_loading(self):

        yaml = YamlConfigurationFile()
        yaml.load_from_file(os.path.dirname(__file__)+"/test_brain.yaml", ConsoleConfiguration(), os.path.dirname(__file__))

        brain_config = BrainConfiguration()
        brain_config.load_config_section(yaml, ".")

        brain = Brain(brain_config)

        self.assertIsInstance(brain.default_oob, DefaultOutOfBoundsProcessor)
        self.assertIsInstance(brain.oobs['dial'], DialOutOfBoundsProcessor)
        self.assertIsInstance(brain.oobs['email'], EmailOutOfBoundsProcessor)
Ejemplo n.º 16
0
    def test_init_no_values(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        line:
        """, ConsoleConfiguration(), ".")

        line_config = LineConfiguration()
        line_config.load_configuration(yaml, ".")

        self.assertEqual("0.0.0.0", line_config.host)
        self.assertEqual(80, line_config.port)
        self.assertEqual(False, line_config.debug)
Ejemplo n.º 17
0
    def test_init_no_values(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        twilio:
        """, ConsoleConfiguration(), ".")

        twilio_config = TwilioConfiguration()
        twilio_config.load_configuration(yaml, ".")

        self.assertEqual("0.0.0.0", twilio_config.host)
        self.assertEqual(80, twilio_config.port)
        self.assertEqual(False, twilio_config.debug)
Ejemplo n.º 18
0
    def test_with_no_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        brain:
        """, ConsoleConfiguration(), ".")

        brain_config = yaml.get_section("brain")

        braintree_config = BrainBraintreeConfiguration()
        braintree_config.load_config_section(yaml, brain_config, ".")

        self.assertFalse(braintree_config.create)
Ejemplo n.º 19
0
    def test_init_no_values(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        facebook:
        """, ConsoleConfiguration(), ".")

        facebook_config = FacebookConfiguration()
        facebook_config.load_configuration(yaml, ".")

        self.assertEqual("0.0.0.0", facebook_config.host)
        self.assertEqual(80, facebook_config.port)
        self.assertEqual(False, facebook_config.debug)
Ejemplo n.º 20
0
    def test_with_no_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        bot:
        """, ConsoleConfiguration(), ".")

        console_config = yaml.get_section("console")

        triggers_config = TriggerConfiguration()
        triggers_config.load_config_section(yaml, console_config, ".")

        self.assertEquals("programy.triggers.local.LocalTriggerManager",
                          triggers_config.manager)
Ejemplo n.º 21
0
    def test_with_no_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        brain:
        """, ConsoleConfiguration(), ".")

        brain_config = yaml.get_section("brain")

        language_config = BrainLanguageConfiguration()
        language_config.load_config_section(yaml, brain_config, ".")

        self.assertTrue(language_config.english)
        self.assertFalse(language_config.chinese)
Ejemplo n.º 22
0
    def test_with_no_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        bot:
        """, ConsoleConfiguration(), ".")

        bot_config = yaml.get_section("bot")

        sentiment_config = BotSentimentAnalyserConfiguration()
        sentiment_config.load_config_section(yaml, bot_config, ".")

        self.assertIsNone(sentiment_config.classname)
        self.assertIsNone(sentiment_config.scores)
Ejemplo n.º 23
0
    def test_with_no_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        bot:
        """, ConsoleConfiguration(), ".")

        bot_config = yaml.get_section("bot")

        redis_config = BotConversationsRedisStorageConfiguration("redis")
        redis_config.load_config_section(yaml, bot_config, ".")

        self.assertEquals("localhost", redis_config.host)
        self.assertEquals(6379, redis_config.port)
Ejemplo n.º 24
0
    def test_init_no_values(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        rest:
        """, ConsoleConfiguration(), ".")

        rest_config = RestConfiguration("rest")
        rest_config.load_configuration(yaml, ".")

        self.assertEqual("0.0.0.0", rest_config.host)
        self.assertEqual(80, rest_config.port)
        self.assertEqual(False, rest_config.debug)
        self.assertEqual(False, rest_config.use_api_keys)
Ejemplo n.º 25
0
    def test_with_no_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        brain:
        """, ConsoleConfiguration(), ".")

        brain_config = yaml.get_section("brain")

        nodes_config = BrainNodesConfiguration()
        nodes_config.load_config_section(yaml, brain_config, ".")

        self.assertIsNone(nodes_config.pattern_nodes)
        self.assertIsNone(nodes_config.template_nodes)
Ejemplo n.º 26
0
    def test_job_defaults_no_defaults(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        console:
          scheduler:

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

        console_config = yaml.get_section("console")
        self.assertIsNotNone(console_config)

        scheduler_config = yaml.get_section("scheduler", console_config)
        self.assertIsNone(scheduler_config)
Ejemplo n.º 27
0
    def test_without_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        bot:
        """, ConsoleConfiguration(), ".")

        bot_config = yaml.get_section("bot")

        convo_config = BotConversationsFileStorageConfiguration(
            config_name="file_storage")
        convo_config.load_config_section(yaml, bot_config, ".")

        self.assertIsNone(convo_config.dir)
Ejemplo n.º 28
0
    def test_load_from_text_multis_one_value(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        configuration = yaml.load_from_text(
            """
            bot:
                brain:  bot1
        """, ConsoleConfiguration(), ".")
        self.assertIsNotNone(configuration)

        self.assertEqual(
            1,
            len(configuration.client_configuration.configurations[0].
                configurations))
Ejemplo n.º 29
0
    def test_init(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
            telegram:
              unknown_command: Sorry, that is not a command I have been taught yet!
              unknown_command_srai: YTELEGRAM_UNKNOWN_COMMAND
          """, ConsoleConfiguration(), ".")

        telegram_config = TelegramConfiguration()
        telegram_config.load_configuration(yaml, ".")

        self.assertEquals(telegram_config.unknown_command, "Sorry, that is not a command I have been taught yet!")
        self.assertEquals(telegram_config.unknown_command_srai, "YTELEGRAM_UNKNOWN_COMMAND")
Ejemplo n.º 30
0
    def test_initialise_without_config_no_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
                other:
                """, ConsoleConfiguration(), ".")

        file_config = yaml.get_section("files")

        config = FileStorageConfiguration()
        config.load_config_section(yaml, file_config, ".")

        tmpdir = FileStorageConfiguration.get_temp_dir()

        self.assert_object_config(config.categories_storage, dirs=[tmpdir + os.sep + "categories"], extension="aiml", subdirs=True, fileformat="xml", encoding="utf-8", delete_on_start=False)
        self.assert_object_config(config.learnf_storage, dirs=[tmpdir + os.sep + "categories/learnf"], extension="aiml", subdirs=False, fileformat="xml", encoding="utf-8", delete_on_start=False)

        self.assert_object_config(config.conversation_storage, dirs=[tmpdir + os.sep + "conversations"], extension="txt", subdirs=False, fileformat="text", encoding="utf-8", delete_on_start=False)

        self.assert_object_config(config.sets_storage, dirs=[tmpdir + os.sep + "sets"], extension="txt", subdirs=False, fileformat="text", encoding="utf-8", delete_on_start=False)
        self.assert_object_config(config.maps_storage, dirs=[tmpdir + os.sep + "maps"], extension="txt", subdirs=False, fileformat="text", encoding="utf-8", delete_on_start=False)
        self.assert_object_config(config.rdf_storage, dirs=[tmpdir + os.sep + "rdfs"], extension="txt", subdirs=True, fileformat="text", encoding="utf-8", delete_on_start=False)

        self.assert_object_config(config.denormal_storage, file=tmpdir + os.sep + "lookups/denormal.txt", fileformat="text", encoding="utf-8", delete_on_start=False)
        self.assert_object_config(config.normal_storage, file=tmpdir + os.sep + "lookups/normal.txt", fileformat="text", encoding="utf-8", delete_on_start=False)
        self.assert_object_config(config.gender_storage, file=tmpdir + os.sep + "lookups/gender.txt", fileformat="text", encoding="utf-8", delete_on_start=False)
        self.assert_object_config(config.person_storage, file=tmpdir + os.sep + "lookups/person.txt", fileformat="text", encoding="utf-8", delete_on_start=False)
        self.assert_object_config(config.person2_storage, file=tmpdir + os.sep + "lookups/person2.txt", fileformat="text", encoding="utf-8", delete_on_start=False)
        self.assert_object_config(config.regex_storage, file=tmpdir + os.sep + "regex/regex-templates.txt", fileformat="text", encoding="utf-8", delete_on_start=False)

        self.assert_object_config(config.properties_storage, file=tmpdir + os.sep + "properties/properties.txt", fileformat="text", encoding="utf-8", delete_on_start=False)
        self.assert_object_config(config.defaults_storage, file=tmpdir + os.sep + "properties/defaults.txt", fileformat="text", encoding="utf-8", delete_on_start=False)

        self.assert_object_config(config.twitter_storage, dirs=[tmpdir + os.sep + "twitter"], extension="txt", subdirs=False, fileformat="text", encoding="utf-8", delete_on_start=False)

        self.assert_object_config(config.spelling_storage, file=tmpdir + os.sep + "spelling/corpus.txt", fileformat="text", encoding="utf-8", delete_on_start=False)

        self.assert_object_config(config.license_storage, file=tmpdir + os.sep + "licenses/license.keys", fileformat="text", encoding="utf-8", delete_on_start=False)

        self.assert_object_config(config.pattern_nodes_storage, file=tmpdir + os.sep + "nodes/pattern_nodes.conf", fileformat="text", encoding="utf-8", delete_on_start=False)
        self.assert_object_config(config.template_nodes_storage, file=tmpdir + os.sep + "nodes/template_nodes.conf", fileformat="text", encoding="utf-8", delete_on_start=False)

        self.assert_object_config(config.binaries_storage, file=tmpdir + os.sep + "binaries/binaries.bin", fileformat="binary", encoding="utf-8", delete_on_start=False)
        self.assert_object_config(config.braintree_storage, file=tmpdir + os.sep + "braintree/braintree.xml", fileformat="xml", encoding="utf-8", delete_on_start=False)

        self.assert_object_config(config.preprocessors_storage, file=tmpdir + os.sep + "processing/preprocessors.conf", fileformat="text", encoding="utf-8", delete_on_start=False)
        self.assert_object_config(config.postprocessors_storage, file=tmpdir + os.sep + "processing/postprocessors.conf", fileformat="text", encoding="utf-8", delete_on_start=False)
        self.assert_object_config(config.postquestionprocessors_storage, file=tmpdir + os.sep + "processing/postquestionprocessors.conf", fileformat="text", encoding="utf-8", delete_on_start=False)

        self.assert_object_config(config.usergroups_storage, file=tmpdir + os.sep + "security/usergroups.yaml", fileformat="yaml", encoding="utf-8", delete_on_start=False)