def __init__(self, extra_config=None):
        self.outgoing_message_queue = Queue()
        if extra_config is None:
            extra_config = {}
        # make up a config.
        tempdir = mkdtemp()
        # reset the config every time
        sys.modules.pop('errbot.config-template', None)
        __import__('errbot.config-template')
        config = ShallowConfig()
        config.__dict__.update(sys.modules['errbot.config-template'].__dict__)
        bot_config_defaults(config)

        # It injects itself as a plugin. Changed the name to be sure we distinguish it.
        self.name = 'DummyBackendRealName'

        config.BOT_DATA_DIR = tempdir
        config.BOT_LOG_FILE = tempdir + sep + 'log.txt'
        config.BOT_PLUGIN_INDEXES = tempdir + sep + 'repos.json'
        config.BOT_EXTRA_PLUGIN_DIR = []
        config.BOT_LOG_LEVEL = logging.DEBUG
        config.BOT_IDENTITY = {'username': '******'}
        config.BOT_ASYNC = False
        config.BOT_PREFIX = '!'
        config.CHATROOM_FN = 'blah'

        # Writeout the made up repos file
        with open(config.BOT_PLUGIN_INDEXES, "w") as index_file:
            index_file.write(SIMPLE_JSON_PLUGINS_INDEX)

        for key in extra_config:
            setattr(config, key, extra_config[key])
        super().__init__(config)
        self.bot_identifier = self.build_identifier('err')
        self.md = text()  # We just want simple text for testing purposes

        # setup a memory based storage
        spm = SpecificPluginManager(config, 'storage', StoragePluginBase, CORE_STORAGE, None)
        storage_plugin = spm.get_plugin_by_name('Memory')

        # setup the plugin_manager just internally
        botplugins_dir = os.path.join(config.BOT_DATA_DIR, PLUGINS_SUBDIR)
        if not os.path.exists(botplugins_dir):
            os.makedirs(botplugins_dir, mode=0o755)

        # get it back from where we publish it.
        repo_index_paths = (os.path.join(os.path.dirname(__file__), '..', 'docs', '_extra', 'repos.json'),)
        repo_manager = BotRepoManager(storage_plugin,
                                      botplugins_dir,
                                      repo_index_paths)
        self.attach_storage_plugin(storage_plugin)
        self.attach_repo_manager(repo_manager)
        self.attach_plugin_manager(BotPluginManager(storage_plugin,
                                                    repo_manager,
                                                    config.BOT_EXTRA_PLUGIN_DIR,
                                                    config.AUTOINSTALL_DEPS,
                                                    getattr(config, 'CORE_PLUGINS', None),
                                                    getattr(config, 'PLUGINS_CALLBACK_ORDER', (None, ))))
        self.inject_commands_from(self)
        self.inject_command_filters_from(ACLS(self))
Exemple #2
0
    def __init__(self, extra_config=None):
        self.outgoing_message_queue = Queue()
        if extra_config is None:
            extra_config = {}
        # make up a config.
        tempdir = mkdtemp()
        # reset the config every time
        sys.modules.pop('errbot.config-template', None)
        __import__('errbot.config-template')
        config = ShallowConfig()
        config.__dict__.update(sys.modules['errbot.config-template'].__dict__)
        bot_config_defaults(config)

        # It injects itself as a plugin. Changed the name to be sure we distinguish it.
        self.name = 'DummyBackendRealName'

        config.BOT_DATA_DIR = tempdir
        config.BOT_LOG_FILE = tempdir + sep + 'log.txt'
        config.BOT_PLUGIN_INDEXES = tempdir + sep + 'repos.json'
        config.BOT_EXTRA_PLUGIN_DIR = []
        config.BOT_LOG_LEVEL = logging.DEBUG
        config.BOT_IDENTITY = {'username': '******'}
        config.BOT_ASYNC = False
        config.BOT_PREFIX = '!'
        config.CHATROOM_FN = 'blah'

        # Writeout the made up repos file
        with open(config.BOT_PLUGIN_INDEXES, "w") as index_file:
            index_file.write(SIMPLE_JSON_PLUGINS_INDEX)

        for key in extra_config:
            setattr(config, key, extra_config[key])
        super().__init__(config)
        self.bot_identifier = self.build_identifier('err')
        self.md = text()  # We just want simple text for testing purposes

        # setup a memory based storage
        spm = SpecificPluginManager(config, 'storage', StoragePluginBase, CORE_STORAGE, None)
        storage_plugin = spm.get_plugin_by_name('Memory')

        # setup the plugin_manager just internally
        botplugins_dir = os.path.join(config.BOT_DATA_DIR, PLUGINS_SUBDIR)
        if not os.path.exists(botplugins_dir):
            os.makedirs(botplugins_dir, mode=0o755)

        # get it back from where we publish it.
        repo_index_paths = (os.path.join(os.path.dirname(__file__), '..', 'docs', '_extra', 'repos.json'),)
        repo_manager = BotRepoManager(storage_plugin,
                                      botplugins_dir,
                                      repo_index_paths)
        self.attach_storage_plugin(storage_plugin)
        self.attach_repo_manager(repo_manager)
        self.attach_plugin_manager(BotPluginManager(storage_plugin,
                                                    repo_manager,
                                                    config.BOT_EXTRA_PLUGIN_DIR,
                                                    config.AUTOINSTALL_DEPS,
                                                    getattr(config, 'CORE_PLUGINS', None),
                                                    getattr(config, 'PLUGINS_CALLBACK_ORDER', (None, ))))
        self.inject_commands_from(self)
        self.inject_command_filters_from(ACLS(self))
