Esempio n. 1
0
def test_configure_confirm_no(mock_confirm, capsys):
    with fake_creds():
        creds = read_creds()
        configure()

        # Check that creds were not modified
        assert read_creds() == creds

        expected_result = dedent("""
        [jovian] It looks like Jovian is already configured ( check ~/.jovian/credentials.json ).
        [jovian] Skipping..
        """).strip()
        captured = capsys.readouterr()
        assert captured.out.strip() == expected_result.strip()
Esempio n. 2
0
def _capture_environment(environment, gist_slug, version):
    """Capture the python environment and attach it to the commit"""
    if environment is not None:
        # Check credentials if environment config exists
        creds = read_creds()
        if 'DEFAULT_CONFIG' in creds and 'environment' in creds['DEFAULT_CONFIG']:
            environment_config = creds['DEFAULT_CONFIG']['environment']
            if not environment_config:
                # Disable environment capture
                return
            if environment == 'auto' and (environment_config == 'conda' or environment_config == 'pip'):
                environment = environment_config

        log('Capturing environment..')
        captured = False

        if environment == 'auto' or environment == 'conda':
            # Capture conda environment
            try:
                upload_conda_env(gist_slug, version)
                captured = True
            except CondaError as e:
                log(str(e), error=True)

        if not captured and (environment == 'pip' or environment == 'auto'):
            # Capture pip environment
            try:
                upload_pip_env(gist_slug, version)
            except Exception as e:
                log(str(e), error=True)
Esempio n. 3
0
def test_read_creds_folder_exists():
    with fake_creds():
        expected_result = {
            "WEBAPP_URL": "https://staging.jovian.ai/",
            "GUEST_KEY": "b6538d4dfde04fcf993463a828a9cec6",
            "ORG_ID": "staging",
            "API_URL": "https://api-staging.jovian.ai",
            "API_KEY": "fake_api_key"
        }
        assert read_creds() == expected_result
Esempio n. 4
0
def test_write_creds():
    with fake_creds():
        creds = {
            "WEBAPP_URL": "https://staging.jovian.ai/",
            "GUEST_KEY": "b6538d4dfde04fcf993463a828a9cec6",
            "ORG_ID": "staging",
            "API_URL": "https://api-staging.jovian.ai"
        }
        write_creds(creds)

        assert read_creds() == creds
Esempio n. 5
0
def test_write_cred_already_exists():
    with fake_creds():
        creds = {
            "WEBAPP_URL": "https://staging.jovian.ai/",
            "GUEST_KEY": "b6538d4dfde04fcf993463a828a9cec6",
            "ORG_ID": "staging",
            "API_URL": "https://api-staging.jovian.ai"
        }
        write_creds(creds)

        write_cred('ORG_ID', 'staging')

        expected_result = creds
        assert read_creds() == expected_result
Esempio n. 6
0
def _attach_files(paths, gist_slug, version, output=False, exclude_files=None):
    """Helper functions to attach files & folders to a commit"""
    config = read_creds().get("DEFAULT_CONFIG", {})

    whitelist = config.get("EXTENSION_WHITELIST")
    upload_wd = config.get("UPLOAD_WORKING_DIRECTORY", False)

    if not isinstance(whitelist, list):
        whitelist = DEFAULT_EXTENSION_WHITELIST

    if not paths:
        if output or not upload_wd:
            return

        paths = [
            f for f in glob.glob('**/*', recursive=True)
            if get_file_extension(f) in whitelist
        ]

    if exclude_files:
        if not isinstance(exclude_files, list):
            exclude_files = [exclude_files]

        for filename in exclude_files:
            try:
                paths.remove(filename)
            except ValueError:
                pass

    log('Uploading additional ' + ('outputs' if output else 'files') + '...')

    # Convert single path to list
    if type(paths) == str:
        paths = [paths]

    for path in paths:
        if os.path.isdir(path):
            files = [
                f
                for f in glob.glob(os.path.join(path, '**/*'), recursive=True)
                if get_file_extension(f) in whitelist
            ]
            for file in files:
                _attach_file(file, gist_slug, version, output)
        elif os.path.exists(path):
            _attach_file(path, gist_slug, version, output)
        else:
            log('Ignoring "' + path + '" (not found)', error=True)
Esempio n. 7
0
def test_purge_cred_key():
    with fake_creds():
        creds = {
            "WEBAPP_URL": "https://staging.jovian.ai/",
            "GUEST_KEY": "b6538d4dfde04fcf993463a828a9cec6",
            "ORG_ID": "staging",
            "API_URL": "https://api-staging.jovian.ai"
        }
        write_creds(creds)

        purge_cred_key('GUEST_KEY')

        expected_result = {
            "WEBAPP_URL": "https://staging.jovian.ai/",
            "ORG_ID": "staging",
            "API_URL": "https://api-staging.jovian.ai"
        }

        assert read_creds() == expected_result
Esempio n. 8
0
def test_write_cred():
    with fake_creds():
        creds = {
            "WEBAPP_URL": "https://staging.jovian.ai/",
            "GUEST_KEY": "b6538d4dfde04fcf993463a828a9cec6",
            "ORG_ID": "staging",
            "API_URL": "https://api-staging.jovian.ai"
        }
        write_creds(creds)

        write_cred('FAKE_KEY', 'fake_value')

        expected_result = {
            "WEBAPP_URL": "https://staging.jovian.ai/",
            "GUEST_KEY": "b6538d4dfde04fcf993463a828a9cec6",
            "ORG_ID": "staging",
            "API_URL": "https://api-staging.jovian.ai",
            "FAKE_KEY": "fake_value"
        }
        assert read_creds() == expected_result
Esempio n. 9
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()
Esempio n. 10
0
def test_configure_confirm_yes(mock_confirm, mock_prompt,
                               mock_validate_api_key, mock_get, capsys):
    with fake_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.ml/'
        }

        expected_result = dedent("""
        [jovian] It looks like Jovian is already configured ( check ~/.jovian/credentials.json ).
        [jovian] Removing existing configuration..
        [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.ml/ ):
        [jovian] Configuration complete!
        """).strip()

        captured = capsys.readouterr()
        assert captured.out.strip() == expected_result.strip()
Esempio n. 11
0
def test_read_creds_no_creds_folder():
    with fake_creds():
        purge_creds()
        assert read_creds() == {}
Esempio n. 12
0
def test_read_creds_with_value_error(mock_json_load, mock_purge_creds):
    with fake_creds():
        assert read_creds() == {}
Esempio n. 13
0
def test_read_creds_no_creds_folder():
    with fake_creds('.jovian-no-creds', 'credentials.json'):
        purge_creds()
        assert read_creds() == {}
Esempio n. 14
0
def test_read_creds_with_value_error(mock_json_load, mock_purge_creds):
    with fake_creds('.jovian', 'credentials.json'):
        assert read_creds() == {}