-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add mock server test for semi-incremental syncs
- Loading branch information
Showing
10 changed files
with
197 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...yte-integrations/connectors/source-zendesk-support/unit_tests/integrations/test_groups.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
|
||
from datetime import datetime, timezone | ||
from unittest import TestCase | ||
|
||
import pendulum | ||
from airbyte_cdk.models import SyncMode | ||
from airbyte_cdk.test.mock_http import HttpMocker | ||
from airbyte_cdk.test.state_builder import StateBuilder | ||
|
||
from .config import ConfigBuilder | ||
from .helpers import given_groups_with_later_records | ||
from .utils import datetime_to_string, read_stream, string_to_datetime | ||
from .zs_requests.request_authenticators import ApiTokenAuthenticator | ||
|
||
_NOW = datetime.now(timezone.utc) | ||
|
||
|
||
class TestGroupsStreamFullRefresh(TestCase): | ||
@property | ||
def _config(self): | ||
return ( | ||
ConfigBuilder() | ||
.with_basic_auth_credentials("user@example.com", "password") | ||
.with_subdomain("d3v-airbyte") | ||
.with_start_date(pendulum.now(tz="UTC").subtract(years=2)) | ||
.build() | ||
) | ||
|
||
@staticmethod | ||
def get_authenticator(config): | ||
return ApiTokenAuthenticator(email=config["credentials"]["email"], password=config["credentials"]["api_token"]) | ||
|
||
@HttpMocker() | ||
def test_given_incoming_state_semi_incremental_groups_does_not_emit_earlier_record(self, http_mocker): | ||
""" | ||
Perform a semi-incremental sync where records that came before the current state are not included in the set | ||
of records emitted | ||
""" | ||
api_token_authenticator = self.get_authenticator(self._config) | ||
given_groups_with_later_records( | ||
http_mocker, | ||
string_to_datetime(self._config["start_date"]), | ||
pendulum.duration(weeks=12), | ||
api_token_authenticator, | ||
) | ||
|
||
output = read_stream("groups", SyncMode.full_refresh, self._config) | ||
assert len(output.records) == 2 | ||
|
||
@HttpMocker() | ||
def test_given_incoming_state_semi_incremental_groups_does_not_emit_earlier_record(self, http_mocker): | ||
""" | ||
Perform a semi-incremental sync where records that came before the current state are not included in the set | ||
of records emitted | ||
""" | ||
api_token_authenticator = self.get_authenticator(self._config) | ||
given_groups_with_later_records( | ||
http_mocker, | ||
string_to_datetime(self._config["start_date"]), | ||
pendulum.duration(weeks=12), | ||
api_token_authenticator, | ||
) | ||
|
||
state_value = { | ||
"updated_at": datetime_to_string(pendulum.now(tz="UTC").subtract(years=1, weeks=50)) | ||
} | ||
|
||
state = StateBuilder().with_stream_state("groups", state_value).build() | ||
|
||
output = read_stream("groups", SyncMode.full_refresh, self._config, state=state) | ||
assert len(output.records) == 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...rations/connectors/source-zendesk-support/unit_tests/integrations/zs_requests/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...tors/source-zendesk-support/unit_tests/integrations/zs_requests/groups_request_builder.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
|
||
import calendar | ||
|
||
import pendulum | ||
|
||
from .base_request_builder import ZendeskSupportBaseRequestBuilder | ||
from .request_authenticators.authenticator import Authenticator | ||
|
||
|
||
class GroupsRequestBuilder(ZendeskSupportBaseRequestBuilder): | ||
@classmethod | ||
def groups_endpoint(cls, authenticator: Authenticator) -> "GroupsRequestBuilder": | ||
return cls("d3v-airbyte", "groups").with_authenticator(authenticator) | ||
|
||
def __init__(self, subdomain: str, resource: str) -> None: | ||
super().__init__(subdomain, resource) | ||
self._page_size: int = None | ||
|
||
@property | ||
def query_params(self): | ||
params = super().query_params or {} | ||
if self._page_size: | ||
params["per_page"] = self._page_size | ||
return params | ||
|
||
def with_page_size(self, page_size: int) -> "PostCommentVotesRequestBuilder": | ||
self._page_size: int = page_size | ||
return self |
1 change: 1 addition & 0 deletions
1
...ations/connectors/source-zendesk-support/unit_tests/integrations/zs_responses/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...rs/source-zendesk-support/unit_tests/integrations/zs_responses/groups_response_builder.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
|
||
from airbyte_cdk.test.mock_http.response_builder import FieldPath, HttpResponseBuilder, find_template | ||
|
||
from .pagination_strategies import CursorBasedPaginationStrategy | ||
|
||
|
||
class GroupsResponseBuilder(HttpResponseBuilder): | ||
@classmethod | ||
def groups_response(cls) -> "GroupsResponseBuilder": | ||
return cls(find_template("groups", __file__), FieldPath("groups"), CursorBasedPaginationStrategy()) |
1 change: 1 addition & 0 deletions
1
...onnectors/source-zendesk-support/unit_tests/integrations/zs_responses/records/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...ce-zendesk-support/unit_tests/integrations/zs_responses/records/groups_records_builder.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
|
||
from airbyte_cdk.test.mock_http.response_builder import FieldPath, NestedPath | ||
|
||
from .records_builder import ZendeskSupportRecordBuilder | ||
|
||
|
||
class GroupsRecordBuilder(ZendeskSupportRecordBuilder): | ||
@classmethod | ||
def groups_record(cls) -> "GroupsRecordBuilder": | ||
record_template = cls.extract_record("groups", __file__, NestedPath(["groups", 0])) | ||
return cls(record_template, FieldPath("id"), FieldPath("updated_at")) |
15 changes: 15 additions & 0 deletions
15
...egrations/connectors/source-zendesk-support/unit_tests/resource/http/response/groups.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"groups": [ | ||
{ | ||
"created_at": "2024-11-20T00:00:00Z", | ||
"default": true, | ||
"deleted": false, | ||
"description": "Employed", | ||
"id": 3432, | ||
"is_public": true, | ||
"name": "Remote Employees", | ||
"updated_at": "2024-11-20T00:00:00Z", | ||
"url": "https://company.zendesk.com/api/v2/groups/3432.json" | ||
} | ||
] | ||
} |