Skip to content

🎉 New Source: SurveyMonkey #4097

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 39 commits into from
Jul 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
2bf45c8
add base files
vovavovavovavova Jun 9, 2021
7636d18
upd base
vovavovavovavova Jun 9, 2021
d7995d2
save
vovavovavovavova Jun 9, 2021
ccfff98
save sample files
vovavovavovavova Jun 10, 2021
80bd366
save & todo resolve state
vovavovavovavova Jun 11, 2021
f778007
save the stage
vovavovavovavova Jun 14, 2021
54bf1b5
save the stage
vovavovavovavova Jun 14, 2021
b90546e
pre-gradle save
vovavovavovavova Jun 14, 2021
6c29da6
fix catalogs
vovavovavovavova Jun 14, 2021
da8702e
Merge remote-tracking branch 'origin/master' into valdemar/#2968_new_…
vovavovavovavova Jun 14, 2021
e5db583
merge && format
vovavovavovavova Jun 14, 2021
10cab69
normal stream slices
vovavovavovavova Jun 14, 2021
449e388
apply requested changes
vovavovavovavova Jun 15, 2021
46c22fe
requested_changes
vovavovavovavova Jun 15, 2021
74975cf
postfix
vovavovavovavova Jun 15, 2021
d673ca3
update comment
vovavovavovavova Jun 15, 2021
326bc1c
expand question stream add page_id
vovavovavovavova Jun 16, 2021
23565a9
upd typing once + rm missed inactual todo
vovavovavovavova Jun 16, 2021
5bf6c1e
upd: caching with temp file
vovavovavovavova Jun 22, 2021
bcc0394
upd requirements (requested)
vovavovavovavova Jun 23, 2021
d1867d6
Merge remote-tracking branch 'origin/master' into valdemar/#2968_new_…
vovavovavovavova Jun 25, 2021
9d0a6ea
latest requested fixes
vovavovavovavova Jun 25, 2021
21e09b2
posttext fix retn tempfile
vovavovavovavova Jun 25, 2021
f831465
apply changes && comment
vovavovavovavova Jun 29, 2021
ffe973e
newly requested changes
vovavovavovavova Jun 30, 2021
3e2506e
return back spec -> changes to be set in new issue
vovavovavovavova Jun 30, 2021
056c311
Merge remote-tracking branch 'origin/master' into valdemar/#2968_new_…
vovavovavovavova Jun 30, 2021
374406f
merge && usage comment
vovavovavovavova Jun 30, 2021
fa9dd07
add unit_test for get_updated_state function
vovavovavovavova Jun 30, 2021
c93bc59
add simple date test
vovavovavovavova Jun 30, 2021
3889293
parametrized (?) unittest
vovavovavovavova Jul 1, 2021
0bb5e59
upd comment on record_mode usage
vovavovavovavova Jul 1, 2021
4382e80
replace config with custom var
vovavovavovavova Jul 1, 2021
5b196cd
pytest mark parametrized use
vovavovavovavova Jul 2, 2021
2cef1c8
rm unneeded var
vovavovavovavova Jul 2, 2021
5a903d5
upd tests (requested)
vovavovavovavova Jul 2, 2021
f033962
Merge remote-tracking branch 'origin/master' into valdemar/#2968_new_…
vovavovavovavova Jul 5, 2021
a606553
merge && upd texts
vovavovavovavova Jul 5, 2021
0b76745
add env airbyte_entrypoint
vovavovavovavova Jul 5, 2021
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 @@ -94,14 +94,14 @@ def read_records(
stream_slice: Mapping[str, Any] = None,
stream_state: Mapping[str, Any] = None,
) -> Iterable[Mapping[str, Any]]:
with vcr.use_cassette(cache_file.name, record_mode="new_episodes", serializer="json"):
yield from super().read_records(
sync_mode=sync_mode, cursor_field=cursor_field, stream_slice=stream_slice, stream_state=stream_state
)
"""
We need to save all the request - to main stream, to details etc. So we need to use all epizodes construct,
since we need much more to save then 1 request.
"""
with vcr.use_cassette(cache_file.name, record_mode="new_episodes", serializer="json"):
yield from super().read_records(
sync_mode=sync_mode, cursor_field=cursor_field, stream_slice=stream_slice, stream_state=stream_state
)


