How to use the masonite.validation.Validator.Validator function in masonite

To help you get started, we’ve selected a few masonite examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MasoniteFramework / masonite / tests / validation / test_validation.py View on Github external
def test_is_in(self):
        validate = Validator().validate({
            'test': 1
        }, is_in(['test'], [1, 2, 3]))

        self.assertEqual(len(validate), 0)

        validate = Validator().validate({
            'test': 1
        }, is_in(['test'], [4, 2, 3]))

        self.assertEqual(validate, {'test': ['test must contain an element in [4, 2, 3]']})
github MasoniteFramework / masonite / tests / validation / test_validation.py View on Github external
def test_dot_required(self):
        validate = Validator().validate({
            'user': {
                'email': 'user@example.com'
            }
        }, required(['user.id']))

        self.assertEqual(validate, {'user.id': ['user.id is required']})

        validate = Validator().validate({
            'user': {
                'id': 1
            }
        }, required(['user.id']))

        self.assertEqual(len(validate), 0)
github MasoniteFramework / masonite / tests / validation / test_validation.py View on Github external
def test_loaded_validator_class(self):
        self.assertIsInstance(self.app.make(Validator), Validator)
github MasoniteFramework / masonite / tests / validation / test_validation.py View on Github external
def test_enclosure_can_encapsulate_rules(self):
        validate = Validator().validate({
            'username': 'user123',
            'email': 'user@example.com',
            'terms': 'on'
        }, MockRuleEnclosure)

        self.assertEqual(len(validate), 0)
github MasoniteFramework / masonite / tests / validation / test_validation.py View on Github external
def test_exists(self):
        validate = Validator().validate({
            'terms': 'on',
            'user': 'here',
        }, exists(['user']))

        self.assertEqual(len(validate), 0)

        validate = Validator().validate({
            'terms': 'test'
        }, exists(['user']))

        self.assertEqual(validate, {'user': ['user must exist']})
github MasoniteFramework / masonite / tests / validation / test_validation.py View on Github external
def test_numeric(self):
        validate = Validator().validate({
            'test': 1
        }, numeric(['test']))

        self.assertEqual(len(validate), 0)

        validate = Validator().validate({
            'test': 'hey'
        }, numeric(['test']))

        self.assertEqual(validate, {'test': ['test must be a numeric']})
github MasoniteFramework / masonite / tests / validation / test_validation.py View on Github external
def test_several_tests(self):
        validate = Validator().validate({
            'test': 'hey'
        }, required(['notin']), numeric(['notin']))

        self.assertEqual(validate, {'notin': ['notin is required', 'notin must be a numeric']})
github MasoniteFramework / masonite / tests / validation / test_validation.py View on Github external
def test_dot_in_range(self):
        validate = Validator().validate({
            'user': {
                'id': 1,
                'email': 'user@example.com',
                'age': 25
            }
        }, in_range(['user.age'], min=25, max=72))

        self.assertEqual(len(validate), 0)

        validate = Validator().validate({
            'user': {
                'id': 1,
                'email': 'user@example.com',
                'age': 25
            }
        }, in_range(['user.age'], min=27, max=72))
github MasoniteFramework / masonite / tests / validation / test_validation.py View on Github external
def test_exception(self):
        with self.assertRaises(AttributeError) as e:
            validate = Validator().validate({
                'terms': 'on',
            }, required(['user'], raises={
                'user': AttributeError
            }))

        try:
            validate = Validator().validate({
                'terms': 'on',
            }, required(['user'], raises={
                'user': AttributeError
            }))
        except AttributeError as e:
            self.assertEqual(str(e), 'user is required')
        
        try:
            validate = Validator().validate({
github MasoniteFramework / masonite / tests / validation / test_validation.py View on Github external
def test_before_today(self):
        validate = Validator().validate({
            'date': '1975-05-21T22:00:00',
        }, before_today(['date']))

        self.assertEqual(len(validate), 0)

        validate = Validator().validate({
            'date': pendulum.yesterday().to_datetime_string(),
        }, before_today(['date']))

        self.assertEqual(len(validate), 0)

        validate = Validator().validate({
            'date': '2020-05-21T22:00:00',
        }, before_today(['date']))

        self.assertEqual(validate, {'date': ['date must be a date before today']})