Exemplo n.º 1
0
def test_prepare_auth_guess(monkeypatch):
    import requests_toolbelt.auth.guess

    assert isinstance(prepare_auth("guess", "user", "pwd"),
                      requests_toolbelt.auth.guess.GuessAuth)

    monkeypatch.delattr(requests_toolbelt.auth.guess, "GuessAuth")

    with pytest.raises(UserError) as excinfo:
        prepare_auth("guess", "user", "pwd")

    assert "requests_toolbelt is too old" in str(excinfo.value).lower()
Exemplo n.º 2
0
def test_prepare_auth_guess(monkeypatch, auth):
    import requests_toolbelt.auth.guess

    assert isinstance(prepare_auth(auth, 'user', 'pwd'),
                      requests_toolbelt.auth.guess.GuessAuth)

    monkeypatch.delattr(requests_toolbelt.auth.guess, 'GuessAuth')

    with pytest.raises(UserError) as excinfo:
        prepare_auth(auth, 'user', 'pwd')

    assert 'requests_toolbelt is too old' in str(excinfo.value).lower()
Exemplo n.º 3
0
def test_prepare_auth_guess(monkeypatch):
    import requests_toolbelt.auth.guess

    assert isinstance(prepare_auth('guess', 'user', 'pwd'),
                      requests_toolbelt.auth.guess.GuessAuth)

    monkeypatch.delattr(requests_toolbelt.auth.guess, 'GuessAuth')

    with pytest.raises(UserError) as excinfo:
        prepare_auth('guess', 'user', 'pwd')

    assert 'requests_toolbelt is too old' in str(excinfo.value).lower()
Exemplo n.º 4
0
def test_prepare_auth_guess(monkeypatch, auth):
    import requests_toolbelt

    assert isinstance(prepare_auth(auth, 'user', 'pwd'),
                      requests_toolbelt.GuessAuth)

    if hasattr(requests_toolbelt, 'GuessAuth'):
        monkeypatch.delattr(requests_toolbelt, 'GuessAuth')

    with pytest.raises(RuntimeError) as excinfo:
        prepare_auth(auth, 'user', 'pwd')

    assert 'requests_toolbelt is too old' in str(excinfo.value).lower()
Exemplo n.º 5
0
def test_prepare_auth():
    assert prepare_auth(None, '', '') is None

    assert prepare_auth(None, 'user', 'pwd') == ('user', 'pwd')
    assert prepare_auth('basic', 'user', 'pwd') == ('user', 'pwd')

    with pytest.raises(ValueError) as excinfo:
        assert prepare_auth('basic', '', 'pwd')
    assert 'you need to specify username and password' in \
        str(excinfo.value).lower()

    from requests.auth import HTTPDigestAuth
    assert isinstance(prepare_auth('digest', 'user', 'pwd'), HTTPDigestAuth)

    with pytest.raises(ValueError) as excinfo:
        prepare_auth('ladida', 'user', 'pwd')

    assert 'unknown authentication method' in str(excinfo.value).lower()
Exemplo n.º 6
0
def test_prepare_auth():
    assert prepare_auth(None, "", "") is None

    assert prepare_auth(None, "user", "pwd") == ("user", "pwd")
    assert prepare_auth("basic", "user", "pwd") == ("user", "pwd")

    with pytest.raises(ValueError) as excinfo:
        assert prepare_auth("basic", "", "pwd")
    assert "you need to specify username and password" in str(
        excinfo.value).lower()

    from requests.auth import HTTPDigestAuth

    assert isinstance(prepare_auth("digest", "user", "pwd"), HTTPDigestAuth)

    with pytest.raises(ValueError) as excinfo:
        prepare_auth("ladida", "user", "pwd")

    assert "unknown authentication method" in str(excinfo.value).lower()
Exemplo n.º 7
0
def test_prepare_auth():
    assert prepare_auth(None, '', '') is None

    assert prepare_auth(None, 'user', 'pwd') == ('user', 'pwd')
    assert prepare_auth('basic', 'user', 'pwd') == ('user', 'pwd')

    with pytest.raises(ValueError) as excinfo:
        assert prepare_auth('basic', '', 'pwd')
    assert 'you need to specify username and password' in \
        str(excinfo.value).lower()

    from requests.auth import HTTPDigestAuth
    assert isinstance(prepare_auth('digest', 'user', 'pwd'),
                      HTTPDigestAuth)

    with pytest.raises(ValueError) as excinfo:
        prepare_auth('ladida', 'user', 'pwd')

    assert 'unknown authentication method' in str(excinfo.value).lower()