From 53f307e40c973e5a8e7e64123b68a0c5852e73fe Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Sat, 18 May 2024 22:03:34 +0200 Subject: [PATCH] Kucoin coverage --- personal_data/fetchers/defi_kucoin.py | 26 +++++++++++-------- test/test_kucoin.py | 37 +++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 11 deletions(-) create mode 100644 test/test_kucoin.py diff --git a/personal_data/fetchers/defi_kucoin.py b/personal_data/fetchers/defi_kucoin.py index db6ca0b..efcd03f 100644 --- a/personal_data/fetchers/defi_kucoin.py +++ b/personal_data/fetchers/defi_kucoin.py @@ -42,6 +42,18 @@ class KucoinAccountBalances(Scraper): yield frozendict(data_point) +def addresses_to_data_points(addresses) -> frozendict: + data_point = {} + data_point['account.num_deposit_addresses'] = len(addresses) + data_point['account.update_time'] = datetime.datetime.now(tz=datetime.UTC) + + if len(addresses) > 0: + for k, v in addresses[-1].items(): + data_point[f'deposit.{k}'] = v + + return frozendict(data_point) + + @dataclasses.dataclass(frozen=True) class KucoinDepositAddresses(Scraper): dataset_name = 'defi_kucoin_deposit_address' @@ -49,14 +61,6 @@ class KucoinDepositAddresses(Scraper): deduplicate_ignore_columns = ['account.update_time'] def scrape(self) -> Iterator[Mapping[str, object]]: - data_point = {} - - addresses = client.get_deposit_address('MPC') - - data_point['account.num_deposit_addresses'] = len(addresses) - data_point['account.update_time'] = datetime.datetime.now(tz=datetime.UTC) - - for k, v in addresses[-1].items(): - data_point[f'deposit.{k}'] = v - - yield frozendict(data_point) + # addresses = client.get_deposit_address('MPC') + addresses = list() + yield addresses_to_data_points(addresses) diff --git a/test/test_kucoin.py b/test/test_kucoin.py new file mode 100644 index 0000000..3b18e34 --- /dev/null +++ b/test/test_kucoin.py @@ -0,0 +1,37 @@ +from frozendict import frozendict + +from personal_data.fetchers.defi_kucoin import addresses_to_data_points + + +def test_addresses_to_data_points_none(): + data_point = addresses_to_data_points([]) + assert data_point['account.update_time'] is not None + expected = { + 'account.num_deposit_addresses': 0, + 'account.update_time': data_point['account.update_time'], + } + assert data_point == frozendict(expected) + + +def test_addresses_to_data_points_one(): + data_point = addresses_to_data_points([{'a': 1, 'b': 2}]) + assert data_point['account.update_time'] is not None + expected = { + 'account.num_deposit_addresses': 1, + 'account.update_time': data_point['account.update_time'], + 'deposit.a': 1, + 'deposit.b': 2, + } + assert data_point == frozendict(expected) + + +def test_addresses_to_data_points_two(): + data_point = addresses_to_data_points([{'a': 1, 'b': 2}, {'a': 4, 'b': 9}]) + assert data_point['account.update_time'] is not None + expected = { + 'account.num_deposit_addresses': 2, + 'account.update_time': data_point['account.update_time'], + 'deposit.a': 4, + 'deposit.b': 9, + } + assert data_point == frozendict(expected)