-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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 Hubspot: add incremental streams #2425
Merged
keu
merged 12 commits into
keu/source-hubspot-native
from
keu/source-hubspot-incremental
Mar 16, 2021
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
af60dba
add incremental
eugene-kulak 408967d
add incremental
eugene-kulak 40cde14
polishing
eugene-kulak 3d9e025
update docs
eugene-kulak 952af6c
fix docstring
eugene-kulak 0c2d554
clean up
eugene-kulak 607428c
fix incremental bookmark access
eugene-kulak 17672fb
fix incremental tests
eugene-kulak fea181b
clean up
eugene-kulak de7c286
add custom test for incremental, improve logging
eugene-kulak 4cd8d70
format
eugene-kulak e12d026
Update airbyte-integrations/connectors/source-hubspot/source_hubspot/…
sherifnada 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
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
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
101 changes: 101 additions & 0 deletions
101
airbyte-integrations/connectors/source-hubspot/integration_tests/integration_test.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,101 @@ | ||
""" | ||
MIT License | ||
|
||
Copyright (c) 2020 Airbyte | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
""" | ||
|
||
import json | ||
from pathlib import Path | ||
from typing import List, Tuple, Any, MutableMapping, Mapping, Iterable | ||
|
||
from airbyte_protocol import ConfiguredAirbyteCatalog, Type, SyncMode | ||
from base_python import AirbyteLogger | ||
from source_hubspot.source import SourceHubspot | ||
import pytest | ||
|
||
|
||
HERE = Path(__file__).parent.absolute() | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def config() -> Mapping[str, Any]: | ||
config_filename = HERE.parent / "secrets" / "config.json" | ||
|
||
if not config_filename.exists(): | ||
raise RuntimeError(f"Please provide config in {config_filename}") | ||
|
||
with open(str(config_filename)) as json_file: | ||
return json.load(json_file) | ||
|
||
|
||
@pytest.fixture | ||
def configured_catalog() -> ConfiguredAirbyteCatalog: | ||
catalog_filename = HERE.parent / "sample_files" / "configured_catalog.json" | ||
if not catalog_filename.exists(): | ||
raise RuntimeError(f"Please provide configured catalog in {catalog_filename}") | ||
|
||
return ConfiguredAirbyteCatalog.parse_file(catalog_filename) | ||
|
||
|
||
@pytest.fixture | ||
def configured_catalog_with_incremental(configured_catalog) -> ConfiguredAirbyteCatalog: | ||
streams = [] | ||
for stream in configured_catalog.streams: | ||
if SyncMode.incremental in stream.stream.supported_sync_modes: | ||
stream.sync_mode = SyncMode.incremental | ||
streams.append(stream) | ||
|
||
configured_catalog.streams = streams | ||
return configured_catalog | ||
|
||
|
||
def read_stream(source: SourceHubspot, config: Mapping, catalog: ConfiguredAirbyteCatalog, state: MutableMapping = None) -> Tuple[List, List]: | ||
records = [] | ||
states = [] | ||
for message in source.read(AirbyteLogger(), config, catalog, state): | ||
if message.type == Type.RECORD: | ||
records.append(message.record) | ||
elif message.type == Type.STATE: | ||
states.append(message.state) | ||
print(message.state.data) | ||
|
||
return records, states | ||
|
||
|
||
def records_older(records: Iterable, than: int) -> Iterable: | ||
for record in records: | ||
if record.data["created"] < than: | ||
yield record | ||
|
||
|
||
class TestIncrementalSync: | ||
def test_sync_with_latest_state(self, config, configured_catalog_with_incremental): | ||
"""Sync first time, save the state and sync second time with saved state from previous sync""" | ||
records1, states1 = read_stream(SourceHubspot(), config, configured_catalog_with_incremental) | ||
|
||
assert states1, "should have at least one state emitted" | ||
assert records1, "should have at lest few records emitted" | ||
|
||
records2, states2 = read_stream(SourceHubspot(), config, configured_catalog_with_incremental, states1[-1].data) | ||
|
||
assert states1 == states2 | ||
assert list(records_older(records1, than=records2[0].data["created"])), "should have older records from the first read" | ||
assert not list(records_older(records2, than=records2[0].data["created"])), "should not have older records from the second read" |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the reason we include this here is because the cursor comparison logic is inclusive?
how can we verify that incremental is working? can we compare cursor values in a custom test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes it is inclusive as we use
startTimestamp
param to filter recordsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could verify that we don't produce records older than the state value in custom test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we do that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added a custom test for incremental, unfortunately,
subscription_changes
stream doesn't have data, and all my tries to subscribe and unsubscribe from emails didn't trigger any event there. I remember I was using demo credentials to test development, but obviously, demo creds can't be used in the test, as they mostly give you a random responseThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no problem.