Skip to content

Commit

Permalink
Bugfix/tdl 14351 (singer-io#29)
Browse files Browse the repository at this point in the history
* Added helper function to remove whitespaces from config, added corresponding unittest.

* Added items to gitignore

Co-authored-by: pbegle <[email protected]>
  • Loading branch information
0xpetersatoshi and pbegle authored Aug 10, 2021
1 parent ed5e68f commit 291e140
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,7 @@ ENV/
env.sh
config.json
.autoenv.zsh
*~
*~

*config.json
*catalog.json
13 changes: 12 additions & 1 deletion tap_appsflyer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@
}


def clean_config(config: dict) -> dict:
"""Strips whitespace from any values in the config."""
for key in config.keys():
value = config[key]
if isinstance(value, str):
config[key] = value.strip()

return config


def af_datetime_str_to_datetime(s):
return datetime.datetime.strptime(s.strip(), "%Y-%m-%d %H:%M:%S")

Expand Down Expand Up @@ -595,7 +605,8 @@ def main():
"api_token"
])

CONFIG.update(args.config)
config = clean_config(args.config)
CONFIG.update(config)

if args.state:
STATE.update(args.state)
Expand Down
16 changes: 15 additions & 1 deletion tests/unittests/test_helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import datetime
from unittest.mock import patch

from tap_appsflyer import get_restricted_start_date
from tap_appsflyer import clean_config, get_restricted_start_date

MOCKED_DATE = datetime.datetime(2021, 7, 1, 1, 1, 1, 369251)

Expand All @@ -22,3 +22,17 @@ def test_get_restricted_start_date():
date = get_restricted_start_date(test_case['case'])

assert date == test_case['expected']


def test_clean_config():
test_cases = [
{'case': {'app_id': ' 123456789 '}, 'expected': '123456789'},
{'case': {'app_id': '7898901 '}, 'expected': '7898901'},
{'case': {'app_id': ' 90234-0823jsjfsfsuf'}, 'expected': '90234-0823jsjfsfsuf'},
{'case': {'app_id': 'fajslfaw084578fsdfj'}, 'expected': 'fajslfaw084578fsdfj'},
{'case': {'app_id': ' abc def ghi '}, 'expected': 'abc def ghi'},
]

for test_case in test_cases:
config = clean_config(test_case['case'])
assert config['app_id'] == test_case['expected']

0 comments on commit 291e140

Please sign in to comment.