<s> from django_laravel_validator . exceptions import InvalidMinValidatorParameterError <EOL> from django_laravel_validator . utils import check_errors <EOL> from django_laravel_validator . validator import Validator <EOL> from . messages import * <EOL> class TestValidator1 ( Validator ) : <EOL> username = '<STR_LIT>' <EOL> password = '<STR_LIT>' <EOL> def check ( self ) : <EOL> username = self . data . get ( '<STR_LIT:username>' ) <EOL> password = self . data . get ( '<STR_LIT:password>' ) <EOL> if username != '<STR_LIT>' : <EOL> self . error_list . get ( '<STR_LIT:username>' ) . update ( dict ( wrong_user = u'<STR_LIT>' ) ) <EOL> if password != '<STR_LIT>' : <EOL> self . error_list . get ( '<STR_LIT:password>' ) . update ( dict ( wrong_pass = u'<STR_LIT>' ) ) <EOL> class TestValidator2 ( Validator ) : <EOL> username = '<STR_LIT>' <EOL> password = '<STR_LIT>' <EOL> def check ( self ) : <EOL> print '<STR_LIT>' <EOL> class TestValidator3 ( Validator ) : <EOL> username = '<STR_LIT>' <EOL> password = '<STR_LIT>' <EOL> class TestValidator4 ( Validator ) : <EOL> username = '<STR_LIT>' <EOL> password = '<STR_LIT>' <EOL> class TestValidator5 ( Validator ) : <EOL> username = '<STR_LIT>' <EOL> password = '<STR_LIT>' <EOL> class TestValidator6 ( Validator ) : <EOL> username = '<STR_LIT>' <EOL> password = '<STR_LIT>' <EOL> remember_me = '<STR_LIT>' <EOL> email = '<STR_LIT>' <EOL> ip = '<STR_LIT>' <EOL> is_superuser = '<STR_LIT:bool>' <EOL> phone = '<STR_LIT>' <EOL> class MatchValidatorTestValidator ( Validator ) : <EOL> password = '<STR_LIT>' <EOL> password_confirm = '<STR_LIT>' <EOL> class UniqueValidatorTestValidator ( Validator ) : <EOL> email = '<STR_LIT>' <EOL> def test_match_validator ( ) : <EOL> data = dict ( password = '<STR_LIT>' , password_confirm = '<STR_LIT>' ) <EOL> validator = MatchValidatorTestValidator ( data ) <EOL> ret = validator . fails ( ) <EOL> assert ret <EOL> def test_validator ( ) : <EOL> data = dict ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> validator = TestValidator1 ( data ) <EOL> ret = validator . fails ( ) <EOL> error_list = validator . errors ( ) <EOL> assert ret is True <EOL> assert check_errors ( error_list , None ) <EOL> data = dict ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> validator = TestValidator1 ( data ) <EOL> ret = validator . fails ( ) <EOL> error_list = validator . errors ( ) <EOL> assert ret is False <EOL> assert check_errors ( error_list , None ) is False <EOL> def test_validator2 ( ) : <EOL> data = dict ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> validator = TestValidator2 ( data ) <EOL> ret = validator . fails ( ) <EOL> error_list = validator . errors ( ) <EOL> assert ret is True <EOL> assert check_errors ( error_list , None ) is True <EOL> data = dict ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> validator = TestValidator2 ( data ) <EOL> ret = validator . fails ( ) <EOL> error_list = validator . errors ( ) <EOL> assert ret is False <EOL> assert error_list . get ( '<STR_LIT:username>' ) . get ( '<STR_LIT>' ) == REQUIRED_MESSAGE <EOL> assert error_list . get ( '<STR_LIT:username>' ) . get ( '<STR_LIT>' ) == MIN_MESSAGE . format ( min = <NUM_LIT:8> ) <EOL> assert error_list . get ( '<STR_LIT:username>' ) . get ( '<STR_LIT>' ) == NUMERIC_MESSAGE <EOL> assert error_list . get ( '<STR_LIT:password>' ) . get ( '<STR_LIT>' ) == MIN_MESSAGE . format ( min = <NUM_LIT:8> ) <EOL> assert error_list . get ( '<STR_LIT:password>' ) . get ( '<STR_LIT>' ) == NUMERIC_MESSAGE <EOL> def test_validator3 ( ) : <EOL> data = dict ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> validator = TestValidator3 ( data ) <EOL> try : <EOL> ret = validator . fails ( ) <EOL> except InvalidMinValidatorParameterError as e : <EOL> pass <EOL> def test_validator4 ( ) : <EOL> data = dict ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> message = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> validator = TestValidator4 ( data , message = message ) <EOL> ret = validator . fails ( ) <EOL> error_list = validator . errors ( ) <EOL> assert ret is False <EOL> assert error_list . get ( '<STR_LIT:username>' ) . get ( '<STR_LIT>' ) == '<STR_LIT>' <EOL> assert error_list . get ( '<STR_LIT:password>' ) . get ( '<STR_LIT>' ) == '<STR_LIT>' <EOL> assert error_list . get ( '<STR_LIT:username>' ) . get ( '<STR_LIT>' ) == '<STR_LIT>' <EOL> assert error_list . get ( '<STR_LIT:username>' ) . get ( '<STR_LIT>' ) == NUMERIC_MESSAGE <EOL> def test_validator5 ( ) : <EOL> data = dict ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> validator = TestValidator5 ( data ) <EOL> ret = validator . fails ( ) <EOL> error_list = validator . errors ( ) <EOL> assert ret is False <EOL> assert error_list . get ( '<STR_LIT:username>' ) . get ( '<STR_LIT>' ) == REQUIRED_MESSAGE <EOL> assert error_list . get ( '<STR_LIT:username>' ) . get ( '<STR_LIT>' ) == MIN_MESSAGE . format ( min = <NUM_LIT:8> ) <EOL> assert error_list . get ( '<STR_LIT:username>' ) . get ( '<STR_LIT>' ) == MAX_MESSAGE . format ( max = <NUM_LIT:16> ) <EOL> assert error_list . get ( '<STR_LIT:username>' ) . get ( '<STR_LIT>' ) == ALPHA_MESSAGE <EOL> assert error_list . get ( '<STR_LIT:password>' ) . get ( '<STR_LIT>' ) == REQUIRED_MESSAGE <EOL> assert error_list . get ( '<STR_LIT:password>' ) . get ( '<STR_LIT>' ) == RANGE_MESSAGE . format ( min = <NUM_LIT:2> , max = <NUM_LIT:5> ) <EOL> assert error_list . get ( '<STR_LIT:password>' ) . get ( '<STR_LIT>' ) == ALPHA_MESSAGE <EOL> def test_validator6 ( ) : <EOL> data = dict ( username = '<STR_LIT>' , password = '<STR_LIT:abc>' , remember_me = '<STR_LIT:1>' , email = '<STR_LIT>' , ip = '<STR_LIT>' , is_superuser = '<STR_LIT:1>' , phone = '<STR_LIT>' ) <EOL> validator = TestValidator6 ( data ) <EOL> ret = validator . fails ( ) <EOL> error_list = validator . errors ( ) <EOL> assert not error_list . get ( '<STR_LIT:username>' ) <EOL> assert not error_list . get ( '<STR_LIT:password>' ) <EOL> assert not error_list . get ( '<STR_LIT>' ) <EOL> assert not error_list . get ( '<STR_LIT:email>' ) <EOL> assert not error_list . get ( '<STR_LIT>' ) <EOL> assert not error_list . get ( '<STR_LIT>' ) <EOL> def test_validator7 ( ) : <EOL> data = dict ( username = '<STR_LIT>' , email = '<STR_LIT>' ) <EOL> validator = UniqueValidatorTestValidator ( data ) <EOL> ret = validator . fails ( ) <EOL> assert ret is True </s>
