예제 #1
0
    def test_post_records_raises_api_error(self, mock_requests_post,
                                           mock_get_api_key):
        with fake_creds('.jovian-invalid-key', 'credentials.json'):
            # setUp
            creds = {
                "WEBAPP_URL": "https://staging.jovian.ml/",
                "GUEST_KEY": "b6538d4dfde04fcf993463a828a9cec6",
                "API_URL": "https://api-staging.jovian.ai",
                "API_KEY": "fake_invalid_api_key",
                "ORG_ID": "staging"
            }
            write_creds(creds)

            with self.assertRaises(ApiError) as context:
                post_records('fake_gist_slug', {'key': 'value'})

            mock_requests_post.assert_called_with(
                'https://api-staging.jovian.ai/data/fake_gist_slug/commit',
                data=None,
                headers={
                    "Authorization": "Bearer fake_invalid_api_key",
                    "x-jovian-source": "library",
                    "x-jovian-library-version": __version__,
                    "x-jovian-guest": "b6538d4dfde04fcf993463a828a9cec6",
                    "x-jovian-org": "staging"
                },
                json={'key': 'value'})

            assert context.exception.args[
                0] == 'Data logging failed: (HTTP 404) Gist not found'
예제 #2
0
def test_post_records_raises_api_error(mock_requests_post, mock_get_api_key):
    with fake_creds():
        # setUp
        creds = {
            "WEBAPP_URL": "https://staging.jovian.ml/",
            "GUEST_KEY": "b6538d4dfde04fcf993463a828a9cec6",
            "API_URL": "https://api-staging.jovian.ai",
            "API_KEY": "fake_invalid_api_key",
            "ORG_ID": "staging",
        }
        write_creds(creds)

        with pytest.raises(ApiError) as context:
            post_records("fake_gist_slug", {"key": "value"})

        mock_requests_post.assert_called_with(
            "https://api-staging.jovian.ai/data/fake_gist_slug/commit",
            data=None,
            headers={
                "Authorization": "Bearer fake_invalid_api_key",
                "x-jovian-source": "library",
                "x-jovian-library-version": __version__,
                "x-jovian-guest": "b6538d4dfde04fcf993463a828a9cec6",
                "x-jovian-org": "staging",
            },
            json={"key": "value"},
        )

        assert (
            str(context.value)
            == "Data logging failed: (HTTP 404) Gist not found"
        )
예제 #3
0
 def test_post_records(self, mock_requests_post):
     with fake_creds('.jovian', 'credentials.json'):
         post_records('fake_gist_slug', {'key': 'value'})
         mock_requests_post.assert_called_with(
             'https://api-staging.jovian.ai/data/fake_gist_slug/commit',
             data=None,
             headers={
                 "Authorization": "Bearer fake_api_key",
                 "x-jovian-source": "library",
                 "x-jovian-library-version": __version__,
                 "x-jovian-guest": "b6538d4dfde04fcf993463a828a9cec6",
                 "x-jovian-org": "staging"
             },
             json={'key': 'value'})
예제 #4
0
def test_post_records(mock_requests_post):
    with fake_creds():
        post_records("fake_gist_slug", {"key": "value"})
        mock_requests_post.assert_called_with(
            "https://api-staging.jovian.ai/data/fake_gist_slug/commit",
            data=None,
            headers={
                "Authorization": "Bearer fake_api_key",
                "x-jovian-source": "library",
                "x-jovian-library-version": __version__,
                "x-jovian-guest": "b6538d4dfde04fcf993463a828a9cec6",
                "x-jovian-org": "staging",
            },
            json={"key": "value"},
        )
예제 #5
0
파일: commit.py 프로젝트: Mynkxb/jovian-py
def _attach_records(gist_slug, version):
    """Attached records to the current commit"""
    tracking_slugs = get_records(slug_only=True)
    if len(tracking_slugs) > 0:
        log('Attaching records (metrics, hyperparameters, dataset etc.)')
        api.post_records(gist_slug, tracking_slugs, version)