コード例 #1
0
ファイル: settings.py プロジェクト: 7minus2/slack-machine
def import_settings(settings_module='local_settings'):
    default_settings = {
        'PLUGINS': [
            'machine.plugins.builtin.general.PingPongPlugin',
            'machine.plugins.builtin.general.HelloPlugin'
        ],
        'STORAGE_BACKEND':
        'machine.storage.backends.memory.MemoryStorage'
    }
    settings = CaseInsensitiveDict(default_settings)
    try:
        local_settings = import_module(settings_module)
        found_local_settings = True
    except ImportError:
        found_local_settings = False
    else:
        for k in dir(local_settings):
            if not k.startswith('_'):
                settings[k] = getattr(local_settings, k)

    for k, v in os.environ.items():
        if k[:3] == 'SM_':
            k = k[3:]
            settings[k] = v

    return (settings, found_local_settings)
コード例 #2
0
def settings():
    settings = CaseInsensitiveDict()
    settings['PLUGINS'] = ['tests.fake_plugins']
    settings['SLACK_API_TOKEN'] = 'xoxo-abc123'
    settings[
        'STORAGE_BACKEND'] = 'machine.storage.backends.memory.MemoryStorage'
    return settings
コード例 #3
0
def import_settings(settings_module='local_settings') -> Tuple[CaseInsensitiveDict, bool]:
    default_settings = {
        'PLUGINS': ['machine.plugins.builtin.general.PingPongPlugin',
                    'machine.plugins.builtin.general.HelloPlugin',
                    'machine.plugins.builtin.help.HelpPlugin',
                    'machine.plugins.builtin.fun.memes.MemePlugin'],
        'STORAGE_BACKEND': 'machine.storage.backends.memory.MemoryStorage',
        'DISABLE_HTTP': False,
        'HTTP_SERVER_HOST': '0.0.0.0',
        'HTTP_SERVER_PORT': 8080,
        'HTTP_SERVER_BACKEND': 'wsgiref',
        'HTTP_PROXY': None,
        'HTTPS_PROXY': None,
        'KEEP_ALIVE': None
    }
    settings = CaseInsensitiveDict(default_settings)
    try:
        local_settings = import_module(settings_module)
        found_local_settings = True
    except ImportError:
        found_local_settings = False
    else:
        for k in dir(local_settings):
            if not k.startswith('_'):
                settings[k] = getattr(local_settings, k)

    for k, v in os.environ.items():
        if k[:3] == 'SM_':
            k = k[3:]
            settings[k] = v

    return settings, found_local_settings
コード例 #4
0
def settings(module_mocker):
    settings = CaseInsensitiveDict()
    settings['PLUGINS'] = ['tests.fake_plugins']
    settings['SLACK_API_TOKEN'] = 'xoxo-abc123'
    settings[
        'STORAGE_BACKEND'] = 'machine.storage.backends.memory.MemoryStorage'
    slack_settings = module_mocker.patch(
        'machine.clients.singletons.slack.import_settings')
    storage_settings = module_mocker.patch(
        'machine.clients.singletons.storage.import_settings')
    slack_settings.return_value = (settings, True)
    storage_settings.return_value = (settings, True)
    return settings
コード例 #5
0
def fake_plugin(mocker, msg_client, storage):
    plugin_instance = FakePlugin(msg_client, CaseInsensitiveDict(), storage)
    mocker.spy(plugin_instance, 'respond_function')
    mocker.spy(plugin_instance, 'listen_function')
    mocker.spy(plugin_instance, 'process_function')
    return plugin_instance
コード例 #6
0
def test_CaseInsensitiveDict():
    d = CaseInsensitiveDict({'foo': 'bar'})
    assert 'foo' in d
    assert 'FoO' in d