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: validate datetime on check #24252

Merged
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.2.25
LABEL io.airbyte.version=0.2.26
LABEL io.airbyte.name=airbyte/source-zendesk-support
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

import base64
import logging
from datetime import datetime
from typing import Any, List, Mapping, Tuple

import requests
from airbyte_cdk.models import SyncMode
from airbyte_cdk.sources import AbstractSource
from airbyte_cdk.sources.streams import Stream
from airbyte_cdk.sources.streams.http.requests_native_auth import TokenAuthenticator
from source_zendesk_support.streams import SourceZendeskException
from source_zendesk_support.streams import SourceZendeskException, DATETIME_FORMAT

from .streams import (
Brands,
Expand Down Expand Up @@ -82,8 +82,9 @@ def check_connection(self, logger, config) -> Tuple[bool, any]:
auth = self.get_authenticator(config)
settings = None
try:
datetime.strptime(config["start_date"], DATETIME_FORMAT)
settings = UserSettingsStream(config["subdomain"], authenticator=auth, start_date=None).get_settings()
except requests.exceptions.RequestException as e:
except Exception as e:
davydov-d marked this conversation as resolved.
Show resolved Hide resolved
return False, e

active_features = [k for k, v in settings.get("active_features", {}).items() if v]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


import calendar
import copy
import re
from datetime import datetime
from unittest.mock import patch
Expand Down Expand Up @@ -117,17 +118,21 @@ def test_get_authenticator(config, expected):


@pytest.mark.parametrize(
"response, check_passed",
"response, start_date, check_passed",
[
({"active_features": {"organization_access_enabled": True}}, (True, None)),
({"active_features": {"organization_access_enabled": True}}, "2020-01-01T00:00:00Z", True),
({}, "2020-01-00T00:00:00Z", False)
],
ids=["check_connection"],
ids=["check_successful", "invalid_start_date"],
)
def test_check(response, check_passed):
def test_check(response, start_date, check_passed):
config = copy.deepcopy(TEST_CONFIG)
config["start_date"] = start_date
with patch.object(UserSettingsStream, "get_settings", return_value=response) as mock_method:
result = SourceZendeskSupport().check_connection(logger=AirbyteLogger, config=TEST_CONFIG)
mock_method.assert_called()
assert check_passed == result
ok, _ = SourceZendeskSupport().check_connection(logger=AirbyteLogger, config=config)
assert check_passed == ok
if ok:
mock_method.assert_called()


@pytest.mark.parametrize(
Expand Down
5 changes: 3 additions & 2 deletions docs/integrations/sources/zendesk-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ The Zendesk connector ideally should not run into Zendesk API limitations under

| Version | Date | Pull Request | Subject |
|:---------|:-----------|:---------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `0.2.25` | 2023-02-28 | [22308](https://github.com/airbytehq/airbyte/pull/22308) | Add `AvailabilityStrategy` for all streams |
| `0.2.24` | 2023-02-17 | [23246](https://github.com/airbytehq/airbyte/pull/23246) | Handle `StartTimeTooRecent` error for Tickets stream |
| `0.2.26` | 2023-03-20 | [24252](https://github.com/airbytehq/airbyte/pull/24252) | Handle invalid `start_date` when checking connection |
| `0.2.25` | 2023-02-28 | [22308](https://github.com/airbytehq/airbyte/pull/22308) | Add `AvailabilityStrategy` for all streams |
| `0.2.24` | 2023-02-17 | [23246](https://github.com/airbytehq/airbyte/pull/23246) | Handle `StartTimeTooRecent` error for Tickets stream |
| `0.2.23` | 2023-02-15 | [23035](https://github.com/airbytehq/airbyte/pull/23035) | Handle 403 Error |
| `0.2.22` | 2023-02-14 | [22483](https://github.com/airbytehq/airbyte/pull/22483) | Fix test; handle 400 error |
| `0.2.21` | 2023-01-27 | [22027](https://github.com/airbytehq/airbyte/pull/22027) | Set `AvailabilityStrategy` for streams explicitly to `None` |
Expand Down