示例#1
0
def test_raises_for_plugin_non_existent_class(custom_app):
    with pytest.raises(PluginConfigurationException):
        custom_app(logging_plugins=[
            LoggingPluginConfig(
                dotted_path='logger_plugin:DoesNotExistLogger',
                kwargs={},
            ),
        ])
示例#2
0
def test_raises_for_not_callable_value(custom_app):
    with pytest.raises(PluginConfigurationException):
        custom_app(logging_plugins=[
            LoggingPluginConfig(
                dotted_path='logger_plugin:NOT_CALLABLE',
                kwargs={},
            ),
        ])
示例#3
0
def test_raises_for_plugin_in_invalid_format(custom_app):
    with pytest.raises(PluginConfigurationException):
        custom_app(logging_plugins=[
            LoggingPluginConfig(
                dotted_path='logger_plugin.TestLogger',
                kwargs={},
            ),
        ])
示例#4
0
def test_raises_for_plugin_with_invalid_constructor(custom_app):
    with pytest.raises(PluginConfigurationException):
        custom_app(logging_plugins=[
            LoggingPluginConfig(
                dotted_path='logger_plugin:NoArgsLogger',
                kwargs={},
            ),
        ])
示例#5
0
def test_loads_plugin_from_callable(custom_app):
    app = custom_app(logging_plugins=[
        LoggingPluginConfig(
            dotted_path='logger_plugin:dynamic_logger',
            kwargs={},
        ),
    ])

    loggers = register_loggers(app.config)

    assert len(loggers) == 1
    assert isinstance(loggers[0], BaseLogger)
    assert loggers[0].config == app.config
示例#6
0
def test_loads_plugins(custom_app):
    kwargs = {'foo': 'bar'}

    app = custom_app(logging_plugins=[
        LoggingPluginConfig(
            dotted_path='logger_plugin:TestLogger',
            kwargs=kwargs,
        ),
    ])

    loggers = register_loggers(app.config)

    assert len(loggers) == 1
    assert isinstance(loggers[0], _TestLogger)
    assert loggers[0].config == app.config
    assert loggers[0].kwargs == kwargs
示例#7
0
def test_realistic_config():
    data = yaml_data('realistic')
    expected = Config(
        state_machines={
            'example':
            StateMachine(
                name='example',
                feeds=[
                    FeedConfig(name='data_feed',
                               url='http://localhost/<label>'),
                ],
                webhooks=[
                    Webhook(
                        match=re.compile('.+\\.example\\.com'),
                        headers={
                            'x-api-key':
                            'Rahfew7eed1ierae0moa2sho3ieB1et3ohhum0Ei',
                        },
                    ),
                ],
                states=[
                    Gate(
                        name='start',
                        triggers=[
                            SystemTimeTrigger(time=datetime.time(18, 30)),
                            TimezoneAwareTrigger(
                                time=datetime.time(12, 25),
                                timezone='Europe/London',
                            ),
                            MetadataTimezoneAwareTrigger(
                                time=datetime.time(13, 37),
                                timezone_metadata_path=['timezone'],
                            ),
                            MetadataTrigger(metadata_path='foo.bar'),
                            IntervalTrigger(
                                interval=datetime.timedelta(hours=1), ),
                            OnEntryTrigger(),
                        ],
                        next_states=ConstantNextState(state='stage2'),
                        exit_condition=ExitConditionProgram('true'),
                    ),
                    Gate(
                        name='stage2',
                        triggers=[],
                        next_states=ContextNextStates(
                            path='metadata.foo.bar',
                            destinations=[
                                ContextNextStatesOption(
                                    state='stage3',
                                    value='1',
                                ),
                                ContextNextStatesOption(
                                    state='stage3',
                                    value='2',
                                ),
                            ],
                            default='end',
                        ),
                        exit_condition=ExitConditionProgram(
                            'metadata.foo.bar is defined', ),
                    ),
                    Action(
                        name='stage3',
                        webhook='https://localhost/hook',
                        next_states=ConstantNextState(state='end'),
                    ),
                    Gate(
                        name='end',
                        triggers=[],
                        exit_condition=ExitConditionProgram('false'),
                        next_states=NoNextStates(),
                    ),
                ],
            ),
        },
        database=DatabaseConfig(
            host='localhost',
            port=5432,
            name='routemaster',
            username='******',
            password='',
        ),
        logging_plugins=[
            LoggingPluginConfig(
                dotted_path='routemaster_prometheus:PrometheusLogger',
                kwargs={'prometheus_gateway': 'localhost'},
            ),
            LoggingPluginConfig(
                dotted_path='routemaster_sentry:SentryLogger',
                kwargs={'raven_dsn': 'nai8ioca4zeeb2ahgh4V'},
            ),
        ],
    )
    with reset_environment():
        assert load_config(data) == expected