1
0
mirror of synced 2025-12-31 06:05:12 -05:00
Files
airbyte/airbyte-integrations/connectors/source-paystack/unit_tests/test_source.py
Cole Snodgrass 2e099acc52 update headers from 2022 -> 2023 (#22594)
* It's 2023!

* 2022 -> 2023

---------

Co-authored-by: evantahler <evan@airbyte.io>
2023-02-08 13:01:16 -08:00

52 lines
1.6 KiB
Python
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#
# Copyright (c) 2023 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