From 6bbae48381b3d1cbc0fc9a6e7083b78a177be696 Mon Sep 17 00:00:00 2001 From: rdeshmukh15 <107538720+rdeshmukh15@users.noreply.github.com> Date: Tue, 6 Feb 2024 16:57:35 +0530 Subject: [PATCH] changes to make tap compatible with singer-python 6.0.0 (#195) * 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 --- CHANGELOG.md | 3 +++ setup.py | 2 +- tap_stripe/__init__.py | 22 ---------------- tests/unittests/test_child_bookmarks.py | 3 +-- tests/unittests/test_dict_to_stripe_object.py | 24 ------------------ tests/unittests/test_lookback_window.py | 25 +++++++++---------- 6 files changed, 17 insertions(+), 62 deletions(-) delete mode 100644 tests/unittests/test_dict_to_stripe_object.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 036ab6f5..3719df3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/setup.py b/setup.py index d71be6ad..4868dee4 100755 --- a/setup.py +++ b/setup.py @@ -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", diff --git a/tap_stripe/__init__.py b/tap_stripe/__init__.py index 8adb8564..daa488e3 100755 --- a/tap_stripe/__init__.py +++ b/tap_stripe/__init__.py @@ -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 @@ -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 @@ -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 diff --git a/tests/unittests/test_child_bookmarks.py b/tests/unittests/test_child_bookmarks.py index dc92be5c..22dd2279 100644 --- a/tests/unittests/test_child_bookmarks.py +++ b/tests/unittests/test_child_bookmarks.py @@ -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) @@ -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. ''' diff --git a/tests/unittests/test_dict_to_stripe_object.py b/tests/unittests/test_dict_to_stripe_object.py deleted file mode 100644 index 84df40c2..00000000 --- a/tests/unittests/test_dict_to_stripe_object.py +++ /dev/null @@ -1,24 +0,0 @@ -import stripe -import unittest -from tap_stripe import convert_dict_to_stripe_object - -class TestDictTOSTRIPEOBJECT(unittest.TestCase): - - def test_dict_to_stripe_object(self): - """ - Test that `convert_dict_to_stripe_object` function convert field datatype of dict to stripe.stripe_object.StripeObject - Example: - """ - mock_object = { - "id": "dummy_id", - "tiers": [ - { - "flat_amount": 10, - "unit_amount": 7241350 - } - ], - "tier_mode": "volume" - } - - # Verify that type of `tiers` field is stripe.stripe_object.StripeObject - self.assertTrue(isinstance(convert_dict_to_stripe_object(mock_object).get('tiers')[0], stripe.stripe_object.StripeObject)) \ No newline at end of file diff --git a/tests/unittests/test_lookback_window.py b/tests/unittests/test_lookback_window.py index 6c0d7101..6adab76f 100644 --- a/tests/unittests/test_lookback_window.py +++ b/tests/unittests/test_lookback_window.py @@ -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") @@ -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"} @@ -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", @@ -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", @@ -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"} @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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",