Exemplo n.º 1
0
def auth_or_string(value):
    if isinstance(value, Auth):
        return value
    elif isinstance(value, str) and value.count(':') == 1:
        username, password = value.split(':')
        return BasicAuth(username, password)
    else:
        raise TypeError()
Exemplo n.º 2
0
def test_auth_string():
    assert auth_or_string("hello:world") == BasicAuth("hello", "world")
    assert auth_or_string(None) == None
    assert auth_or_string(BasicAuth("foo", "bar")) == BasicAuth("foo", "bar")
    with pytest.raises(TypeError):
        auth_or_string(1)