Skip to content

✨ Source Zendesk Support: tickets to low-code #55711

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

Open
wants to merge 8 commits into
base: issue-11894/user-identities-to-low-code
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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 @@ -700,6 +700,23 @@ definitions:
cursor_field: "updated_at"
primary_key: "id"

tickets_stream:
$ref: "#/definitions/base_incremental_stream"
retriever:
$ref: "#/definitions/retriever"
ignore_stream_slicer_parameters_on_paginated_requests: true
paginator:
$ref: "#/definitions/after_url_paginator"
pagination_strategy:
$ref: "#/definitions/after_url_paginator/pagination_strategy"
stop_condition: "{{ config.get('ignore_pagination', False) or response.get('end_of_stream') }}"
$parameters:
name: "tickets"
path: "incremental/tickets/cursor.json"
cursor_field: "generated_timestamp"
cursor_filter: "start_time"
primary_key: "id"

topics_stream:
$ref: "#/definitions/semi_incremental_stream"
retriever:
Expand Down Expand Up @@ -790,6 +807,7 @@ streams:
- $ref: "#/definitions/ticket_comments_stream"
- $ref: "#/definitions/ticket_metric_events_stream"
- $ref: "#/definitions/ticket_skips_stream"
- $ref: "#/definitions/tickets_stream"
- $ref: "#/definitions/triggers_stream"
- $ref: "#/definitions/users_stream"
- $ref: "#/definitions/users_identities_stream"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
Articles,
ArticleVotes,
TicketMetrics,
Tickets,
UserSettingsStream,
)

Expand Down Expand Up @@ -117,7 +116,6 @@ def get_nested_streams(self, config: Mapping[str, Any]) -> List[Stream]:
ArticleComments(**args),
ArticleCommentVotes(**args),
ArticleVotes(**args),
Tickets(**args),
TicketMetrics(**args),
]
return streams
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,20 +243,6 @@ def test_check_start_time_param():
assert output == expected


@pytest.mark.parametrize(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some cleanup here but I didn't remove the import because we still have TicketMetrics which uses the Python implementation of Tickets. My guess is that this whole file will just be deleted soon anyway

"stream_state, expected",
[
# valid state, expect the value of the state
({"generated_timestamp": 1648771200}, 1648771200),
(None, 1622505600),
],
ids=["state present", "state is None"],
)
def test_check_stream_state(stream_state, expected):
result = Tickets(**STREAM_ARGS).get_stream_state_value(stream_state)
assert result == expected


def test_parse_response_from_empty_json(requests_mock):
requests_mock.get(STREAM_URL, text="", status_code=403)
test_response = requests.get(STREAM_URL)
Expand Down Expand Up @@ -302,7 +288,6 @@ def test_ticket_forms_exception_stream(self):
(StatelessTicketMetrics, "ticket_metrics"),
(TicketSkips, "skips.json"),
(TicketMetricEvents, "incremental/ticket_metric_events"),
(Tickets, "incremental/tickets/cursor.json"),
(Topics, "community/topics"),
(Brands, "brands"),
(CustomRoles, "custom_roles"),
Expand Down Expand Up @@ -331,7 +316,6 @@ def test_ticket_forms_exception_stream(self):
"StatelessTicketMetrics",
"TicketSkips",
"TicketMetricEvents",
"Tickets",
"Topics",
"Brands",
"CustomRoles",
Expand Down Expand Up @@ -692,91 +676,6 @@ def test_request_params(self, stream_cls, expected):
assert expected == result


class TestSourceZendeskIncrementalExportStream:
@pytest.mark.parametrize(
"stream_cls",
[
(Tickets),
],
ids=[
"Tickets",
],
)
def test_check_start_time_param(self, stream_cls):
expected = int(dict(parse_qsl(urlparse(STREAM_URL).query)).get("start_time"))
stream = stream_cls(**STREAM_ARGS)
result = stream.validate_start_time(expected)
assert result == expected

