* feat(67): add support for 'spec' using Python HTTP API source template and stripe as an example * chore(67): add sample state and config * feat(67): add check functionality for paystack source by fetching first customer * feat(67): add support for discover and read customer stream * feat(67): add paystack source connector to UI * feat(67): update source definitions to use 0.1.0 * Hacktoberfest 67 paystack source (#1) * feat(67): add support for 'spec' using Python HTTP API source template and stripe as an example * chore(67): add sample state and config * feat(67): add check functionality for paystack source by fetching first customer * feat(67): add support for discover and read customer stream * feat(67): add paystack source connector to UI * feat(67): update source definitions to use 0.1.0 Co-authored-by: Foluso Ogunlana <foluso_ogunlana@stearsng.com> * feat(67): update stream state cursor field to be integer and to match API record field name * chore(67): add unit tests for source and streams * chore(67): store formatted date time in state to match type of catalog * chore(67): add configuration for acceptance integration tests * docs(67): update docs and summary with paystack * chore(67): add essential schemas to be catalogued for new streams * feat(67): add support for critical streams - transactions subscriptions transfers refunds settlements * docs(67): update image and bootstrap * chore(67): update builds.md to include paystack badge * docs(67): add changelog and source definition JSON file * docs(67): add paystack to integrations readme * chore(67): update check_connection to airbyte standard * refactor to simplify streams and remove constants file * fix(67): correct "null, null" values in schemas * chore(67): update file formatting with gradle format Co-authored-by: Foluso <5675998+foogunlana@users.noreply.github.com>
52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
#
|
||
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
|
||
#
|
||
|
||
from unittest.mock import ANY, MagicMock
|
||
|
||
import pytest
|
||
import requests
|
||
from source_paystack.source import SourcePaystack
|
||
|
||
|
||
@pytest.mark.parametrize(
|
||
("items",),
|
||
[([{"createdAt": "2022-07-01T00:00:00Z", "id": 12345}],), ([],)], # single customer # no customers
|
||
)
|
||
def test_check_connection_success(mocker, requests_mock, items):
|
||
source = SourcePaystack()
|
||
logger_mock = MagicMock()
|
||
config_mock = {"start_date": "2020-07-01T00:00:00Z", "secret_key": "sk_test_abc123"}
|
||
requests_mock.get(
|
||
"https://api.paystack.co/customer",
|
||
json={
|
||
"data": items,
|
||
"meta": {"page": 1, "pageCount": 0},
|
||
},
|
||
)
|
||
|
||
assert source.check_connection(logger_mock, config_mock) == (True, None)
|
||
|
||
|
||
def test_check_connection_failure(mocker, requests_mock):
|
||
source = SourcePaystack()
|
||
logger_mock, config_mock = MagicMock(), MagicMock()
|
||
requests_mock.get("https://api.paystack.co/customer", json={"status": False, "message": "Failed"})
|
||
|
||
assert source.check_connection(logger_mock, config_mock) == (False, ANY)
|
||
|
||
|
||
def test_check_connection_error(mocker, requests_mock):
|
||
source = SourcePaystack()
|
||
logger_mock, config_mock = MagicMock(), MagicMock()
|
||
requests_mock.get("https://api.paystack.co/customer", exc=requests.exceptions.ConnectTimeout)
|
||
|
||
assert source.check_connection(logger_mock, config_mock) == (False, ANY)
|
||
|
||
|
||
def test_streams(mocker):
|
||
source = SourcePaystack()
|
||
streams = source.streams({"start_date": "2020-08-01", "secret_key": "sk_test_123456"})
|
||
|
||
assert len(streams) == 8
|