def test_empty_dummy_request_should_fail(self): request = construct_dummy_request() fn = spec_keyword_in_json_body( (int, 'foo', lambda foo, varType: isinstance(foo, varType))) response = fn(request) self.assertIsInstance(response, bool) self.assertFalse(response)
def test_provided_int_expected_int_should_succed(self): request = construct_dummy_request(json_body={'foo': 2}) fn = spec_keyword_in_json_body( (int, 'foo', lambda foo, varType: isinstance(foo, varType))) response = fn(request) self.assertIsInstance(response, bool) self.assertTrue(response)
def test_provided_empty_string_should_fail(self): request = construct_dummy_request(json_body={'foo': ''}) fn = spec_keyword_in_json_body( (str, 'foo', lambda foo, varType: isinstance(foo, varType) and foo != '')) response = fn(request) self.assertIsInstance(response, bool) self.assertFalse(response)
from dbas.strings.translator import Translator from dbas.validators.common import valid_lang_cookie_fallback from dbas.validators.core import has_keywords_in_json_path, has_maybe_keywords, validate, spec_keyword_in_json_body from dbas.validators.notifications import valid_notification_title, valid_notification_text, \ valid_notification_recipient from dbas.validators.user import valid_user LOG = logging.getLogger(__name__) @view_config(request_method='POST', route_name='user_login', renderer='json') @validate( spec_keyword_in_json_body( (str, "user", lambda user, expected_type: isinstance( user, expected_type) and user != ""), (str, "password", lambda password, expected_type: isinstance( password, expected_type) and password != ""), (bool, 'keep_login', lambda keep_login, expected_type: isinstance( keep_login, expected_type))), has_maybe_keywords(('redirect_url', str, ''))) def user_login(request): """ Will login the user by his nickname and password :param request: request of the web server :return: dict() with error """ LOG.debug("Login user with Nickname and Password") lang = get_language_from_cookie(request) nickname = request.validated.get('user') password = request.validated.get('password')