Exemple #3
0
    def setUp(self):
        # make up a config.
        tempdir = mkdtemp()
        # reset the config every time
        sys.modules.pop("errbot.config-template", None)
        __import__("errbot.config-template")
        config = sys.modules["errbot.config-template"]
        bot_config_defaults(config)
        config.BOT_DATA_DIR = tempdir
        config.BOT_LOG_FILE = os.path.join(tempdir, "log.txt")
        config.BOT_EXTRA_PLUGIN_DIR = []
        config.BOT_LOG_LEVEL = logging.DEBUG
        config.BOT_IDENTITY = {"username": "******", "token": "___"}
        config.BOT_ASYNC = False
        config.BOT_PREFIX = "!"
        config.CHATROOM_FN = "blah"

        self.slack = TestSlackBackend(config)

        self.reaction_event = {
            "type": "reaction_added",
            "user": "******",
            "reaction": "thumbsup",
            "item": {
                "type": "message",
                "channel": "C0G9QF9GZ",
                "ts": "1360782400.498405",
            },
            "event_ts": "1360782804.083113",
        }
        self.slack.callback_reaction = MagicMock(
            side_effect=self.callback_reaction_mock)
Exemple #4
0
    def __init__(self, extra_config=None):
        self.outgoing_message_queue = Queue()
        if extra_config is None:
            extra_config = {}
        # make up a config.
        tempdir = mkdtemp()
        # reset the config every time
        sys.modules.pop("errbot.config-template", None)
        __import__("errbot.config-template")
        config = ShallowConfig()
        config.__dict__.update(sys.modules["errbot.config-template"].__dict__)
        bot_config_defaults(config)
        config.BOT_DATA_DIR = tempdir
        config.BOT_LOG_FILE = tempdir + sep + "log.txt"
        config.BOT_PLUGIN_INDEXES = tempdir + sep + "repos.json"
        config.BOT_EXTRA_PLUGIN_DIR = []
        config.BOT_LOG_LEVEL = logging.DEBUG
        config.BOT_IDENTITY = {"username": "******"}
        config.BOT_ASYNC = False
        config.BOT_PREFIX = "!"
        config.CHATROOM_FN = "blah"

        # Writeout the made up repos file
        with open(config.BOT_PLUGIN_INDEXES, "w") as index_file:
            index_file.write(SIMPLE_JSON_PLUGINS_INDEX)

        for key in extra_config:
            setattr(config, key, extra_config[key])
        super().__init__(config)
        self.bot_identifier = self.build_identifier("err")
        self.md = text()  # We just want simple text for testing purposes

        # setup a memory based storage
        spm = SpecificPluginManager(config, "storage", StoragePluginBase, CORE_STORAGE, None)
        storage_plugin = spm.get_plugin_by_name("Memory")

        # setup the plugin_manager just internally
        botplugins_dir = os.path.join(config.BOT_DATA_DIR, PLUGINS_SUBDIR)
        if not os.path.exists(botplugins_dir):
            os.makedirs(botplugins_dir, mode=0o755)

        # get it back from where we publish it.
        repo_index_paths = (os.path.join(os.path.dirname(__file__), "..", "docs", "_extra", "repos.json"),)
        repo_manager = BotRepoManager(storage_plugin, botplugins_dir, repo_index_paths)
        self.attach_storage_plugin(storage_plugin)
        self.attach_repo_manager(repo_manager)
        self.attach_plugin_manager(
            BotPluginManager(
                storage_plugin,
                repo_manager,
                config.BOT_EXTRA_PLUGIN_DIR,
                config.AUTOINSTALL_DEPS,
                getattr(config, "CORE_PLUGINS", None),
                getattr(config, "PLUGINS_CALLBACK_ORDER", (None,)),
            )
        )
        self.inject_commands_from(self)
        self.inject_command_filters_from(ACLS(self))
