Exemple #1
0
def test_post_blocks_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)

        blocks = [{"data": {"key": "value"}, "record_type": "metrics"}]

        with pytest.raises(ApiError) as context:
            post_blocks(blocks)

        mock_requests_post.assert_called_with(
            "https://api-staging.jovian.ai/data/record",
            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=[{"data": {"key": "value"}, "record_type": "metrics"}],
        )

        assert (
            str(context.value)
            == "Data logging failed: (HTTP 500) Internal Server Error"
        )
Exemple #2
0
def test_post_blocks(mock_requests_post):

    with fake_creds():
        blocks = [{"data": {"key": "value"}, "record_type": "metrics"}]
        post_blocks(blocks)

        mock_requests_post.assert_called_with(
            "https://api-staging.jovian.ai/data/record",
            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=[{"data": {"key": "value"}, "record_type": "metrics"}],
        )
Exemple #3
0
    def test_post_blocks(self, mock_requests_post):

        with fake_creds('.jovian', 'credentials.json'):
            blocks = [{'data': {'key': 'value'}, 'record_type': 'metrics'}]
            post_blocks(blocks)

            mock_requests_post.assert_called_with(
                'https://api-staging.jovian.ai/data/record',
                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=[{
                    'data': {
                        'key': 'value'
                    },
                    'record_type': 'metrics'
                }])
Exemple #4
0
    def test_post_blocks_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)

            blocks = [{'data': {'key': 'value'}, 'record_type': 'metrics'}]

            with self.assertRaises(ApiError) as context:
                post_blocks(blocks)

            mock_requests_post.assert_called_with(
                'https://api-staging.jovian.ai/data/record',
                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=[{
                    'data': {
                        'key': 'value'
                    },
                    'record_type': 'metrics'
                }])

            assert context.exception.args[
                0] == 'Data logging failed: (HTTP 500) Internal Server Error'