Skip to content

Commit

Permalink
* HHandle string true/false config values properly
Browse files Browse the repository at this point in the history
  • Loading branch information
RushiT0122 committed Feb 7, 2025
1 parent ad6abc3 commit 03a8b18
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 4 deletions.
6 changes: 6 additions & 0 deletions tap_hubspot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1486,6 +1486,12 @@ def main_impl():
CONFIG.update(args.config)
STATE = {}

if str(CONFIG.get('select_fields_by_default')).lower() not in ['none', 'true', 'false']:
raise ValueError("Invalid value for select_fields_by_default. It should be either 'true' or 'false'.")

CONFIG['select_fields_by_default'] = (
str(CONFIG.get('select_fields_by_default', 'true')).lower() != 'false')

if args.state:
STATE.update(args.state)

Expand Down
82 changes: 78 additions & 4 deletions tests/unittests/test_deselect_unselected_fields.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,81 @@
import unittest
from unittest.mock import patch, MagicMock
from tap_hubspot import deselect_unselected_fields, do_sync, CONFIG

from tap_hubspot import deselect_unselected_fields, do_sync, main_impl, CONFIG


class TestMainImpl(unittest.TestCase):

@patch('tap_hubspot.utils.parse_args')
@patch('tap_hubspot.do_discover')
@patch('tap_hubspot.do_sync')
def test_main_impl_default_behavior(self, mock_do_sync, mock_do_discover, mock_parse_args):
"""Test the default behavior of the main_impl function when select_fields_by_default is not set."""
mock_args = MagicMock()
mock_args.config = {}
mock_args.state = None
mock_args.discover = False
mock_args.properties = None
mock_parse_args.return_value = mock_args

main_impl()

self.assertTrue(CONFIG['select_fields_by_default'])
mock_do_discover.assert_not_called()
mock_do_sync.assert_not_called()

@patch('tap_hubspot.utils.parse_args')
@patch('tap_hubspot.do_discover')
@patch('tap_hubspot.do_sync')
def test_main_impl_select_fields_by_default_true(self, mock_do_sync, mock_do_discover, mock_parse_args):
"""Test the behavior of the main_impl function when select_fields_by_default is set to true."""
mock_args = MagicMock()
mock_args.config = {'select_fields_by_default': 'true'}
mock_args.state = None
mock_args.discover = False
mock_args.properties = None
mock_parse_args.return_value = mock_args

main_impl()

self.assertTrue(CONFIG['select_fields_by_default'])
mock_do_discover.assert_not_called()
mock_do_sync.assert_not_called()

@patch('tap_hubspot.utils.parse_args')
@patch('tap_hubspot.do_discover')
@patch('tap_hubspot.do_sync')
def test_main_impl_select_fields_by_default_false(self, mock_do_sync, mock_do_discover, mock_parse_args):
"""Test the behavior of the main_impl function when select_fields_by_default is set to false."""
mock_args = MagicMock()
mock_args.config = {'select_fields_by_default': 'false'}
mock_args.state = None
mock_args.discover = False
mock_args.properties = None
mock_parse_args.return_value = mock_args

main_impl()

self.assertFalse(CONFIG['select_fields_by_default'])
mock_do_discover.assert_not_called()
mock_do_sync.assert_not_called()

@patch('tap_hubspot.utils.parse_args')
@patch('tap_hubspot.do_discover')
@patch('tap_hubspot.do_sync')
def test_main_impl_invalid_select_fields_by_default(self, mock_do_sync, mock_do_discover, mock_parse_args):
"""Test the behavior of the main_impl function when select_fields_by_default is set to an invalid value."""
mock_args = MagicMock()
mock_args.config = {'select_fields_by_default': 'invalid'}
mock_args.state = None
mock_args.discover = False
mock_args.properties = None
mock_parse_args.return_value = mock_args

with self.assertRaises(ValueError):
main_impl()

mock_do_discover.assert_not_called()
mock_do_sync.assert_not_called()

class TestDoSync(unittest.TestCase):

Expand Down Expand Up @@ -50,7 +124,7 @@ def test_do_sync_select_fields_by_default_true(self, mock_singer, mock_get_selec
mock_generate_custom_streams.return_value = []

# Mocking the catalog and state
CONFIG.update({'select_fields_by_default': True})
CONFIG.update({'select_fields_by_default': 'true'})
catalog = {'streams': []}
state = {}

Expand Down Expand Up @@ -78,7 +152,7 @@ def test_do_sync_select_fields_by_default_false(self, mock_singer, mock_get_sele
mock_generate_custom_streams.return_value = []

# Mocking the catalog and state
CONFIG.update({'select_fields_by_default': False})
CONFIG.update({'select_fields_by_default': 'false'})
catalog = {'streams': []}
state = {}

Expand Down

0 comments on commit 03a8b18

Please sign in to comment.