import time import datetime import cookielib __author__ = 'regu0004' if __name__ == '__main__': # Set expiration date 5 minutes into the future utc_now = datetime.datetime.utcnow() dt = datetime.timedelta(minutes=5) utc_future = utc_now + dt expires = time.mktime(utc_future.timetuple()) name = "test" value = "cookie" cookie = cookielib.Cookie(0, name, value, None, False, "", False, False, "", False, False, expires, False, None, None, {}) # Assert cookie has not expired utc_now = time.mktime(datetime.datetime.utcnow().timetuple()) local_now = time.time() assert not cookie.is_expired(utc_now) # Functions/methods in the cookielib module uses time.time() which retrieves the epoch time in local time assert not cookie.is_expired(time.time())