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 = sys.modules['errbot.config-template'] bot_config_defaults(config) config.BOT_DATA_DIR = tempdir config.BOT_LOG_FILE = tempdir + sep + 'log.txt' 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' for key in extra_config: setattr(config, key, extra_config[key]) super(DummyBackend, self).__init__(config) self.bot_identifier = self.build_identifier('err') self.inject_commands_from(self) self.inject_command_filters_from(ACLS(self)) self.md = text() # We just want simple text for testing purposes
def __init__(self, extra_config={}): self.bot_config = Config() for key in extra_config: setattr(self.bot_config, key, extra_config[key]) bot_config_defaults(self.bot_config) super(DummyBackend, self).__init__(self.bot_config) self.inject_commands_from(self)
def __init__(self, extra_config=None): 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 = sys.modules["errbot.config-template"] bot_config_defaults(config) config.BOT_DATA_DIR = tempdir config.BOT_LOG_FILE = tempdir + sep + "log.txt" 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" for key in extra_config: setattr(config, key, extra_config[key]) super(DummyBackend, self).__init__(config) self.bot_identifier = self.build_identifier("err") self.inject_commands_from(self) self.inject_command_filters_from(ACLS(self)) self.md = text() # We just want simple text for testing purposes
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 = sys.modules['errbot.config-template'] bot_config_defaults(config) config.BOT_DATA_DIR = tempdir config.BOT_LOG_FILE = tempdir + sep + 'log.txt' 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' for key in extra_config: setattr(config, key, extra_config[key]) super().__init__(config) self.bot_identifier = self.build_identifier('err') self.inject_commands_from(self) self.inject_command_filters_from(ACLS(self)) self.md = text() # We just want simple text for testing purposes
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))) self.inject_commands_from(self) self.inject_command_filters_from(ACLS(self))
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 = sys.modules['errbot.config-template'] 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))) self.inject_commands_from(self) self.inject_command_filters_from(ACLS(self))
def __init__(self, extra_config={}): class Config: BOT_IDENTITY = {'username': '******'} BOT_ASYNC = False BOT_PREFIX = '!' CHATROOM_FN = 'blah' self.bot_config = Config() for key in extra_config: setattr(self.bot_config, key, extra_config[key]) bot_config_defaults(self.bot_config) super(DummyBackend, self).__init__(self.bot_config) self.inject_commands_from(self)
def test_storage(self): key = b'test' if PY2 else 'test' config = sys.modules['errbot.config-template'] 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' self.assertEquals(persistent_object[key], 'à value') self.assertIn(key, persistent_object) del persistent_object[key] self.assertNotIn(key, persistent_object) self.assertEquals(len(persistent_object), 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 = sys.modules["errbot.config-template"] bot_config_defaults(config) config.BOT_DATA_DIR = tempdir config.BOT_LOG_FILE = tempdir + sep + "log.txt" 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" 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) self.attach_plugin_manager( BotPluginManager( storage_plugin, botplugins_dir, config.BOT_EXTRA_PLUGIN_DIR, config.AUTOINSTALL_DEPS, getattr(config, "CORE_PLUGINS", None), ) ) self.attach_storage_plugin(storage_plugin) self.inject_commands_from(self) self.inject_command_filters_from(ACLS(self))
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)
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)
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 = sys.modules['errbot.config-template'] bot_config_defaults(config) config.BOT_DATA_DIR = tempdir config.BOT_LOG_FILE = tempdir + sep + 'log.txt' 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' 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) self.attach_plugin_manager( BotPluginManager(storage_plugin, botplugins_dir, config.BOT_EXTRA_PLUGIN_DIR, config.AUTOINSTALL_DEPS, getattr(config, 'CORE_PLUGINS', None))) self.attach_storage_plugin(storage_plugin) self.inject_commands_from(self) self.inject_command_filters_from(ACLS(self))
def test_storage(): key = b'test' if PY2 else '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