Exemple #5
0
def text_backend():
    tempdir = mkdtemp()

    # reset the config every time
    sys.modules.pop('errbot.config-template', None)
    __import__('errbot.config-template')
    config = sys.modules['errbot.config-template']
    bot_config_defaults(config)
    config.BOT_DATA_DIR = tempdir
    config.BOT_LOG_FILE = os.path.join(tempdir, 'log.txt')
    config.BOT_EXTRA_PLUGIN_DIR = []
    config.BOT_LOG_LEVEL = logging.DEBUG
    config.BOT_PREFIX = '!'
    config.BOT_IDENTITY['username'] = '******'
    config.BOT_ADMINS = ['@test_admin']

    return TextBackend(config)
Exemple #6
0
def text_backend():
    tempdir = mkdtemp()

    # reset the config every time
    sys.modules.pop("errbot.config-template", None)
    __import__("errbot.config-template")
    config = sys.modules["errbot.config-template"]
    bot_config_defaults(config)
    config.BOT_DATA_DIR = tempdir
    config.BOT_LOG_FILE = os.path.join(tempdir, "log.txt")
    config.BOT_EXTRA_PLUGIN_DIR = []
    config.BOT_LOG_LEVEL = logging.DEBUG
    config.BOT_PREFIX = "!"
    config.BOT_IDENTITY["username"] = "******"
    config.BOT_ADMINS = ["@test_admin"]

    return TextBackend(config)
Exemple #7
0
    def setUp(self):
        # make up a config.
        tempdir = mkdtemp()
        # reset the config every time
        sys.modules.pop('errbot.config-template', None)
        __import__('errbot.config-template')
        config = sys.modules['errbot.config-template']
        bot_config_defaults(config)
        config.BOT_DATA_DIR = tempdir
        config.BOT_LOG_FILE = os.path.join(tempdir, 'log.txt')
        config.BOT_EXTRA_PLUGIN_DIR = []
        config.BOT_LOG_LEVEL = logging.DEBUG
        config.BOT_IDENTITY = {'username': '******', 'token': '___'}
        config.BOT_ASYNC = False
        config.BOT_PREFIX = '!'
        config.CHATROOM_FN = 'blah'

        self.slack = TestSlackBackend(config)
Exemple #8
0
    def setUp(self):
        # make up a config.
        tempdir = mkdtemp()
        # reset the config every time
        sys.modules.pop("errbot.config-template", None)
        __import__("errbot.config-template")
        config = sys.modules["errbot.config-template"]
        bot_config_defaults(config)
        config.BOT_DATA_DIR = tempdir
        config.BOT_LOG_FILE = os.path.join(tempdir, "log.txt")
        config.BOT_EXTRA_PLUGIN_DIR = []
        config.BOT_LOG_LEVEL = logging.DEBUG
        config.BOT_IDENTITY = {"username": "******", "token": "___"}
        config.BOT_ASYNC = False
        config.BOT_PREFIX = "!"
        config.CHATROOM_FN = "blah"

        self.slack = TestSlackBackend(config)
Exemple #9
0
    def setUp(self):
        # make up a config.
        tempdir = mkdtemp()
        # reset the config every time
        sys.modules.pop('errbot.config-template', None)
        __import__('errbot.config-template')
        config = sys.modules['errbot.config-template']
        bot_config_defaults(config)
        config.BOT_DATA_DIR = tempdir
        config.BOT_LOG_FILE = os.path.join(tempdir, 'log.txt')
        config.BOT_EXTRA_PLUGIN_DIR = []
        config.BOT_LOG_LEVEL = logging.DEBUG
        config.BOT_IDENTITY = {'username': '******', 'token': '___'}
        config.BOT_ASYNC = False
        config.BOT_PREFIX = '!'
        config.CHATROOM_FN = 'blah'

        self.slack = TestSlackBackend(config)
Exemple #10
0
def test_storage():
    key = 'test'

    __import__('errbot.config-template')
    config = ShallowConfig()
    config.__dict__.update(sys.modules['errbot.config-template'].__dict__)
    bot_config_defaults(config)

    spm = BackendPluginManager(config, 'errbot.storage', 'Memory', StoragePluginBase, CORE_STORAGE)
    storage_plugin = spm.load_plugin()

    persistent_object = StoreMixin()
    persistent_object.open_storage(storage_plugin, 'test')
    persistent_object[key] = 'à value'
    assert persistent_object[key] == 'à value'
    assert key in persistent_object
    del persistent_object[key]
    assert key not in persistent_object
    assert len(persistent_object) == 0
