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

Fix currently syncing bookmark #116

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions tap_mambu/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def sync_all_streams(client, config, catalog, state):
if last_stream in selected_streams:
selected_streams = selected_streams[selected_streams.index(last_stream):] +\
selected_streams[:selected_streams.index(last_stream)]
else:
# Remove currently_syncing stream if not selected
update_currently_syncing(state, None)
last_stream = None

# For each endpoint (above), determine if the stream should be streamed
# (based on the catalog and last_stream), then sync those streams.
Expand Down
55 changes: 55 additions & 0 deletions tests/unittests/test_currently_syncing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import mock
from tap_mambu.sync import sync_all_streams
from tap_mambu.helpers.client import MambuClient
from tap_mambu.helpers.constants import DEFAULT_DATE_WINDOW_SIZE, DEFAULT_PAGE_SIZE
from tap_mambu.helpers.generator_processor_pairs import get_generator_processor_for_stream


config = {"username": "YOUR_USERNAME",
"password": "YOUR_PASSWORD",
"apikey": "YOUR_APIKEY",
"subdomain": "YOUR_SUBDOMAIN",
"start_date": "2019-01-01T00:00:00Z",
"lookback_window": 30,
"user_agent": "tap-mambu <api_user_email@your_company.com>",
"page_size": "500",
"apikey_audit": "AUDIT_TRAIL_APIKEY"}


@mock.patch("tap_mambu.sync.get_stream_subtypes")
@mock.patch("tap_mambu.sync.get_generator_processor_for_stream")
@mock.patch("tap_mambu.sync.get_selected_streams")
@mock.patch("tap_mambu.sync.get_timezone_info")
@mock.patch("tap_mambu.helpers.client.MambuClient.check_access")
class TestCurrentlySyncingBookmark:
def test_remove_delected_stream(self,
mock_check_access,
mock_get_timezone_info,
mock_get_selected_streams,
mock_get_generator_processor_for_stream,
mock_get_stream_subtypes):

client = MambuClient(config.get('username'),
config.get('password'),
config.get('apikey'),
config['subdomain'],
config.get('apikey_audit'),
int(config.get('page_size', DEFAULT_PAGE_SIZE)),
user_agent=config['user_agent'],
window_size=config.get('window_size'))
catalog = {}
state = {"bookmarks": {"stream1": "bookmark_stream_1"}, "currently_syncing": "stream2"}

# Define the selected streams and the last stream
selected_streams = ['stream1', 'stream3']

# Mock the return values of the functions
mock_get_timezone_info.return_value = None
mock_get_generator_processor_for_stream.return_value = get_generator_processor_for_stream("tasks")
mock_get_selected_streams.return_value = selected_streams
mock_get_stream_subtypes.return_value = []

# Call the sync
sync_all_streams(client, config, catalog, state)

assert state == {"bookmarks": {"stream1": "bookmark_stream_1"}}