def then_next_run_is_on_monday(context, time): data = get_json_data(context.response) next_run = parse_date(data.get("next_run")) fmt = "%H:%M:%S" try: # assume time is set in given time zone tz = pytz.timezone(data["schedule"]["time_zone"]) except KeyError: # fallback to utc tz = pytz.utc parsed = datetime.strptime(time, fmt) expected = datetime.now(tz) expected = expected.replace(hour=parsed.hour, minute=parsed.minute, second=parsed.second, microsecond=0) if expected < utcnow(): # make sure it's monday in future expected = expected + timedelta(days=(7 - expected.weekday())) expected_utc = local_to_utc(tz.zone, expected) assert isinstance(next_run, datetime) if tz.zone == "Australia/Sydney": assert next_run.weekday() == 6 else: assert next_run.weekday() == 0 assert next_run.strftime(fmt) == expected_utc.strftime( fmt), "next run %s is not expected %s" % ( next_run.strftime(fmt), expected_utc.strftime(fmt), )
def then_next_run_is_on_monday(context, time): data = get_json_data(context.response) next_run = parse_date(data.get('next_run')) fmt = '%H:%M:%S' try: # assume time is set in given time zone tz = pytz.timezone(data['schedule']['time_zone']) except KeyError: # fallback to utc tz = pytz.utc parsed = datetime.strptime(time, fmt) expected = datetime.now(tz) expected += timedelta(((-expected.weekday()) + 7) % 7) expected = expected.astimezone(tz) expected = expected.replace(hour=parsed.hour, minute=parsed.minute, second=parsed.second, microsecond=0) expected_utc = expected.astimezone(pytz.utc) assert isinstance(next_run, datetime) if tz.zone == 'Australia/Sydney': assert next_run.weekday() == 6 else: assert next_run.weekday() == 0 assert next_run.strftime(fmt) == expected_utc.strftime(fmt), \ 'next run %s is not expected %s' % (next_run.strftime(fmt), expected_utc.strftime(fmt))
def then_next_run_is_on_monday(context, time): data = get_json_data(context.response) next_run = parse_date(data.get('next_run')) assert isinstance(next_run, datetime) assert next_run.weekday() == 0 assert next_run.strftime('%H%M') == time assert next_run.strftime('%S') == '00', 'there should be no seconds, but it was %s' % (next_run.strftime('%S'), )
def then_next_run_is_on_monday(context, time): data = get_json_data(context.response) next_run = parse_date(data.get('next_run')) assert isinstance(next_run, datetime) assert next_run.weekday() == 0 assert next_run.strftime('%H%M') == time assert next_run.strftime( '%S') == '00', 'there should be no seconds, but it was %s' % ( next_run.strftime('%S'), )
def then_next_run_is_on_monday(context, time): data = get_json_data(context.response) next_run = parse_date(data.get('next_run')) assert isinstance(next_run, datetime) assert next_run.weekday() == 0 assert next_run.strftime('%H:%M:%S') == time, 'it is %s' % (next_run, )