Skip to content
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

Correctly honor the restrictions on start_date #30

Merged
merged 1 commit into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions tap_appsflyer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
24 changes: 24 additions & 0 deletions tests/unittests/test_helpers.py
Original file line number Diff line number Diff line change
@@ -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']