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

🐛 Source Zendesk Support: Fix wrong types for schemas, add Transformer #8050

Merged
Show file tree
Hide file tree
Changes from 2 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ COPY source_zendesk_support ./source_zendesk_support
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]

LABEL io.airbyte.version=0.1.4
LABEL io.airbyte.version=0.1.5
LABEL io.airbyte.name=airbyte/source-zendesk-support
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from setuptools import find_packages, setup

MAIN_REQUIREMENTS = ["airbyte-cdk~=0.1.23", "pytz"]
MAIN_REQUIREMENTS = ["airbyte-cdk~=0.1.36", "pytz"]

TEST_REQUIREMENTS = ["pytest~=6.1", "source-acceptance-test", "requests-mock==1.9.3"]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"type": ["null", "object"],
"properties": {
"custom": {},
"custom": {
"type": ["null", "object"]
},
"trusted": {
"type": ["null", "boolean"]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@
"business_hours": {
"type": ["null", "boolean"]
},
"metric": {}
"metric": {
"type": ["null", "string"]
}
},
"type": ["null", "object"]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@
"formatted_to": {
"type": ["null", "string"]
},
"transcription_visible": {},
"transcription_visible": {
"type": ["null", "boolean"]
},
"trusted": {
"type": ["null", "boolean"]
},
Expand All @@ -142,10 +144,7 @@
"type": ["null", "integer"]
},
"value": {
"type": ["null", "array", "string"],
"items": {
"type": ["null", "string"]
}
"type": ["null", "string"]
},
"author_id": {
"type": ["null", "integer"]
Expand Down Expand Up @@ -237,10 +236,7 @@
"type": ["null", "integer"]
},
"previous_value": {
"type": ["null", "array", "string"],
"items": {
"type": ["null", "string"]
}
"type": ["null", "string"]
},
"macro_title": {
"type": ["null", "string"]
Expand All @@ -260,7 +256,9 @@
"metadata": {
"type": ["null", "object"],
"properties": {
"custom": {},
"custom": {
"type": ["null", "object"]
},
"trusted": {
"type": ["null", "boolean"]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@
"type": ["null", "boolean"]
},
"system_field_options": {
"type": ["null", "array"],
"items": {}
"type": ["null", "array"]
},
"sub_type_id": {
"type": ["null", "integer"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@
"id": {
"type": ["null", "integer"]
},
"value": {}
"value": {
"type": ["null", "string"]
}
},
"type": ["null", "object"]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from airbyte_cdk.models import SyncMode
from airbyte_cdk.sources.streams.http import HttpStream
from airbyte_cdk.sources.streams.http.auth.core import HttpAuthenticator
from airbyte_cdk.sources.utils.transform import TransformConfig, TypeTransformer

DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
LAST_END_TIME_KEY = "_last_end_time"
Expand All @@ -34,6 +35,8 @@ class SourceZendeskSupportStream(HttpStream, ABC):
created_at_field = "created_at"
updated_at_field = "updated_at"

transformer = TypeTransformer(TransformConfig.DefaultSchemaNormalization)

def __init__(self, subdomain: str, **kwargs):
super().__init__(**kwargs)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
#

import json
from unittest.mock import Mock
from unittest.mock import MagicMock, Mock

import pytest
import requests
import requests_mock
from airbyte_cdk.models import AirbyteStream, ConfiguredAirbyteCatalog, ConfiguredAirbyteStream, DestinationSyncMode, SyncMode
from requests.exceptions import HTTPError
from source_zendesk_support import SourceZendeskSupport
from source_zendesk_support.streams import Tags, TicketComments
Expand All @@ -22,6 +23,16 @@ def prepare_stream_args():
return SourceZendeskSupport.convert_config2stream_args(json.loads(f.read()))


@pytest.fixture(scope="module")
def config():
"""Generates fake config"""
return {
"subdomain": "fake_domain",
"start_date": "2020-01-01T00:00:00Z",
"auth_method": {"auth_method": "api_token", "email": "email@email.com", "api_token": "fake_api_token"},
}


@pytest.mark.parametrize(
"header_name,header_value,expected",
[
Expand Down Expand Up @@ -94,3 +105,45 @@ def test_comments_not_found_ticket(prepare_stream_args, status_code, expected_co
next(comments)
else:
assert len(list(comments)) == expected_comment_count


@pytest.mark.parametrize(
"input_data,expected_data",
[
(
{"id": 123, "custom_fields": [{"id": 3213212, "value": ["fake_3000", "fake_5555"]}]},
{"id": 123, "custom_fields": [{"id": 3213212, "value": "['fake_3000', 'fake_5555']"}]},
),
(
{"id": 234, "custom_fields": [{"id": 2345234, "value": "fake_123"}]},
{"id": 234, "custom_fields": [{"id": 2345234, "value": "fake_123"}]},
),
(
{"id": 345, "custom_fields": [{"id": 5432123, "value": 55432.321}]},
{"id": 345, "custom_fields": [{"id": 5432123, "value": "55432.321"}]},
),
],
)
def test_transform_for_tickets_stream(config, input_data, expected_data):
"""Checks Transform in case when records come with invalid fields data types"""
test_catalog = ConfiguredAirbyteCatalog(
streams=[
ConfiguredAirbyteStream(
stream=AirbyteStream(name="tickets", json_schema={}),
sync_mode=SyncMode.full_refresh,
destination_sync_mode=DestinationSyncMode.overwrite,
)
]
)

with requests_mock.Mocker() as ticket_mock:
ticket_mock.get(
f"https://{config['subdomain']}.zendesk.com/api/v2/incremental/tickets.json",
status_code=200,
json={"tickets": [input_data], "end_time": "2021-07-22T06:55:55Z", "end_of_stream": True},
)

source = SourceZendeskSupport()
records = source.read(MagicMock(), config, test_catalog, None)
for record in records:
assert record.record.data == expected_data
1 change: 1 addition & 0 deletions docs/integrations/sources/zendesk-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ We recommend creating a restricted, read-only key specifically for Airbyte acces

| Version | Date | Pull Request | Subject |
| :------ | :-------- | :----- | :------ |
| `0.1.5` | 2021-11-?? | [????](https://github.com/airbytehq/airbyte/pull/????) | Fix wrong types for schemas, add Transformer |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forgot to update this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am going to request review from Airbyte team for this PR, and update the changeogs before publishing.

| `0.1.4` | 2021-10-26 | [7377](https://github.com/airbytehq/airbyte/pull/7377) | fix initially_assigned_at type in ticket metrics |
| `0.1.3` | 2021-10-17 | [7097](https://github.com/airbytehq/airbyte/pull/7097) | correction of spec file |
| `0.1.2` | 2021-10-16 | [6513](https://github.com/airbytehq/airbyte/pull/6513) | fixed comments stream |
Expand Down