1
0
mirror of synced 2026-01-05 03:04:38 -05:00
Files
airbyte/airbyte-integrations/connectors/source-webflow/unit_tests/test_streams.py
Alexander Marquardt e4d3d60ca8 🎉 New Source: Webflow (#13617)
* Added webflow code

* Updated readme

* Updated README

* Added webflow to source_definitions.yaml

* Enhanced documentation for the Webflow source connector

* Improved webflow source connector instructions

* Moved Site ID to before API token in Spec.yaml (for presentation in the UI)

* Addressed comments in PR.

* Changes to address requests in PR review

* Removed version from config

* Minor udpate to spec.yaml for clarity

* Updated to pass the accept-version as a constant rather than parameter

* Updated check_connection to hit the collections API that requires both site id and the authentication token.

* Fixed the test_check_connection to use the new check_connection function

* Added a streams test for generate_streams

* Re-named "autentication" object to "auth" to be more consistent with the way it is created by the CDK

* Added in an explict line to instantiante an "auth" object from WebflowTokenAuthenticator, to make it easier to describe in the blog

* Fixed a typo in a comment

* Renamed some classes to be more intuitive

* Renamed class to be more intuitive

* Minor change to an internal method name

* Made _get_collection_name_to_id_dict staticmethod

* Fixed a unit-test error that only appeared when running " python -m pytest -s unit_tests".
This was caused by Mocked settings from test_source.py leaking into test_streams.py

* format: add double quotes and remove unused import

* readme: remove semantic version naming of connector in build commands

* Updated spec.yaml

* auto-bump connector version

* format files

* add changelog

* update dockerfile

* auto-bump connector version

Co-authored-by: sajarin <sajarindider@gmail.com>
Co-authored-by: Octavia Squidington III <octavia-squidington-iii@users.noreply.github.com>
Co-authored-by: marcosmarxm <marcosmarxm@gmail.com>
2022-06-22 08:44:27 -03:00

79 lines
2.7 KiB
Python

#
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
#
from http import HTTPStatus
from unittest.mock import MagicMock
import pytest
from source_webflow.source import CollectionContents, SourceWebflow, WebflowStream
@pytest.fixture
def patch_base_class(mocker):
# Mock abstract methods to enable instantiating abstract class
mocker.patch.object(WebflowStream, "path", "v0/example_endpoint")
mocker.patch.object(WebflowStream, "primary_key", "test_primary_key")
mocker.patch.object(WebflowStream, "__abstractmethods__", set())
def test_request_params_of_collection_items(patch_base_class):
stream = CollectionContents()
inputs = {"stream_slice": None, "stream_state": None, "next_page_token": {"offset": 1}}
expected_params = {"limit": 100, "offset": 1}
assert stream.request_params(**inputs) == expected_params
def test_next_page_token_of_collection_items(patch_base_class):
stream = CollectionContents()
response_data = {"items": [{"item1_key": "item1_val"}], "count": 10, "offset": 100}
inputs = {"response": MagicMock(json=lambda: response_data)}
expected_token = {"offset": 110}
assert stream.next_page_token(**inputs) == expected_token
def test_parse_response_of_collection_items(patch_base_class):
stream = CollectionContents()
mock_record = {"item1_key": "item1_val"}
response_data = {"items": [mock_record]}
inputs = {"response": MagicMock(json=lambda: response_data)}
parsed_item = next(stream.parse_response(**inputs))
assert parsed_item == mock_record
def test_generate_streams(patch_base_class):
SourceWebflow._get_collection_name_to_id_dict = MagicMock(return_value={"name-1": "id-1", "name-2": "id-2"})
source = SourceWebflow()
config_mock = MagicMock()
streams = source.generate_streams(config_mock, "fake site id")
assert len(list(streams)) == 2
def test_http_method(patch_base_class):
stream = WebflowStream()
expected_method = "GET"
assert stream.http_method == expected_method
@pytest.mark.parametrize(
("http_status", "should_retry"),
[
(HTTPStatus.OK, False),
(HTTPStatus.BAD_REQUEST, False),
(HTTPStatus.TOO_MANY_REQUESTS, True),
(HTTPStatus.INTERNAL_SERVER_ERROR, True),
],
)
def test_should_retry(patch_base_class, http_status, should_retry):
response_mock = MagicMock()
response_mock.status_code = http_status
stream = WebflowStream()
assert stream.should_retry(response_mock) == should_retry
def test_backoff_time(patch_base_class):
response_mock = MagicMock()
stream = WebflowStream()
expected_backoff_time = None
assert stream.backoff_time(response_mock) == expected_backoff_time