1
0
mirror of synced 2026-01-08 21:05:13 -05:00
Files
airbyte/airbyte-integrations/connectors/source-surveymonkey/unit_tests/test_source.py
Dominik Wagner cb593fae9b 🎉 Source SurveyMonkey: add survey_collectors and collectors stream (#23721)
* add survey_collectors stream

* add stream to docs

* add missing schema

* fix stream and add expected records

* remove unused file

* bump connector version

* fix unit test

* add doc url for surveycollectors

* update expected records

* auto-bump connector version

---------

Co-authored-by: sh4sh <6833405+sh4sh@users.noreply.github.com>
Co-authored-by: marcosmarxm <marcosmarxm@gmail.com>
Co-authored-by: Marcos Marx <marcosmarxm@users.noreply.github.com>
Co-authored-by: Octavia Squidington III <octavia-squidington-iii@users.noreply.github.com>
2023-04-27 07:16:28 -03:00

77 lines
2.7 KiB
Python

#
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
#
import pytest
from source_surveymonkey.source import SourceSurveymonkey
source_config = {"start_date": "2021-01-01T00:00:00", "access_token": "something"}
new_source_config = {
"start_date": "2021-01-01T00:00:00",
"origin": "USA",
"credentials": {"auth_method": "something", "access_token": "something", "client_secret": "client_secret", "client_id": "client_id"},
}
def test_source_streams():
streams = SourceSurveymonkey().streams(config=new_source_config)
assert len(streams) == 6
def test_source_check_connection_old_config(requests_mock):
requests_mock.get(
"https://api.surveymonkey.com/v3/users/me", json={"scopes": {"granted": ["responses_read_detail", "surveys_read", "users_read"]}}
)
results = SourceSurveymonkey().check_connection(logger=None, config=source_config)
assert results == (True, None)
def test_source_check_connection_new_config(requests_mock):
requests_mock.get(
"https://api.surveymonkey.com/v3/users/me", json={"scopes": {"granted": ["responses_read_detail", "surveys_read", "users_read"]}}
)
results = SourceSurveymonkey().check_connection(logger=None, config=new_source_config)
assert results == (True, None)
def test_source_check_connection_failed_missing_scopes(requests_mock):
requests_mock.get("https://api.surveymonkey.com/v3/users/me", json={"scopes": {"granted": ["surveys_read", "users_read"]}})
results = SourceSurveymonkey().check_connection(logger=None, config=new_source_config)
assert results == (False, "missed required scopes: responses_read_detail")
@pytest.mark.parametrize(
"config, err_msg",
[
(
{
"start_date": "2021-01-01T00:00:00",
"origin": "USA",
},
"credentials fields are not provided",
),
(
{
"start_date": "2021-01-01T00:00:00",
"origin": "USA",
"credentials": {"access_token": "something", "client_secret": "client_secret", "client_id": "client_id"},
},
"auth_method in credentials is not provided",
),
(
{
"start_date": "2021-01-01T00:00:00",
"origin": "USA",
"credentials": {"auth_method": "something", "client_secret": "client_secret", "client_id": "client_id"},
},
"access_token in credentials is not provided",
),
],
)
def test_source_check_connection_failed_missing_credentials(config, err_msg):
results = SourceSurveymonkey().check_connection(logger=None, config=config)
assert results == (False, err_msg)