diff --git a/tap_appsflyer/__init__.py b/tap_appsflyer/__init__.py index 021bc73..f2851ab 100644 --- a/tap_appsflyer/__init__.py +++ b/tap_appsflyer/__init__.py @@ -39,12 +39,20 @@ def af_datetime_str_to_datetime(s): return datetime.datetime.strptime(s.strip(), "%Y-%m-%d %H:%M:%S") +def get_restricted_start_date(date: str) -> datetime.datetime: + # https://support.appsflyer.com/hc/en-us/articles/207034366-API-Policy + restriction_date = datetime.datetime.now() - datetime.timedelta(days=90) + start_date = utils.strptime(date) + + return max(start_date, restriction_date) + + def get_start(key): if key in STATE: - return utils.strptime(STATE[key]) + return get_restricted_start_date(STATE[key]) if "start_date" in CONFIG: - return utils.strptime(CONFIG["start_date"]) + return get_restricted_start_date(CONFIG["start_date"]) return datetime.datetime.now() - datetime.timedelta(days=30) diff --git a/tests/unittests/test_helpers.py b/tests/unittests/test_helpers.py new file mode 100644 index 0000000..8674fd6 --- /dev/null +++ b/tests/unittests/test_helpers.py @@ -0,0 +1,24 @@ +import datetime +from unittest.mock import patch + +from tap_appsflyer import get_restricted_start_date + +MOCKED_DATE = datetime.datetime(2021, 7, 1, 1, 1, 1, 369251) + +class MockedDatetime(datetime.datetime): + def now(): + return MOCKED_DATE + +@patch('datetime.datetime', MockedDatetime) +def test_get_restricted_start_date(): + test_cases = [ + {'case': '2018-01-01T00:00:00Z', 'expected': datetime.datetime(2021, 4, 2, 1, 1, 1, 369251)}, + {'case': '2021-07-27T00:00:00Z', 'expected': datetime.datetime(2021, 7, 27, 0, 0)}, + {'case': '2021-04-02T00:00:00Z', 'expected': datetime.datetime(2021, 4, 2, 1, 1, 1, 369251)}, + {'case': '2021-05-23T12:34:56Z', 'expected': datetime.datetime(2021, 5, 23, 12, 34, 56)}, + ] + + for test_case in test_cases: + date = get_restricted_start_date(test_case['case']) + + assert date == test_case['expected']