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!')
def test_ensure_org_pro_raises_error(mock_is_flavor_pro, get_side_effect,
                                     request_org_id, creds, msg):
    with fake_creds(), \
            mock.patch("jovian.utils.credentials.request_org_id", return_value=request_org_id), \
            mock.patch("requests.get", side_effect=get_side_effect):

        write_creds(creds)

        with pytest.raises(ConfigError) as context:
            ensure_org()

        assert msg in str(context.value)
Exemple #3
0
    def test_ensure_org_api_url_key_error(self, mock_is_flavor_pro,
                                          mock_request_org_id,
                                          mock_requests_get):
        with fake_creds('.jovian-api-key-error', 'credentials.json'):
            # setUp
            creds = {
                "WEBAPP_URL": "https://staging.jovian.ml/",
                "GUEST_KEY": "b6538d4dfde04fcf993463a828a9cec6"
            }
            write_creds(creds)

            with self.assertRaises(ConfigError) as context:
                ensure_org()

            msg = "Failed to extract API_URL from JSON configuration file https://no-api-key.jovian.ml/config.json"
            self.assertTrue(msg in context.exception.args[0])
Exemple #4
0
    def test_ensure_org_some_creds_exist_default_org_id(
            self, mock_is_flavor_pro, mock_request_org_id, mock_requests_get):
        with fake_creds('.jovian-some-creds', 'credentials.json'):
            # setUp
            creds = {
                "WEBAPP_URL": "https://staging.jovian.ml/",
                "GUEST_KEY": "b6538d4dfde04fcf993463a828a9cec6",
                "API_URL": "https://api-staging.jovian.ai"
            }
            write_creds(creds)

            ensure_org()

            assert read_api_url() == "https://api.jovian.ai"
            assert read_org_id() == "public"
            assert read_webapp_url() == "https://jovian.ml/"
Exemple #5
0
    def test_ensure_org_with_json_decode_error(self, mock_is_flavor_pro,
                                               mock_request_org_id,
                                               mock_requests_get):
        with fake_creds('.jovian-decode-error', 'credentials.json'):
            # setUp
            creds = {
                "WEBAPP_URL": "https://staging.jovian.ml/",
                "GUEST_KEY": "b6538d4dfde04fcf993463a828a9cec6",
                "API_URL": "https://api-staging.jovian.ai"
            }
            write_creds(creds)

            with self.assertRaises(ConfigError) as context:
                ensure_org()

            msg = "Failed to parse JSON configuration file from https://jsonerror.jovian.ml/config.json"
            self.assertTrue(msg in context.exception.args[0])
Exemple #6
0
    def test_ensure_org_with_unsuccessful_response(self, mock_is_flavor_pro,
                                                   mock_request_org_id,
                                                   mock_requests_get):
        with fake_creds('.jovian-unsuccessful-response', 'credentials.json'):
            # setUp
            creds = {
                "WEBAPP_URL": "https://staging.jovian.ml/",
                "GUEST_KEY": "b6538d4dfde04fcf993463a828a9cec6",
                "API_URL": "https://api-staging.jovian.ai"
            }
            write_creds(creds)

            with self.assertRaises(ConfigError) as context:
                ensure_org()

            msg = "Request to retrieve configuration file https://fakecompany.jovian.ml/config.json failed with " + \
                  "status_code 500 . Looks like there's something wrong with your setup."
            self.assertTrue(msg in context.exception.args[0])
Exemple #7
0
    def test_ensure_org_with_connection_error(self, mock_is_flavor_pro,
                                              mock_request_org_id,
                                              mock_requests_get):
        with fake_creds('.jovian-connection-error', 'credentials.json'):
            # setUp
            creds = {
                "WEBAPP_URL": "https://staging.jovian.ml/",
                "GUEST_KEY": "b6538d4dfde04fcf993463a828a9cec6",
                "API_URL": "https://api-staging.jovian.ai"
            }
            write_creds(creds)

            with self.assertRaises(ConfigError) as context:
                ensure_org()

            msg = "Failed to connect to https://fakecompany.jovian.ml/ . Please verify your organization ID and " + \
                  "ensure you are connected to the internet."
            self.assertTrue(msg in context.exception.args[0])
def test_ensure_org_all_creds_exist(mock_is_flavor_pro):
    with fake_creds():
        assert ensure_org() == None
Exemple #9
0
 def test_ensure_org_all_creds_exist(self, mock_is_flavor_pro):
     with fake_creds('.jovian', 'credentials.json'):
         assert ensure_org() == None