Beispiel #1
0
def test_check_connection_ok(config, requests_mock):
    url = "https://api.intercom.io/tags"
    requests_mock.get(url, json={})
    ok, error_msg = SourceIntercom().check_connection(logger, config=config)

    assert ok
    assert not error_msg
def test_supported_versions(stream_attributes, version, not_supported_streams, custom_companies_data_field):
    class CustomVersionApiAuthenticator(VersionApiAuthenticator):
        relevant_supported_version = str(version)

    authenticator = CustomVersionApiAuthenticator(token=stream_attributes["access_token"])
    for stream in SourceIntercom().streams(deepcopy(stream_attributes)):
        stream._authenticator = authenticator
        if stream.name == "companies":
            stream.data_fields = [custom_companies_data_field]
        elif hasattr(stream, "parent_stream_class") and stream.parent_stream_class == Companies:
            stream.parent_stream_class.data_fields = [custom_companies_data_field]

        if stream.name in not_supported_streams:
            LOGGER.info(f"version {version} shouldn't be supported the stream '{stream.name}'")
            with pytest.raises(HTTPError) as err:
                for slice in stream.stream_slices(sync_mode=SyncMode.full_refresh):
                    next(stream.read_records(sync_mode=None, stream_slice=slice), None)
                    break
            # example of response errors:
            # {"type": "error.list", "request_id": "000hjqhpf95ef3b8f8v0",
            #  "errors": [{"code": "intercom_version_invalid", "message": "The requested version could not be found"}]}
            assert len(err.value.response.json()["errors"]) > 0
            err_data = err.value.response.json()["errors"][0]
            LOGGER.info(f"version {version} doesn't support the stream '{stream.name}', error: {err_data}")
        else:
            LOGGER.info(f"version {version} should be supported the stream '{stream.name}'")
            for slice in stream.stream_slices(sync_mode=SyncMode.full_refresh):
                records = stream.read_records(sync_mode=None, stream_slice=slice)
                if stream.name == "companies":
                    # need to read all records for scroll resetting
                    list(records)
                else:
                    next(records, None)
Beispiel #3
0
def test_streams(config):
    streams = SourceIntercom().streams(config)

    assert len(streams) == 11
Beispiel #4
0
def test_check_connection_exception(config):
    ok, error_msg = SourceIntercom().check_connection(logger, config=config)

    assert not ok
    assert error_msg
Beispiel #5
0
def test_check_connection_invalid_config(config):
    config.pop("start_date")
    ok, error_msg = SourceIntercom().check_connection(logger, config=config)

    assert not ok
    assert error_msg
Beispiel #6
0
def test_check_connection_empty_config(config):
    config = {}

    with pytest.raises(KeyError):
        SourceIntercom().check_connection(logger, config=config)