def test_get_future_date(self): now = datetime.datetime.now() future_date_str = get_future_date(60) extra_days = datetime.datetime.strptime( future_date_str, "%a, %d-%b-%Y %H:%M:%S GMT") - now # +- 1 day is acceptable here assert extra_days.days in range(59, 60)
def process_response(self, request, response): global_bar_seen = self.get_global_bar_seen(request) if global_bar_seen in (None, False): if request.cookie_preferences_set: value = False if global_bar_seen is False: value = True response.set_cookie( settings.GLOBAL_BAR_SEEN_COOKIE_NAME, json.dumps(value), expires=get_future_date( days=settings.COOKIE_SETTINGS_CONFIRMATION_BANNER ), ) return response
def form_valid(self, form): response = super().form_valid(form) data = {} # convert from values to bool for k, v in form.cleaned_data.items(): data[k] = bool(util.strtobool(v)) settings_expires = get_future_date( days=settings.COOKIE_SETTINGS_EXPIRY) response.set_cookie( settings.COOKIE_SETTINGS_COOKIE_NAME, json.dumps(data), expires=settings_expires, ) response.set_cookie( settings.COOKIE_PREFERENCES_SET_COOKIE_NAME, json.dumps(True), expires=settings_expires, ) return response