Exemplo n.º 1
0
def configure():
    """Configure Jovian for first time usage"""
    # Check if already exists
    if creds_exist():
        log('It looks like Jovian is already configured ( check ~/.jovian/credentials.json ).')
        msg = 'Do you want to overwrite the existing configuration?'
        confirm = click.confirm(msg)

        if confirm:
            log('Removing existing configuration..')
        else:
            log('Skipping..')
            return

    # Remove existing credentials
    purge_creds()

    # Capture and save organization ID
    ensure_org(check_pro=False)

    # Ask for API Key
    get_guest_key()
    get_api_key()

    log('Configuration complete!')
Exemplo n.º 2
0
def test_purge_creds():
    with fake_creds() as dir:
        assert os.path.exists(os.path.join(dir,
                                           '.jovian/credentials.json')) == True
        purge_creds()
        assert os.path.exists(os.path.join(
            dir, '.jovian/credentials.json')) == False
Exemplo n.º 3
0
def test_reset_config_no_creds(capsys):
    with fake_creds():
        purge_creds()

        reset_config()

        expected_result = "[jovian] Jovian is not configured yet. Run \"jovian configure\" to set it up."
        captured = capsys.readouterr()
        assert captured.out.strip() == expected_result
Exemplo n.º 4
0
def test_purge_creds():
    with fake_creds('.jovian-purge-creds', 'credentials.json'):
        os.makedirs(credentials.CONFIG_DIR, exist_ok=True)
        os.system(
            'touch jovian/tests/resources/creds/.jovian-purge-creds/credentials.json'
        )
        assert os.path.exists(
            'jovian/tests/resources/creds/.jovian-purge-creds/credentials.json'
        ) == True
        purge_creds()
        assert os.path.exists(
            'jovian/tests/resources/creds/.jovian-purge-creds/credentials.json'
        ) == False
Exemplo n.º 5
0
def reset_config(confirm=True):
    """Remove the existing configuration by purging credentials"""
    if creds_exist():
        if confirm:
            msg = 'Do you want to remove the existing configuration?'
            confirmed = click.confirm(msg)
        else:
            confirmed = True

        if confirmed:
            log('Removing existing configuration. Run "jovian configure" to set up Jovian')
            purge_creds()
        else:
            log('Skipping..')
            return
    else:
        log('Jovian is not configured yet. Run "jovian configure" to set it up.')
Exemplo n.º 6
0
def test_configure_no_creds(mock_prompt, mock_validate_api_key, mock_get, capsys):
    with fake_creds():
        purge_creds()

        configure()

        assert read_creds() == {'API_KEY': 'fake_api_key',
                                'API_URL': 'https://api-staging.jovian.ai',
                                'GUEST_KEY': ANY,
                                'ORG_ID': 'staging',
                                'WEBAPP_URL': 'https://staging.jovian.ai/'}

        expected_result = dedent("""
        [jovian] If you're a jovian-pro user please enter your company's organization ID on Jovian (otherwise leave it blank).
        [jovian] Please enter your API key ( from https://staging.jovian.ai/ ):
        [jovian] Configuration complete!
        """).strip()

        captured = capsys.readouterr()
        assert captured.out.strip() == expected_result.strip()
Exemplo n.º 7
0
def test_read_creds_no_creds_folder():
    with fake_creds():
        purge_creds()
        assert read_creds() == {}
Exemplo n.º 8
0
def test_read_creds_no_creds_folder():
    with fake_creds('.jovian-no-creds', 'credentials.json'):
        purge_creds()
        assert read_creds() == {}