Ejemplo n.º 1
0
def test_get_credentials_no_config(monkeypatch):
    """No configuration file found"""
    monkeypatch.setattr(ConfigParser, 'read', lambda x, y: [])

    with pytest.raises(InvalidConfiguration) as exc:
        get_credentials(
            Namespace(config=None, instance=None, url=None, secret=None))
    assert "No configuration file found" in str(exc.value)
Ejemplo n.º 2
0
def test_get_credentials_missing_attribute(shaarli_config, attribute):
    """The specified instance has no configuration section"""
    with pytest.raises(InvalidConfiguration) as exc:
        get_credentials(
            Namespace(config=str(shaarli_config),
                      instance='no{}'.format(attribute),
                      url=None,
                      secret=None))
    assert "Missing entry: '{}'".format(attribute) in str(exc.value)
Ejemplo n.º 3
0
def test_get_credentials_missing_section(shaarli_config):
    """The specified instance has no configuration section"""
    with pytest.raises(InvalidConfiguration) as exc:
        get_credentials(
            Namespace(config=str(shaarli_config),
                      instance='nonexistent',
                      url=None,
                      secret=None))
    assert "Missing entry: 'shaarli:nonexistent'" in str(exc.value)
Ejemplo n.º 4
0
def build_shaarli_client(settings):
    args = Namespace(
        config=settings.get('SHAARLI_POSTER_CONFIG_FILE_PATH'),
        instance=settings.get('SHAARLI_POSTER_INSTANCE'),
        secret=None,
        url=None,
    )
    return ShaarliV1Client(*get_credentials(args))
Ejemplo n.º 5
0
def test_get_credentials_from_userconfig(shaarli_config, instance):
    """Read credentials from a user-provided configuration file"""
    url, secret = get_credentials(
        Namespace(config=str(shaarli_config),
                  instance=instance,
                  url=None,
                  secret=None))
    assert url == SHAARLI_URL
    assert secret == SHAARLI_SECRET
Ejemplo n.º 6
0
def test_get_credentials_from_config(tmpdir, shaarli_config, instance):
    """Read credentials from a standard location"""
    with tmpdir.as_cwd():
        shaarli_config.copy(tmpdir.join('shaarli_client.ini'))

        url, secret = get_credentials(
            Namespace(config=None, instance=instance, url=None, secret=None))

    assert url == SHAARLI_URL
    assert secret == SHAARLI_SECRET
Ejemplo n.º 7
0
def test_get_credentials_from_cli():
    """Get authentication information as CLI parameters"""
    url, secret = get_credentials(
        Namespace(url=SHAARLI_URL, secret=SHAARLI_SECRET))
    assert url == SHAARLI_URL
    assert secret == SHAARLI_SECRET