@pytest.mark.parametrize(
"stream_cls",
[
(Tickets),
],
ids=[
"Tickets",
],
)
def test_next_page_token(self, requests_mock, stream_cls):
stream = stream_cls(**STREAM_ARGS)
stream_name = snake_case(stream.__class__.__name__)
requests_mock.get(STREAM_URL, json={stream_name: {}})
test_response = requests.get(STREAM_URL)
output = stream.next_page_token(test_response)
assert output == {}

@pytest.mark.parametrize(
"stream_cls, expected",
[
(Tickets, {"start_time": 1622505600}),
(Articles, {"sort_by": "updated_at", "sort_order": "asc", "start_time": 1622505600}),
],
ids=[
"Tickets",
"Articles",
],
)
def test_request_params(self, stream_cls, expected):
stream = stream_cls(**STREAM_ARGS)
result = stream.request_params(next_page_token=None, stream_state=None)
assert expected == result

@pytest.mark.parametrize(
"stream_cls",
[
(Tickets),
],
ids=[
"Tickets",
],
)
def test_parse_response(self, requests_mock, stream_cls):
stream = stream_cls(**STREAM_ARGS)
stream_name = snake_case(stream.__class__.__name__)
expected = [{"updated_at": "2022-03-17T16:03:07Z"}]
requests_mock.get(STREAM_URL, json={stream_name: expected})
test_response = requests.get(STREAM_URL)
output = list(stream.parse_response(test_response))
assert expected == output

@pytest.mark.parametrize(
"stream_cls, stream_slice, expected_path",
[
(ArticleVotes, {"parent": {"id": 1}}, "help_center/articles/1/votes"),
(ArticleComments, {"parent": {"id": 1}}, "help_center/articles/1/comments"),
(ArticleCommentVotes, {"parent": {"id": 1, "source_id": 1}}, "help_center/articles/1/comments/1/votes"),
],
ids=[
"ArticleVotes_path",
"ArticleComments_path",
"ArticleCommentVotes_path",
],
)
def test_path(self, stream_cls, stream_slice, expected_path):
stream = stream_cls(**STREAM_ARGS)
assert stream.path(stream_slice=stream_slice) == expected_path


class TestSourceZendeskSupportTicketEventsExportStream:
@pytest.mark.parametrize(
"stream_cls, expected",
Expand Down Expand Up @@ -880,42 +779,6 @@ def test_event_type(self, stream_cls, expected):
assert result == expected


def test_read_tickets_stream(requests_mock):
requests_mock.get(
"https://subdomain.zendesk.com/api/v2/incremental/tickets/cursor.json",
json={
"tickets": [
{"custom_fields": []},
{},
{
"custom_fields": [
{"id": 360023382300, "value": None},
{"id": 360004841380, "value": "customer_tickets"},
{"id": 360022469240, "value": "5"},
{"id": 360023712840, "value": False},
]
},
],
"end_of_stream": True,
},
)

stream = Tickets(subdomain="subdomain", start_date="2020-01-01T00:00:00Z")
records = read_full_refresh(stream)
assert records == [
{"custom_fields": []},
{},
{
"custom_fields": [
{"id": 360023382300, "value": None},
{"id": 360004841380, "value": "customer_tickets"},
{"id": 360022469240, "value": "5"},
{"id": 360023712840, "value": "False"},
]
},
]


def test_read_ticket_metric_events_request_params(requests_mock):
first_page_response = {
"ticket_metric_events": [
Expand Down Expand Up @@ -992,16 +855,6 @@ def test_read_tickets_comment(requests_mock, status_code):
assert request_history.call_count == 1


def test_read_non_json_error(requests_mock, caplog):
requests_mock.get("https://subdomain.zendesk.com/api/v2/incremental/tickets/cursor.json", text="not_json_response")
stream = Tickets(subdomain="subdomain", start_date="2020-01-01T00:00:00Z")
expected_message = (
"Skipping stream tickets: Non-JSON response received. Please ensure that you have enough permissions for this stream."
)
read_full_refresh(stream)
assert expected_message in (record.message for record in caplog.records if record.levelname == "ERROR")


class TestTicketMetrics:
@pytest.mark.parametrize(
"state, expected_implemented_stream",
Expand Down
Loading