コード例 #1
0
ファイル: test_auth.py プロジェクト: datapane/datapane
def test_auth():
    """Test API-based auth"""
    TEST_ENV = "test_env"

    fp: Optional[Path] = None
    try:
        dp.init(config_env=TEST_ENV)

        config = c.get_config()
        fp = config._path

        # check the config env file can't login and is the default
        assert config.token == c.DEFAULT_TOKEN
        with pytest.raises(InvalidTokenError):
            dp.ping()

        # login
        username = dp.login(token=TEST_TOKEN,
                            server=TEST_SERVER,
                            env=TEST_ENV,
                            cli_login=False)
        assert username == "datapane-test"
        # logout
        dp.logout(env=TEST_ENV)

        # check we've remove the config env file
        assert not fp.exists()

    finally:
        if fp and fp.exists():
            fp.unlink()
コード例 #2
0
def test_auth():
    """Test API-based auth"""
    TEST_ENV = "test_env"

    fp = c.get_config_file(TEST_ENV)
    if fp.exists():
        fp.unlink()

    try:
        dp.init(config_env=TEST_ENV)

        # check the config env file is default
        assert fp.read_text() == c.get_default_config()

        with pytest.raises(InvalidTokenError):
            dp.ping()

        # login
        dp.login(token=TEST_TOKEN,
                 server=TEST_SERVER,
                 env=TEST_ENV,
                 cli_login=False)
        dp.ping()
        # logout
        dp.logout(env=TEST_ENV)

        # check we've reset the config env file back to default
        assert fp.read_text() == c.get_default_config()

        with pytest.raises(InvalidTokenError):
            dp.ping()
    finally:
        if fp.exists():
            fp.unlink()
コード例 #3
0
def test_login_fixture():
    """Test that the fixture-based login, using config object, works"""
    dp.ping()