Exemple #11
0
def test_storage():
    key = 'test'

    __import__('errbot.config-template')
    config = ShallowConfig()
    config.__dict__.update(sys.modules['errbot.config-template'].__dict__)
    bot_config_defaults(config)

    spm = SpecificPluginManager(config, 'storage', StoragePluginBase,
                                CORE_STORAGE, None)
    storage_plugin = spm.get_plugin_by_name('Memory')

    persistent_object = StoreMixin()
    persistent_object.open_storage(storage_plugin, 'test')
    persistent_object[key] = 'à value'
    assert persistent_object[key] == 'à value'
    assert key in persistent_object
    del persistent_object[key]
    assert key not in persistent_object
    assert len(persistent_object) == 0
Exemple #12
0
def test_storage():
    key = "test"

    __import__("errbot.config-template")
    config = ShallowConfig()
    config.__dict__.update(sys.modules["errbot.config-template"].__dict__)
    bot_config_defaults(config)

    spm = BackendPluginManager(config, "errbot.storage", "Memory",
                               StoragePluginBase, CORE_STORAGE)
    storage_plugin = spm.load_plugin()

    persistent_object = StoreMixin()
    persistent_object.open_storage(storage_plugin, "test")
    persistent_object[key] = "à value"
    assert persistent_object[key] == "à value"
    assert key in persistent_object
    del persistent_object[key]
    assert key not in persistent_object
    assert len(persistent_object) == 0
Exemple #13
0
    def __init__(self, extra_config=None):
        self.outgoing_message_queue = Queue()
        if extra_config is None:
            extra_config = {}
        # make up a config.
        tempdir = mkdtemp()
        # reset the config every time
        sys.modules.pop("errbot.config-template", None)
        __import__("errbot.config-template")
        config = ShallowConfig()
        config.__dict__.update(sys.modules["errbot.config-template"].__dict__)
        bot_config_defaults(config)

        # It injects itself as a plugin. Changed the name to be sure we distinguish it.
        self.name = "DummyBackendRealName"

        config.BOT_DATA_DIR = tempdir
        config.BOT_LOG_FILE = tempdir + sep + "log.txt"
        config.BOT_PLUGIN_INDEXES = tempdir + sep + "repos.json"
        config.BOT_EXTRA_PLUGIN_DIR = []
        config.BOT_LOG_LEVEL = logging.DEBUG
        config.BOT_IDENTITY = {"username": "******"}
        config.BOT_ASYNC = False
        config.BOT_PREFIX = "!"
        config.CHATROOM_FN = "blah"

        # Writeout the made up repos file
        with open(config.BOT_PLUGIN_INDEXES, "w") as index_file:
            index_file.write(SIMPLE_JSON_PLUGINS_INDEX)

        for key in extra_config:
            setattr(config, key, extra_config[key])
        super().__init__(config)
        self.bot_identifier = self.build_identifier("err")
        self.md = text()  # We just want simple text for testing purposes

        # setup a memory based storage
        spm = BackendPluginManager(config, "errbot.storage", "Memory",
                                   StoragePluginBase, CORE_STORAGE)
        storage_plugin = spm.load_plugin()

        # setup the plugin_manager just internally
        botplugins_dir = os.path.join(config.BOT_DATA_DIR, PLUGINS_SUBDIR)
        if not os.path.exists(botplugins_dir):
            os.makedirs(botplugins_dir, mode=0o755)

        # get it back from where we publish it.
        repo_index_paths = (os.path.join(os.path.dirname(__file__), "..",
                                         "docs", "_extra", "repos.json"), )
        repo_manager = BotRepoManager(storage_plugin, botplugins_dir,
                                      repo_index_paths)
        self.attach_storage_plugin(storage_plugin)
        self.attach_repo_manager(repo_manager)
        self.attach_plugin_manager(
            BotPluginManager(
                storage_plugin,
                config.BOT_EXTRA_PLUGIN_DIR,
                config.AUTOINSTALL_DEPS,
                getattr(config, "CORE_PLUGINS", None),
                lambda name, clazz: clazz(self, name),
                getattr(config, "PLUGINS_CALLBACK_ORDER", (None, )),
            ))
        self.inject_commands_from(self)
        self.inject_command_filters_from(ACLS(self))