Example #1
0
def test_import_settings_non_existing_module():
    settings, found = import_settings('tests.does_not_exist')
    assert found == False
    assert 'PLUGINS' in settings
    assert settings['PLUGINS'] == [
        'machine.plugins.builtin.general.PingPongPlugin',
        'machine.plugins.builtin.general.HelloPlugin'
    ]
Example #2
0
 def __init__(self):
     _settings, _ = import_settings()
     slack_api_token = _settings.get('SLACK_API_TOKEN', None)
     http_proxy = _settings.get('HTTP_PROXY', None)
     self.rtm_client = RTMClient(token=slack_api_token, proxy=http_proxy)
     self.web_client = WebClient(token=slack_api_token, proxy=http_proxy)
     self._bot_info = {}
     self._users = {}
     self._channels = {}
Example #3
0
    def __init__(self):
        _settings, _ = import_settings()
        slack_api_token = _settings.get('SLACK_API_TOKEN', None)
        http_proxy = _settings.get('HTTP_PROXY', None)
        https_proxy = _settings.get('HTTPS_PROXY', None)
        proxies = {'http': http_proxy, 'https': https_proxy}

        self._client = SlackClient(
            slack_api_token, proxies=proxies) if slack_api_token else None
Example #4
0
def test_normal_import_settings():
    settings, found = import_settings('tests.local_test_settings')
    assert found == True
    assert 'PLUGINS' in settings
    assert settings['PLUGINS'] == [
        'machine.plugins.builtin.general.PingPongPlugin',
        'machine.plugins.builtin.general.HelloPlugin'
    ]
    assert 'SLACK_API_TOKEN' in settings
    assert settings['SLACK_API_TOKEN'] == 'xoxo-abc123'
    assert 'MY_PLUGIN_SETTING' in settings
    assert settings['MY_PLUGIN_SETTING'] == 'foobar'
    assert '_THIS_SHOULD_NOT_REGISTER' not in settings
def test_env_import_settings():
    with patch.dict(
            'os.environ', {
                'SM_SETTING_1': 'SETTING1',
                'XM_SETTING_2': 'SETTING2',
                'SM_SLACK_API_TOKEN': 'xoxo-somethingelse'
            }):
        settings, found = import_settings('tests.local_test_settings')
        assert found == True
        assert 'SETTING_1' in settings
        assert settings['SETTING_1'] == 'SETTING1'
        assert 'SETTING_2' not in settings
        assert 'SLACK_API_TOKEN' in settings
        assert settings['SLACK_API_TOKEN'] == 'xoxo-somethingelse'
Example #6
0
    def __init__(self, settings=None):
        announce("Initializing Slack Machine:")

        with indent(4):
            puts("Loading settings...")
            if settings:
                self._settings = settings
                found_local_settings = True
            else:
                self._settings, found_local_settings = import_settings()
            fmt = '[%(asctime)s][%(levelname)s] %(name)s %(filename)s:%(funcName)s:%(lineno)d |' \
                  ' %(message)s'
            date_fmt = '%Y-%m-%d %H:%M:%S'
            log_level = self._settings.get('LOGLEVEL', logging.ERROR)
            logging.basicConfig(
                level=log_level,
                format=fmt,
                datefmt=date_fmt,
            )
            if not found_local_settings:
                warn(
                    "No local_settings found! Are you sure this is what you want?"
                )
            if 'SLACK_API_TOKEN' not in self._settings:
                error(
                    "No SLACK_API_TOKEN found in settings! I need that to work..."
                )
                sys.exit(1)
            self._client = Slack()
            puts("Initializing storage using backend: {}".format(
                self._settings['STORAGE_BACKEND']))
            self._storage = Storage.get_instance()
            logger.debug("Storage initialized!")

            self._plugin_actions = {
                'process': {},
                'listen_to': {},
                'respond_to': {},
                'catch_all': {}
            }
            self._help = {'human': {}, 'robot': {}}
            puts("Loading plugins...")
            self.load_plugins()
            logger.debug("The following plugin actions were registered: %s",
                         self._plugin_actions)
            self._dispatcher = EventDispatcher(self._plugin_actions,
                                               self._settings)
Example #7
0
 def __init__(self):
     _settings, _ = import_settings()
     self._client = SlackClient(
         _settings['SLACK_API_TOKEN']
     ) if 'SLACK_API_TOKEN' in _settings else None
Example #8
0
 def __init__(self):
     _settings, _ = import_settings()
     _, cls = import_string(_settings['STORAGE_BACKEND'])[0]
     self._storage = cls(_settings)
Example #9
0
 def __init__(self):
     _settings, _ = import_settings()
     self._scheduler = BackgroundScheduler()
     if 'REDIS_URL' in _settings:
         redis_config = gen_config_dict(_settings)
         self._scheduler.add_jobstore('redis', **redis_config)