-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tdl 24072 fix typecasting bug max api limit #84
Merged
somethingmorerelevant
merged 12 commits into
master
from
TDL-24072-fix-typecasting-bug-max-api-limit
Sep 21, 2023
Merged
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
fe8a953
fixed typecasting error
somethingmorerelevant fa818ec
fixed linting issue
somethingmorerelevant 6a1ee0f
added test for max_api_limit
somethingmorerelevant b5571b2
added readme and changelog
somethingmorerelevant dfca3b3
updated unit test
somethingmorerelevant 02c2cbd
updated scenarios
somethingmorerelevant ff78422
updated tap-tester image
somethingmorerelevant d3055f6
fixed pylint ignores
somethingmorerelevant 54f17fe
updated schema validator
somethingmorerelevant 90b01ef
added ut for true value
somethingmorerelevant ba0cb35
updated __str__ usage
somethingmorerelevant bb34888
added eof line
somethingmorerelevant File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import unittest | ||
from datetime import datetime,timedelta | ||
from tap_marketo.client import Client, MAX_DAILY_CALLS | ||
|
||
class TestDateWindowConfig(unittest.TestCase): | ||
|
||
def test_datewindow_disabled_no_val(self): | ||
dsprayberry marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
Verify that daily_calls_limit is default if no value is passed | ||
""" | ||
# Initialize Client object | ||
client = Client(**{'endpoint': "123-ABC-789",'client_id':'ABC-123','client_secret':'123-QRT'}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Be consistent with the |
||
|
||
self.assertEqual(client.max_daily_calls, MAX_DAILY_CALLS) | ||
|
||
def test_datewindow_disabled_empty_str(self): | ||
""" | ||
Verify that daily_calls_limit is default if empty string value is passed | ||
Verify no Exception is raised for typecasting error between str to num | ||
""" | ||
# Initialize Client object | ||
client = Client(**{'endpoint': "123-ABC-789",'client_id':'ABC-123','client_secret':'123-QRT',"max_daily_calls":""}) | ||
|
||
self.assertEqual(client.max_daily_calls, MAX_DAILY_CALLS) | ||
|
||
def test_datewindow_disabled_bool_val(self): | ||
""" | ||
Verify that daily_calls_limit is default if bool value is passed | ||
""" | ||
# Initialize Client object | ||
client = Client(**{'endpoint': "123-ABC-789",'client_id':'ABC-123','client_secret':'123-QRT','max_daily_calls':False}) | ||
self.assertEqual(client.max_daily_calls ,MAX_DAILY_CALLS) | ||
|
||
def test_datewindow_disabled_num_val(self): | ||
""" | ||
Verify that api_limit is 0 if 0 value is passed | ||
""" | ||
# Initialize Client object | ||
client = Client(**{'endpoint': "123-ABC-789",'client_id':'ABC-123','client_secret':'123-QRT',"max_daily_calls":0}) | ||
self.assertEqual(client.max_daily_calls, MAX_DAILY_CALLS) | ||
|
||
def test_datewindow_disabled_none_val(self): | ||
""" | ||
Verify that api_limit is default if None value is passed | ||
""" | ||
# Initialize Client object | ||
client = Client(**{'endpoint': "123-ABC-789",'client_id':'ABC-123','client_secret':'123-QRT',"max_daily_calls":None}) | ||
self.assertEqual(client.max_daily_calls, MAX_DAILY_CALLS) | ||
|
||
def test_datewindow_enabled_num_val(self): | ||
""" | ||
Verify that api_limit is set appropriately if num value is passed | ||
""" | ||
# Initialize Client object | ||
client = Client(**{'endpoint': "123-ABC-789",'client_id':'ABC-123','client_secret':'123-QRT',"max_daily_calls":3}) | ||
|
||
self.assertEqual(client.max_daily_calls, 3) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we make this a logger error like:
LOGGER.warning("Invalid max_daily_calls was passed: \'{}\', using default value of 40,000.".format("max_daily_calls"))
That way it's a little clearer what might have happened to folks reading the logs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int(max_daily_calls or MAX_DAILY_CALLS)
expression will fallback to default value forNone
,True
/False
and""
.IMO any other exception should be raised instead of falling back to default value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the idea of failing the code for a non-mandatory value but suppressing it will not handle all scenarios, this will only result in the user observing unexpected behaviour.
Hence i find it best to raise an error incase of any such values instead of using a fallback mechanism.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the helper text in UI for this tap also displays a value with a comma for the maximum daily api calls limit i.e
50,000
which will also be a invalid inputThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i have added a few more test scenarios and handled the negative / zero limit condition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have precedence in other taps of logging if we're going to fall back to a default value and allowing the tap to try to proceed with the default, but not really for an API quota scenario, so I'm good either way