-
Notifications
You must be signed in to change notification settings - Fork 4.9k
chore: source-freshdesk to cdk7 #67109
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
128 changes: 0 additions & 128 deletions
128
airbyte-integrations/connectors/source-freshdesk/components.py
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
This file contains hidden or 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
26 changes: 26 additions & 0 deletions
26
airbyte-integrations/connectors/source-freshdesk/unit_tests/integration/config_builder.py
This file contains hidden or 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,26 @@ | ||
| from datetime import datetime | ||
| from typing import Any, Mapping | ||
|
|
||
|
|
||
| class ConfigBuilder: | ||
| def __init__(self) -> None: | ||
| self._config = { | ||
| "api_key": "fake_api_key", | ||
| "domain": "any-domain.freshdesk.com", | ||
| "start_date": "2010-01-18T21:18:20Z", | ||
| } | ||
|
|
||
| def start_date(self, start_date: datetime) -> "ConfigBuilder": | ||
| self._config["start_date"] = start_date.strftime("%Y-%m-%dT%H:%M:%SZ") | ||
| return self | ||
|
|
||
| def api_key(self, api_key: str) -> "ConfigBuilder": | ||
| self._config["api_key"] = api_key | ||
| return self | ||
|
|
||
| def domain(self, domain: str) -> "ConfigBuilder": | ||
| self._config["domain"] = domain | ||
| return self | ||
|
|
||
| def build(self) -> Mapping[str, Any]: | ||
| return self._config |
119 changes: 119 additions & 0 deletions
119
airbyte-integrations/connectors/source-freshdesk/unit_tests/integration/test_tickets.py
This file contains hidden or 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,119 @@ | ||
| # Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
|
|
||
| import sys | ||
| from datetime import datetime | ||
| from pathlib import Path | ||
| from typing import Any, Dict, Optional | ||
| from unittest import TestCase | ||
|
|
||
| from airbyte_cdk import ConfiguredAirbyteCatalog, SyncMode, TState, YamlDeclarativeSource | ||
| from airbyte_cdk.test.catalog_builder import CatalogBuilder | ||
| from airbyte_cdk.test.entrypoint_wrapper import EntrypointOutput | ||
| from airbyte_cdk.test.entrypoint_wrapper import read as entrypoint_read | ||
| from airbyte_cdk.test.mock_http import HttpMocker, HttpRequest, HttpResponse | ||
| from airbyte_cdk.test.mock_http.response_builder import ( | ||
| FieldPath, | ||
| HttpResponseBuilder, | ||
| RecordBuilder, | ||
| create_record_builder, | ||
| create_response_builder, | ||
| find_template, RootPath, | ||
| ) | ||
| from airbyte_cdk.test.state_builder import StateBuilder | ||
|
|
||
| from config_builder import ConfigBuilder | ||
|
|
||
| PAGE_LIMIT_300TH_REACHED = '{"description":"Validation failed","errors":[{"field":"page","message":"You cannot access tickets beyond the 300th page. Please provide a smaller page number.","code":"invalid_value"}]}' | ||
|
|
||
|
|
||
| def _get_manifest_path() -> Path: | ||
| source_declarative_manifest_path = Path("/airbyte/integration_code/source_declarative_manifest") | ||
| if source_declarative_manifest_path.exists(): | ||
| return source_declarative_manifest_path | ||
| return Path(__file__).parent.parent.parent | ||
|
|
||
|
|
||
| _SOURCE_FOLDER_PATH = _get_manifest_path() | ||
| _YAML_FILE_PATH = _SOURCE_FOLDER_PATH / "manifest.yaml" | ||
|
|
||
| sys.path.append(str(_SOURCE_FOLDER_PATH)) # to allow loading custom components | ||
|
|
||
| _DOMAIN = "a-domain.freshdesk.com" | ||
| _API_KEY = "an_api_key" | ||
|
|
||
| def _catalog() -> ConfiguredAirbyteCatalog: | ||
| return CatalogBuilder().with_stream("tickets", SyncMode.full_refresh).build() | ||
|
|
||
|
|
||
| def _source(catalog: ConfiguredAirbyteCatalog, config: Dict[str, Any], state: Optional[TState]) -> YamlDeclarativeSource: | ||
| return YamlDeclarativeSource(path_to_yaml=str(_YAML_FILE_PATH), catalog=catalog, config=config, state=state) | ||
|
|
||
|
|
||
| def _response_template() -> Dict[str, Any]: | ||
| return find_template("tickets", __file__) | ||
|
|
||
|
|
||
| def _record() -> RecordBuilder: | ||
| return create_record_builder( | ||
| _response_template(), RootPath(), record_id_path=FieldPath("id"), record_cursor_path=FieldPath("updated_at") | ||
| ) | ||
|
|
||
|
|
||
| def _response() -> HttpResponseBuilder: | ||
| return create_response_builder( | ||
| response_template=_response_template(), | ||
| records_path=RootPath(), | ||
| ) | ||
|
|
||
|
|
||
| def read( | ||
| config_builder: Optional[ConfigBuilder] = None, | ||
| state_builder: Optional[StateBuilder] = None, | ||
| expecting_exception: bool = False, | ||
| ) -> EntrypointOutput: | ||
| catalog = _catalog() | ||
| config = config_builder.build() if config_builder else ConfigBuilder().build() | ||
| state = state_builder.build() if state_builder else StateBuilder().build() | ||
| return entrypoint_read(_source(catalog, config, state), config, catalog, state, expecting_exception) | ||
|
|
||
|
|
||
| class TicketsTest(TestCase): | ||
| @HttpMocker() | ||
| def test_when_read_then_extract_records(self, http_mocker: HttpMocker) -> None: | ||
| http_mocker.get( | ||
| HttpRequest(f"https://{_DOMAIN}/api/v2/tickets?order_type=asc&order_by=updated_at&include=description,requester,stats&per_page=100&updated_since=2022-01-01T00%3A00%3A00Z"), | ||
| _response().with_record(_record()).with_record(_record()).build(), | ||
| ) | ||
| output = read(ConfigBuilder().domain(_DOMAIN).start_date(datetime(2022, 1, 1)), StateBuilder()) | ||
| assert len(output.records) == 2 | ||
|
|
||
| @HttpMocker() | ||
| def test_given_hitting_300th_page_when_read_then_reset_pagination(self, http_mocker: HttpMocker) -> None: | ||
| http_mocker.get( | ||
| HttpRequest(f"https://{_DOMAIN}/api/v2/tickets?order_type=asc&order_by=updated_at&include=description,requester,stats&per_page=100&updated_since=2022-01-01T00%3A00%3A00Z"), | ||
| self._a_response_with_full_page("2023-01-01T00:00:00Z"), | ||
| ) | ||
| for page in range(2, 301): | ||
| http_mocker.get( | ||
| HttpRequest(f"https://{_DOMAIN}/api/v2/tickets?order_type=asc&order_by=updated_at&include=description,requester,stats&page={page}&per_page=100&updated_since=2022-01-01T00%3A00%3A00Z"), | ||
| self._a_response_with_full_page("2023-01-01T00:00:00Z"), | ||
| ) | ||
| http_mocker.get( | ||
| HttpRequest(f"https://{_DOMAIN}/api/v2/tickets?order_type=asc&order_by=updated_at&include=description,requester,stats&page=301&per_page=100&updated_since=2022-01-01T00%3A00%3A00Z"), | ||
| HttpResponse(PAGE_LIMIT_300TH_REACHED, 400), | ||
| ) | ||
|
|
||
| http_mocker.get( | ||
| HttpRequest(f"https://{_DOMAIN}/api/v2/tickets?order_type=asc&order_by=updated_at&include=description,requester,stats&per_page=100&updated_since=2023-01-01T00%3A00%3A00Z"), | ||
| _response().with_record(_record()).with_record(_record()).build(), | ||
| ) | ||
|
|
||
| output = read(ConfigBuilder().domain(_DOMAIN).start_date(datetime(2022, 1, 1)), StateBuilder()) | ||
|
|
||
| assert len(output.records) == 300 * 100 + 2 | ||
|
|
||
| def _a_response_with_full_page(self, cursor_value: str) -> HttpResponse: | ||
| response = _response() | ||
| for x in range(100): | ||
| response.with_record(_record().with_cursor(cursor_value)) | ||
| return response.build() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.