Skip to content

Commit

Permalink
changes to make tap compatible with singer-python 6.0.0 (#195)
Browse files Browse the repository at this point in the history
* changes to make tap compatible with python 3.11.7

* fixing pylint issue

* removed a function which converts record from dict to stripe_object

* removed a function convert_dict_to_stripe_object

* removed unused import

* fix unit tests

* CHANGELOG.md and setup.py changes
  • Loading branch information
rdeshmukh15 authored Feb 6, 2024
1 parent ab6b0ff commit 6bbae48
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 62 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 3.2.0
* Makes tap compatible with singer-python 6.0.0 [#195](https://github.com/singer-io/tap-stripe/pull/195)

## 3.1.0
* Upgrades to run on python 3.11.7 [#193](https://github.com/singer-io/tap-stripe/pull/193)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name="tap-stripe",
version="3.1.0",
version="3.2.0",
description="Singer.io tap for extracting data",
author="Stitch",
url="http://singer.io",
Expand Down
22 changes: 0 additions & 22 deletions tap_stripe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from stripe.api_resources.list_object import ListObject
from stripe.error import InvalidRequestError
from stripe.api_requestor import APIRequestor
from stripe.util import convert_to_stripe_object
import singer
from singer import utils, Transformer, metrics
from singer import metadata
Expand Down Expand Up @@ -555,25 +554,6 @@ def write_bookmark_for_stream(stream_name, replication_key, stream_bookmark):
stream_bookmark)


def convert_dict_to_stripe_object(record):
"""
Convert field datatype of dict object to `stripe.stripe_object.StripeObject`.
Example:
record = {'id': 'dummy_id', 'tiers': [{"flat_amount": 4578"unit_amount": 7241350}]}
This function convert datatype of each record of 'tiers' field to `stripe.stripe_object.StripeObject`.
"""
# Loop through each fields of `record` object
for key, val in record.items():
# Check type of field
if isinstance(val, list):
# Loop through each records of list
for index, field_val in enumerate(val):
if isinstance(field_val, dict):
# Convert datatype of dict to `stripe.stripe_object.StripeObject`
record[key][index] = convert_to_stripe_object(record[key][index])

return record

# pylint: disable=too-many-locals
# pylint: disable=too-many-statements

Expand Down Expand Up @@ -681,8 +661,6 @@ def sync_stream(stream_name, is_sub_stream=False):

# get the replication key value from the object
rec = unwrap_data_objects(stream_obj.to_dict_recursive())
# convert field datatype of dict object to `stripe.stripe_object.StripeObject`
rec = convert_dict_to_stripe_object(rec)
rec = reduce_foreign_keys(rec, stream_name)
stream_obj_created = rec[replication_key]
rec['updated'] = stream_obj_created
Expand Down
3 changes: 1 addition & 2 deletions tests/unittests/test_child_bookmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ def test_sync_event_updates_when_substream_bookmark_present(self, mock_get_bookm
mock_get_bookmark_for_sub_stream.assert_called_with("invoice_line_items")

@mock.patch('tap_stripe.reduce_foreign_keys', return_value = {"created": 1561047480})
@mock.patch('tap_stripe.convert_dict_to_stripe_object')
@mock.patch('tap_stripe.is_parent_selected', return_value=False)
@mock.patch('tap_stripe.paginate', return_value = [mock.Mock()])
@mock.patch('tap_stripe.Context.is_sub_stream', return_value=False)
Expand All @@ -121,7 +120,7 @@ def test_sync_event_updates_for_parent_stream(self, mock_write_record, mock_get_
mock_now, mock_get_catalog_entry,
mock_to_map, mock_is_selected, mock_write_schema,
mock_is_sub_stream, mock_paginate, mock_is_parent_selected,
mock_convert_dict, mock_reduce_foreign_keys):
mock_reduce_foreign_keys):
'''
Verify that when only the parent stream is selected, write_record() is called for the parent stream.
'''
Expand Down
24 changes: 0 additions & 24 deletions tests/unittests/test_dict_to_stripe_object.py

This file was deleted.

25 changes: 12 additions & 13 deletions tests/unittests/test_lookback_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def to_dict_recursive(cls):
@mock.patch("singer.write_record")
@mock.patch('singer.utils.now', return_value=datetime.strptime("2022-01-01T08:30:50Z", BOOKMARK_FORMAT))
@mock.patch("tap_stripe.reduce_foreign_keys", return_value={"created": 16452804585})
@mock.patch("tap_stripe.convert_dict_to_stripe_object", return_value={"created": "2022-02-17T00:00:00"})
@mock.patch("tap_stripe.paginate", return_value=[MockClass()])
@mock.patch("tap_stripe.Context.get_catalog_entry")
@mock.patch("tap_stripe.singer.metadata.to_map")
Expand All @@ -37,7 +36,7 @@ class TestLookbackWindow(unittest.TestCase):

def test_default_value_lookback(
self, mock_get_bookmark_for_stream, mock_sync_substream, mock_dt_to_epoch, mock_epoch_to_dt, mock_get,
mock_metadata_map, mock_get_catalog_entry, mock_paginate, mock_convert_dict_to_stripe_object,
mock_metadata_map, mock_get_catalog_entry, mock_paginate,
mock_reduce_foreign_keys, mock_utils_now, mock_write_record):
'''Verify that the lookback window is 600 by default if nothing is provided in the config.'''
config = {"client_secret": "test_secret", "account_id": "test_account", "start_date": "2022-02-17T00:00:00"}
Expand All @@ -50,7 +49,7 @@ def test_default_value_lookback(

def test_config_provided_value_lookback(
self, mock_get_bookmark_for_stream, mock_sync_substream, mock_dt_to_epoch, mock_epoch_to_dt, mock_get,
mock_metadata_map, mock_get_catalog_entry, mock_paginate, mock_convert_dict_to_stripe_object,
mock_metadata_map, mock_get_catalog_entry, mock_paginate,
mock_reduce_foreign_keys, mock_utils_now, mock_write_record):
'''Verify that the lookback window is correctly passed when mentioned in the config.'''
config = {"client_secret": "test_secret", "account_id": "test_account",
Expand All @@ -64,7 +63,7 @@ def test_config_provided_value_lookback(

def test_empty_string_in_config_lookback(
self, mock_get_bookmark_for_stream, mock_sync_substream, mock_dt_to_epoch, mock_epoch_to_dt, mock_get,
mock_metadata_map, mock_get_catalog_entry, mock_paginate, mock_convert_dict_to_stripe_object,
mock_metadata_map, mock_get_catalog_entry, mock_paginate,
mock_reduce_foreign_keys, mock_utils_now, mock_write_record):
'''Verify that the lookback window is correctly passed when empty string is passed in the config.'''
config = {"client_secret": "test_secret", "account_id": "test_account",
Expand All @@ -78,7 +77,7 @@ def test_empty_string_in_config_lookback(

def test_default_value_lookback_events(
self, mock_get_bookmark_for_stream, mock_sync_substream, mock_dt_to_epoch, mock_epoch_to_dt, mock_get,
mock_metadata_map, mock_get_catalog_entry, mock_paginate, mock_convert_dict_to_stripe_object,
mock_metadata_map, mock_get_catalog_entry, mock_paginate,
mock_reduce_foreign_keys, mock_utils_now, mock_write_record):
'''Verify that the lookback window is 600 by default if nothing is provided in the config.'''
config = {"client_secret": "test_secret", "account_id": "test_account", "start_date": "2022-02-17T00:00:00"}
Expand All @@ -91,7 +90,7 @@ def test_default_value_lookback_events(

def test_config_provided_value_lookback_events(
self, mock_get_bookmark_for_stream, mock_sync_substream, mock_dt_to_epoch, mock_epoch_to_dt, mock_get,
mock_metadata_map, mock_get_catalog_entry, mock_paginate, mock_convert_dict_to_stripe_object,
mock_metadata_map, mock_get_catalog_entry, mock_paginate,
mock_reduce_foreign_keys, mock_utils_now, mock_write_record):
'''Verify that the lookback window is correctly passed when mentioned in the config.'''
config = {"client_secret": "test_secret", "account_id": "test_account",
Expand All @@ -105,7 +104,7 @@ def test_config_provided_value_lookback_events(

def test_empty_string_in_config_lookback_events(
self, mock_get_bookmark_for_stream, mock_sync_substream, mock_dt_to_epoch, mock_epoch_to_dt, mock_get,
mock_metadata_map, mock_get_catalog_entry, mock_paginate, mock_convert_dict_to_stripe_object,
mock_metadata_map, mock_get_catalog_entry, mock_paginate,
mock_reduce_foreign_keys, mock_utils_now, mock_write_record):
'''Verify that the lookback window is correctly passed when empty string is passed in the config.'''
config = {"client_secret": "test_secret", "account_id": "test_account",
Expand All @@ -119,7 +118,7 @@ def test_empty_string_in_config_lookback_events(

def test_invalid_value_string_in_config_lookback_events(
self, mock_get_bookmark_for_stream, mock_sync_substream, mock_dt_to_epoch, mock_epoch_to_dt, mock_get,
mock_metadata_map, mock_get_catalog_entry, mock_paginate, mock_convert_dict_to_stripe_object,
mock_metadata_map, mock_get_catalog_entry, mock_paginate,
mock_reduce_foreign_keys, mock_utils_now, mock_write_record):
'''Verify that the lookback window is correctly passed when empty string is passed in the config.'''
config = {"client_secret": "test_secret", "account_id": "test_account",
Expand All @@ -134,7 +133,7 @@ def test_invalid_value_string_in_config_lookback_events(

def test_invalid_value_string_in_config_lookback_balance_transactions(
self, mock_get_bookmark_for_stream, mock_sync_substream, mock_dt_to_epoch, mock_epoch_to_dt, mock_get,
mock_metadata_map, mock_get_catalog_entry, mock_paginate, mock_convert_dict_to_stripe_object,
mock_metadata_map, mock_get_catalog_entry, mock_paginate,
mock_reduce_foreign_keys, mock_utils_now, mock_write_record):
'''Verify that the lookback window is correctly passed when empty string is passed in the config.'''
config = {"client_secret": "test_secret", "account_id": "test_account",
Expand All @@ -149,7 +148,7 @@ def test_invalid_value_string_in_config_lookback_balance_transactions(

def test_0_in_config_lookback_events(
self, mock_get_bookmark_for_stream, mock_sync_substream, mock_dt_to_epoch, mock_epoch_to_dt, mock_get,
mock_metadata_map, mock_get_catalog_entry, mock_paginate, mock_convert_dict_to_stripe_object,
mock_metadata_map, mock_get_catalog_entry, mock_paginate,
mock_reduce_foreign_keys, mock_utils_now, mock_write_record):
'''Verify that the lookback window is correctly passed when empty string is passed in the config.'''
config = {"client_secret": "test_secret", "account_id": "test_account",
Expand All @@ -163,7 +162,7 @@ def test_0_in_config_lookback_events(

def test_0_in_config_lookback_balance_transactions(
self, mock_get_bookmark_for_stream, mock_sync_substream, mock_dt_to_epoch, mock_epoch_to_dt, mock_get,
mock_metadata_map, mock_get_catalog_entry, mock_paginate, mock_convert_dict_to_stripe_object,
mock_metadata_map, mock_get_catalog_entry, mock_paginate,
mock_reduce_foreign_keys, mock_utils_now, mock_write_record):
'''Verify that the lookback window is correctly passed when empty string is passed in the config.'''
config = {"client_secret": "test_secret", "account_id": "test_account",
Expand All @@ -177,7 +176,7 @@ def test_0_in_config_lookback_balance_transactions(

def test_string_0_in_config_lookback_balance_transactions(
self, mock_get_bookmark_for_stream, mock_sync_substream, mock_dt_to_epoch, mock_epoch_to_dt, mock_get,
mock_metadata_map, mock_get_catalog_entry, mock_paginate, mock_convert_dict_to_stripe_object,
mock_metadata_map, mock_get_catalog_entry, mock_paginate,
mock_reduce_foreign_keys, mock_utils_now, mock_write_record):
'''Verify that the lookback window is correctly passed when '0' is passed in the config.'''
config = {"client_secret": "test_secret", "account_id": "test_account",
Expand All @@ -191,7 +190,7 @@ def test_string_0_in_config_lookback_balance_transactions(

def test_string_0_in_config_lookback_events(
self, mock_get_bookmark_for_stream, mock_sync_substream, mock_dt_to_epoch, mock_epoch_to_dt, mock_get,
mock_metadata_map, mock_get_catalog_entry, mock_paginate, mock_convert_dict_to_stripe_object,
mock_metadata_map, mock_get_catalog_entry, mock_paginate,
mock_reduce_foreign_keys, mock_utils_now, mock_write_record):
'''Verify that the lookback window is correctly passed when '0' is passed in the config.'''
config = {"client_secret": "test_secret", "account_id": "test_account",
Expand Down

0 comments on commit 6bbae48

Please sign in to comment.