diff --git a/tdclient/schedule_api.py b/tdclient/schedule_api.py index b1c1de1..8d9ec3b 100644 --- a/tdclient/schedule_api.py +++ b/tdclient/schedule_api.py @@ -25,7 +25,7 @@ def create_schedule(self, name, params=None): if code != 200: self.raise_error("Create schedule failed", res, body) js = self.checked_json(body, ["start"]) - return self._parsedate(js["start"], "%Y-%m-%d %H:%M:%S %Z") + return self._parsedate(self.get_or_else(js, "start", "1970-01-01T00:00:00Z"), "%Y-%m-%d %H:%M:%S %Z") def delete_schedule(self, name): """ diff --git a/tdclient/test/schedule_api_test.py b/tdclient/test/schedule_api_test.py index cc4a4b3..b7f18bb 100644 --- a/tdclient/test/schedule_api_test.py +++ b/tdclient/test/schedule_api_test.py @@ -34,6 +34,25 @@ def test_create_schedule_success(): assert start.second == 51 assert start.utcoffset().seconds == 0 # UTC +def test_create_schedule_without_cron_success(): + td = api.API("APIKEY") + # TODO: should be replaced by wire dump + body = b""" + { + "start": null + } + """ + td.post = mock.MagicMock(return_value=make_response(200, body)) + start = td.create_schedule("bar", {"type": "presto", "cron": ""}) + td.post.assert_called_with("/v3/schedule/create/bar", {"type": "presto", "cron": ""}) + assert start.year == 1970 + assert start.month == 1 + assert start.day == 1 + assert start.hour == 0 + assert start.minute == 0 + assert start.second == 0 + assert start.utcoffset().seconds == 0 # UTC + def test_delete_schedule_success(): td = api.API("APIKEY") # TODO: should be replaced by wire dump