Skip to content

Commit

Permalink
adding fixtures to mock time.sleep for connectors that explicitly sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
brianjlai committed Apr 26, 2022
1 parent 8dc704f commit deef578
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 3 deletions.
1 change: 1 addition & 0 deletions airbyte-integrations/connectors/source-freshdesk/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

TEST_REQUIREMENTS = [
"pytest==6.1.2",
"pytest-mock~=3.6",
"requests_mock==1.8.0",
"source-acceptance-test",
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@

from pathlib import Path

from pytest import fixture
from source_freshdesk.client import Client

HERE = Path(__file__).parent.absolute()


@fixture(autouse=True)
def time_sleep_mock(mocker):
time_mock = mocker.patch("time.sleep", lambda x: None)
yield time_mock


def test_client_backoff_on_limit_reached(requests_mock):
"""Error once, check that we retry and not fail"""
responses = [
Expand Down
1 change: 1 addition & 0 deletions airbyte-integrations/connectors/source-hubspot/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

TEST_REQUIREMENTS = [
"pytest==6.1.2",
"pytest-mock~=3.6",
"requests_mock==1.8.0",
"source-acceptance-test",
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
logger = logging.getLogger("test_client")


@pytest.fixture(autouse=True)
def time_sleep_mock(mocker):
time_mock = mocker.patch("time.sleep", lambda x: None)
yield time_mock


def test_check_connection_ok(requests_mock, config):
responses = [
{"json": [], "status_code": 200},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
from .utils import read_full_refresh, read_incremental


@pytest.fixture(autouse=True)
def time_sleep_mock(mocker):
time_mock = mocker.patch("time.sleep", lambda x: None)
yield time_mock


def test_updated_at_field_non_exist_handler(requests_mock, common_params, fake_properties_list):
stream = ContactLists(**common_params)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ def patch_incremental_base_class(mocker):
mocker.patch.object(IncrementalMixpanelStream, "__abstractmethods__", set())


@pytest.fixture(autouse=True)
def time_sleep_mock(mocker):
time_mock = mocker.patch("time.sleep", lambda x: None)
yield time_mock


def test_url_base(patch_base_class):
stream = MixpanelStream(authenticator=MagicMock())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

TEST_REQUIREMENTS = [
"pytest~=6.1",
"pytest-mock~=3.6",
"source-acceptance-test",
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@

from airbyte_cdk.sources.streams.http.auth import NoAuth
from dateutil.parser import isoparse
from pytest import fixture
from source_paypal_transaction.source import Balances, PaypalTransactionStream, Transactions


@fixture(autouse=True)
def time_sleep_mock(mocker):
time_mock = mocker.patch("time.sleep", lambda x: None)
yield time_mock


def test_get_field():

record = {"a": {"b": {"c": "d"}}}
Expand Down
2 changes: 1 addition & 1 deletion airbyte-integrations/connectors/source-salesforce/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

MAIN_REQUIREMENTS = ["airbyte-cdk", "vcrpy==4.1.1", "pandas"]

TEST_REQUIREMENTS = ["pytest~=6.1", "requests_mock", "source-acceptance-test", "pytest-timeout"]
TEST_REQUIREMENTS = ["pytest~=6.1", "pytest-mock~=3.6", "requests_mock", "source-acceptance-test", "pytest-timeout"]

setup(
name="source_salesforce",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
)


@pytest.fixture(autouse=True)
def time_sleep_mock(mocker):
time_mock = mocker.patch("time.sleep", lambda x: None)
yield time_mock


def test_bulk_sync_creation_failed(stream_config, stream_api):
stream: BulkIncrementalSalesforceStream = generate_stream("Account", stream_config, stream_api)
with requests_mock.Mocker() as m:
Expand Down Expand Up @@ -482,7 +488,8 @@ def test_forwarding_sobject_options(stream_config, stream_names, catalog_stream_
"flag1": True,
"queryable": True,
}
for stream_name in stream_names if stream_name != "Describe"
for stream_name in stream_names
if stream_name != "Describe"
],
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
from source_salesforce.exceptions import TypeSalesforceException


@pytest.fixture(autouse=True)
def time_sleep_mock(mocker):
time_mock = mocker.patch("time.sleep", lambda x: None)
yield time_mock


@pytest.mark.parametrize(
"streams_criteria,predicted_filtered_streams",
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
from source_salesforce.streams import BulkIncrementalSalesforceStream


@pytest.fixture(autouse=True)
def time_sleep_mock(mocker):
time_mock = mocker.patch("time.sleep", lambda x: None)
yield time_mock


@pytest.mark.parametrize(
"n_records, first_size, first_peak",
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

MAIN_REQUIREMENTS = ["airbyte-cdk~=0.1.36", "pytz", "requests-futures~=1.0.0", "pendulum~=2.1.2"]

TEST_REQUIREMENTS = ["pytest~=6.1", "source-acceptance-test", "requests-mock==1.9.3"]
TEST_REQUIREMENTS = ["pytest~=6.1", "pytest-mock~=3.6", "source-acceptance-test", "requests-mock==1.9.3"]

setup(
version="0.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
}


@pytest.fixture(autouse=True)
def time_sleep_mock(mocker):
time_mock = mocker.patch("time.sleep", lambda x: None)
yield time_mock


@pytest.mark.parametrize(
"records_count,page_size,expected_futures_deque_len",
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@
TEST_STREAM = TicketComments(**STREAM_ARGS)


@pytest.fixture(autouse=True)
def time_sleep_mock(mocker):
time_mock = mocker.patch("time.sleep", lambda x: None)
yield time_mock


def test_str2datetime():
expected = datetime.strptime(DATETIME_STR, DATETIME_FORMAT)
output = BaseSourceZendeskSupportStream.str2datetime(DATETIME_STR)
Expand Down

0 comments on commit deef578

Please sign in to comment.