class IncrementalSurveymonkeyStream(SurveymonkeyStream, ABC):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,49 +25,39 @@
import json

import pendulum
import vcr
from airbyte_cdk.models import SyncMode
from source_surveymonkey import SourceSurveymonkey
from airbyte_cdk.sources.streams.http.auth import TokenAuthenticator
from source_surveymonkey.streams import Surveys

test_parameters = {
"base_date": "2021-06-10T11:02:01",
"lesser_dates": ["2021-06-09T11:02:01", "2021-05-10T11:02:01", "2020-06-10T11:02:01"], # lesser than base date
"bigger_dates": ["2021-06-10T11:02:02", "2025-06-10T11:02:01", "2021-08-10T11:02:01"], # bigger than base date
}


def test_get_updated_state_unit():
source = SourceSurveymonkey()
config = json.load(open("secrets/config.json"))
streams = source.streams(config=config)
stream = [i for i in streams if i.__class__.__name__ == "Surveys"][0]
config = json.load(open("secrets/config.json")) # not used but required as __init__ arguments
Copy link
Contributor

Choose a reason for hiding this comment

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

you don't need this, just pass anythinh there

authenticator = TokenAuthenticator(token=config["access_token"])
start_date = pendulum.parse(config["start_date"])
stream = Surveys(authenticator=authenticator, start_date=start_date)

record = {"title": "Market Research - Product Testing Template", "date_modified": "2021-06-08T18:09:00", "id": "306079584"}

current_state = {"date_modified": "2021-06-10T11:02:01"}
expected_state = current_state
assert stream.get_updated_state(current_state, record) == expected_state

record_with_bigger_date = {"title": "My random title", "date_modified": "2021-06-15T18:09:00", "id": "306079584"}
expected_state = {stream.cursor_field: record_with_bigger_date[stream.cursor_field]}
assert stream.get_updated_state(current_state, record_with_bigger_date) == expected_state
current_state = {"date_modified": test_parameters["base_date"]}


def test_get_updated_state():
source = SourceSurveymonkey()
config = json.load(open("secrets/config.json"))
streams = source.streams(config=config)
surveys_instance = [i for i in streams if i.__class__.__name__ == "Surveys"][0]
survey_responses_instance = [i for i in streams if i.__class__.__name__ == "SurveyResponses"][0]
with vcr.use_cassette("pretty_name.yaml", record_mode="new_episodes"):
surveys_generator = surveys_instance.read_records(sync_mode=SyncMode.full_refresh)
latest_record = next(surveys_generator)
survey_id = latest_record["id"]
survey_responses_generator = survey_responses_instance.read_records(
sync_mode=SyncMode.full_refresh, stream_slice={"survey_id": survey_id}
)
responses_latest_record = next(survey_responses_generator)

new_state = surveys_instance.get_updated_state(current_stream_state={}, latest_record=latest_record)
new_response_state = survey_responses_instance.get_updated_state(current_stream_state={}, latest_record=responses_latest_record)
assert new_state
assert len(new_state) == 1
pendulum.parse(list(new_state.values())[0])
assert new_response_state
assert survey_id in new_response_state
expected_date_value = list(new_response_state[survey_id].values())[0]
pendulum.parse(expected_date_value)
# test lesser current state
expected_state = current_state
for lesser_date in test_parameters["lesser_dates"]:
record = {"title": "test", "id": 100500, "date_modified": lesser_date}
assert stream.get_updated_state(current_state, record) == expected_state

# test bigger current state
for bigger_date in test_parameters["bigger_dates"]:
record = {"title": "test", "id": 100500, "date_modified": bigger_date}
expected_state = {stream.cursor_field: bigger_date}
assert stream.get_updated_state(current_state, record) == expected_state

# test zero current state
record_with_some_date = {"title": "test", "date_modified": "2000-06-15T18:09:00", "id": 1}
expected_state = {stream.cursor_field: record_with_some_date[stream.cursor_field]}
assert stream.get_updated_state({}, record_with_some_date) == expected_state