Ejemplo n.º 1
0
def test_load_from_yaml_failed_db_error(monkeypatch):
    monkeypatch.setattr(
        'satellite.routes.loaders.route_manager.replace',
        Mock(side_effect=DatabaseError(Mock(), Mock(), Mock())),
    )
    with pytest.raises(LoadError) as ctx:
        load_from_yaml(StringIO(ROUTES_YAML))
    assert str(ctx.value).startswith('Unable to load routes into the DB')
Ejemplo n.º 2
0
def test_load_from_yaml_failed_failed_route_check(monkeypatch):
    monkeypatch.setattr(
        'satellite.routes.loaders.route_manager.replace',
        Mock(side_effect=InvalidRouteConfiguration('test error')),
    )
    with pytest.raises(LoadError) as ctx:
        load_from_yaml(StringIO(ROUTES_YAML))
    assert str(ctx.value) == 'Invalid routes config: test error'
Ejemplo n.º 3
0
def test_load_from_yaml_failed_validation():
    with pytest.raises(LoadError) as ctx:
        load_from_yaml(
            StringIO(
                ROUTES_YAML.replace(
                    'public_token_generator: UUID',
                    'public_token_generator: UNKNOWN',
                )))
    assert str(ctx.value).startswith('Invalid routes data')
Ejemplo n.º 4
0
def test_load_from_yaml_ok(monkeypatch, snapshot):
    mock_replace = Mock()
    monkeypatch.setattr(
        'satellite.routes.loaders.route_manager.replace',
        mock_replace,
    )

    res = load_from_yaml(StringIO(ROUTES_YAML))
    assert res == 2
    mock_replace.assert_called_once()
    snapshot.assert_match(list(mock_replace.call_args))
Ejemplo n.º 5
0
def main(**kwargs):
    set_start_method('fork')  # PyInstaller supports only fork start method

    pickling_support.install()

    init_satellite_dir()

    try:
        config = configure(**{
            name: value
            for name, value in kwargs.items() if value is not None
        })
    except InvalidConfigError as exc:
        raise click.ClickException(f'Invalid config: {exc}') from exc

    satellite_logging.configure(log_path=config.log_path, silent=config.silent)
    logger = logging.getLogger()

    db.configure(config.db_path)
    try:
        db.init()
    except db.DBVersionMismatch as exc:
        raise click.ClickException(exc) from exc

    if config.routes_path:
        with open(config.routes_path, 'r') as stream:
            try:
                loaded_routes_count = load_from_yaml(stream)
            except LoadError as exc:
                raise click.ClickException(
                    f'Unable to load routes from file: {exc}') from exc
        logger.info(
            f'Loaded {loaded_routes_count} routes from routes config file.')

    deleted_aliases = AliasStore.cleanup()
    logger.info(f'Deleted {deleted_aliases} expired aliases.')

    app = WebApplication(config)
    app.start()
Ejemplo n.º 6
0
def test_load_from_yaml_invalid_yaml():
    with pytest.raises(LoadError) as ctx:
        load_from_yaml(StringIO('{invalid'))
    assert str(ctx.value).startswith('Unable to parse config')