def test_bad_cookie_value(self): request = self.factory.get(self.requested_url) if self.key in request.session: del request.session[self.key] request.COOKIES[self.key] = self.value res = functions.get_config_value(request, self.key, self.int_default) self.assertEqual(res, self.int_default)
def test_found_in_cookie(self): request = self.factory.get(self.requested_url) if request.session.get(self.key): del request.session[self.key] request.COOKIES[self.key] = self.value res = functions.get_config_value(request, self.key, self.str_default) self.assertEqual(res, self.value)
def test_return_default(self): key = 'NOT FOUND ANYWHERE' request = self.factory.get(self.requested_url) if request.session.get(key): del request.session[key] if request.COOKIES.get(key): del request.COOKIES[key] res = functions.get_config_value(request, key, self.str_default) self.assertEqual(res, self.str_default)
def test_return_default_no_settings(self): key = "TESTSERVER" request = self.factory.get(self.requested_url) if request.session.get(key): del request.session[key] if request.COOKIES.get(key): del request.COOKIES[key] res = functions.get_config_value(request, key, self.str_default, search_in_settings=False) self.assertEqual(res, self.str_default)
def test_found_in_config(self): key = 'TESTSERVER' value = 'http://testserver' request = self.factory.get(self.requested_url) if request.session.get(key): del request.session[key] if request.COOKIES.get(key): del request.COOKIES[key] res = functions.get_config_value(request, key, self.str_default) self.assertEqual(res, value)
def test_return_default_no_settings(self): key = 'TESTSERVER' request = self.factory.get(self.requested_url) if request.session.get(key): del request.session[key] if request.COOKIES.get(key): del request.COOKIES[key] res = functions.get_config_value(request, key, self.str_default, search_in_settings=False) self.assertEqual(res, self.str_default)
def test_session_gets_set(self): request = self.factory.get(self.requested_url) request.session[self.key] = self.value functions.get_config_value(request, self.key, self.int_default) self.assertEqual(request.session[self.key], self.int_default)
def test_float_default_value(self): default = 30.1 request = self.factory.get(self.requested_url) request.session[self.key] = self.value res = functions.get_config_value(request, self.key, default) self.assertEqual(res, self.value)
def get_log_length(request): return utils.get_config_value(request, 'INSTANCE_LOG_LENGTH', settings.INSTANCE_LOG_LENGTH)
def get_page_size(request): return utils.get_config_value(request, 'API_RESULT_PAGE_SIZE', settings.API_RESULT_PAGE_SIZE)