Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vdk-plugins] vdk-ingest-http: Adopt simplejson in place of json #1229

Merged
merged 2 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions projects/vdk-plugins/vdk-ingest-http/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
pytest
pytest-httpserver
requests
simplejson
vdk-core
vdk-test-utils
2 changes: 1 addition & 1 deletion projects/vdk-plugins/vdk-ingest-http/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
description="Versatile Data Kit SDK ingestion plugin to ingest data via http requests.",
long_description=pathlib.Path("README.md").read_text(),
long_description_content_type="text/markdown",
install_requires=["vdk-core"],
install_requires=["vdk-core", "simplejson"],
package_dir={"": "src"},
packages=setuptools.find_namespace_packages(where="src"),
entry_points={
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright 2021 VMware, Inc.
# SPDX-License-Identifier: Apache-2.0
import gzip
import json
import logging
import sys
from typing import Dict
Expand All @@ -10,6 +9,7 @@
from typing import Optional

import requests
import simplejson as json
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry
from vdk.internal.builtin_plugins.ingestion.ingester_base import IIngesterPlugin
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Copyright 2021 VMware, Inc.
# SPDX-License-Identifier: Apache-2.0
import gzip
import json
import sys
from decimal import Decimal
from unittest import mock
from unittest.mock import MagicMock

import pytest
import simplejson as json
from vdk.internal.core.errors import PlatformServiceError
from vdk.internal.core.errors import UserCodeError
from vdk.internal.core.errors import VdkConfigurationError
Expand Down Expand Up @@ -231,7 +232,31 @@ def arg(a):
)


@mock.patch("json.dumps")
@mock.patch("requests.Session.post", side_effect=mocked_requests_post)
def test_ingest_over_http_special_type(mock_post):
http_ingester: IngestOverHttp = IngestOverHttp(job_context)
payload["decimal"] = Decimal(15.5)
http_ingester.ingest_payload(
payload=[payload],
destination_table="test_table",
target="http://example.com/data-source",
)

assert mock_post.call_count == 1

payload["@table"] = "test_table"

mock_post.assert_called_with(
url="http://example.com/data-source",
data=json.dumps([payload]),
headers={"Content-Type": "application/octet-stream"},
timeout=(None, None),
cert=None,
verify=None,
)


@mock.patch("simplejson.dumps")
def test_ingest_over_http_json_dumps_parameters_propagation(mock_jsondumps):
allow_nan = True

Expand Down