Skip to content

Commit

Permalink
#1678 source fb marketing: add validation for the date range in the f…
Browse files Browse the repository at this point in the history
…uture
  • Loading branch information
davydov-d committed Apr 14, 2023
1 parent b4f3853 commit 4cd0414
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Expand Up @@ -59,6 +59,8 @@ def check_connection(self, logger: logging.Logger, config: Mapping[str, Any]) ->
try:
config = self._validate_and_transform(config)

if config.end_date > pendulum.now():
return False, "Date range can not be in the future."
if config.end_date < config.start_date:
return False, "end_date must be equal or after start_date."

Expand Down
Expand Up @@ -58,6 +58,14 @@ def test_check_connection_ok(self, api, config, logger_mock):
api.assert_called_once_with(account_id="123", access_token="TOKEN")
logger_mock.info.assert_called_once_with(f"Select account {api.return_value.account}")

def test_check_connection_future_date_range(self, api, config, logger_mock):
config["start_date"] = "2219-10-10T00:00:00"
config["end_date"] = "2219-10-11T00:00:00"
assert SourceFacebookMarketing().check_connection(logger_mock, config=config) == (
False,
"Date range can not be in the future.",
)

def test_check_connection_end_date_before_start_date(self, api, config, logger_mock):
config["start_date"] = "2019-10-10T00:00:00"
config["end_date"] = "2019-10-09T00:00:00"
Expand Down

0 comments on commit 4cd0414

Please sign in to comment.