def schedule_json(self) -> Optional[Dict]: """Get schedule parameter json object. This is requests from java gateway interface.""" if not self.schedule: return None else: start_time = conv_to_schedule( self.start_time if self.start_time else datetime.now()) end_time = conv_to_schedule( self.end_time if self.end_time else MAX_DATETIME) return { "startTime": start_time, "endTime": end_time, "crontab": self.schedule, "timezoneId": self.timezone, }
}, ), # Test None value ( "2021/01/01 01:02:03", None, { "start_time": "2021-01-01 01:02:03", "end_time": "9999-12-31 23:59:59" }, ), ( None, None, { "start_time": conv_to_schedule(datetime(2021, 1, 1)), "end_time": "9999-12-31 23:59:59", }, ), ], ) def test_schedule_json_start_and_end_time(start_time, end_time, expect_date): """Test function schedule_json about handle start_time and end_time. Only two datetime test cases here because we have more test cases in tests/utils/test_date.py file. """ schedule = "0 0 0 * * ? *" expect = { "crontab": schedule, "startTime": expect_date["start_time"], "endTime": expect_date["end_time"],
def test_conv_to_schedule(src: datetime, expect: str) -> None: """Test function conv_to_schedule.""" assert expect == conv_to_schedule(src)