def test_email_rule_fails(self):
        emails = [
            'Abc.example.com',
            'A@b@[email protected]',
            'a"b(c)d,e:f;g<h>i[j\k][email protected]',
            'just"not"*****@*****.**',
            'thisis"not\[email protected]',
            'this\ still\"*****@*****.**',
            'plainaddress',
            '#@%^%#$@#$@#.com',
            '@example.com',
            'Joe Smith < *****@*****.** >',
            'email.example.com',
            'email@[email protected]',
            '*****@*****.**',
            '*****@*****.**',
            '*****@*****.**',
            'email@example',
            '.333',
            '.44444',
            'email @ example..com',
            'Abc.',
            '.123 @ example.com',
            '[email protected]',
            'あいうえお@example.com',
            '*****@*****.**',
            '[email protected] (Joe Smith)',
        ]

        for email in emails:
            v = Validator({'email': email}, {'email': 'required|email'})
            self.assertTrue(v.fails())
    def test_max_fails(self):
        validation = Validator({
            'age': 9,
            'height': 251
        }, {
            'age': 'max:100',
            'height': 'max:250'
        })

        self.assertTrue(validation.fails())
        self.assertTrue('height' in validation.failed_rules)
    def test_regex_fail(self):

        inv = ['AA45aa', '45aaa', 'AA@!5', 'aa@!5aaa']

        for p in inv:
            v = Validator(
                {'password': p}, {
                    'password': '******',
                })

            self.assertTrue(v.fails())
    def test_gt_fail(self):
        validation = Validator({
            'age': 17,
            'height': 10
        }, {
            'age': 'required',
            'height': 'gt:age'
        })

        self.assertTrue(validation.fails())
        self.assertTrue('height' in validation.failed_rules)
    def test_present_fails(self):
        v = Validator({
            'user': {
            }
        }, {
            'user': '******',
            'user.age': 'present'
        })

        self.assertTrue(v.fails())
        self.assertTrue('user.age' in v.failed_rules)
    def test_lte_fails(self):
        validation = Validator({
            'age': 184,
            'height': 185
        }, {
            'age': 'required',
            'height': 'lte:age'
        })

        self.assertTrue(validation.fails())
        self.assertTrue('height' in validation.failed_rules)
    def test_ipv4_and_ipv6_ips_fails(self):

        ips = [
            '1200:0000:AB00:1234:O000:2552:7777:1313', '[2001:db8:0:1]:80',
            'http://[2001:db8:0:1]:80', '256.0.0.0'
        ]

        for ip in ips:
            v = Validator({'ip': ip}, {'ip': 'ip'})

            self.assertTrue(v.fails())
    def test_min_fails(self):
        validation = Validator({
            'age': 2,
            'height': -185
        }, {
            'age': 'min:1',
            'height': 'min:1'
        })

        self.assertTrue(validation.fails())
        self.assertTrue('height' in validation.failed_rules)
    def test_required_without_all_fails_with_empty_data(self):
        v = Validator({
            'user': {
            }
        }, {
            'user': '******',
            'user.name': 'required_without_all:user.age,user.wife'
        })

        self.assertTrue(v.fails())
        self.assertTrue('user.name' in v.failed_rules)
    def test_required_unless_fails(self):
        v = Validator({
            'user': {
                'age': 25
            }
        }, {
            'user': '******',
            'user.name': 'required_unless:user.age:26,27'
        })

        self.assertTrue(v.fails())
        self.assertTrue('user.name' in v.failed_rules)
    def test_required_without_fails(self):
        v = Validator({
            'user': {
                'age': None,
            }
        }, {
            'user': '******',
            'user.name': 'required_without:user.age'
        })

        self.assertTrue(v.fails())
        self.assertTrue('user.name' in v.failed_rules)
    def test_integer_fails(self):
        validation = Validator({
            'age': 10.5,
            'height': 120
        },
        {
            'age': 'integer',
            'height': 'integer'
        })

        self.assertTrue(validation.fails())
        self.assertTrue('age' in validation.failed_rules)
    def test_between_must_fail(self):
        validation = Validator({
            'age': 9,
            'bill': -3300
        }, {
            'age': 'between:10,100',
            'bill': 'between:-3200,0'
        })

        self.assertTrue(validation.fails())
        self.assertTrue('age' in validation.failed_rules)
        self.assertTrue('bill' in validation.failed_rules)
    def test_size_must_fail(self):
        validation = Validator({
            'age': 5,
            'bill': -7,
            'count': 0
        }, {
            'age': 'size:10',
            'bill': 'size:-6',
            'count': 'size:0'
        })

        self.assertTrue(validation.fails())
    def test_gte_fails(self):
        validation = Validator({
            'age': 9,
            'height': 185,
            'width': 184,
        }, {
            'age': 'required',
            'height': 'gte:age',
            'width': 'gte:height'
        })

        self.assertTrue(validation.fails())
        self.assertTrue('height' not in validation.failed_rules)
    def test_ipv4_fails(self):

        ips = [
            '256.0.0.0', '1200::AB00:1234::2552:7777:1313',
            '1200:0000:AB00:1234:O000:2552:7777:1313', '[2001:db8:0:1]:80',
            'http://[2001:db8:0:1]:80',
            '1200:0000:AB00:1234:0000:2552:7777:1313',
            '21DA:D3:0:2F3B:2AA:FF:FE28:9C5A',
            'FE80:0000:0000:0000:0202:B3FF:FE1E:8329'
        ]

        for ip in ips:
            v = Validator({'ip': ip}, {'ip': 'ipv4'})

            self.assertTrue(v.fails())
    def test_nested_data_min_fails(self):
        validation = Validator({
            'user': {
                'name': 'john',
                'age': 20,
            },
        },
        {
            'user': '******',
            'user.name': 'required|min:4',
            'user.age': 'required|min:28',
        })

        self.assertTrue(validation.fails())
        self.assertTrue('user.age' in validation.failed_rules)
    def test_required_with_all_fails(self):
        v = Validator({
            'user': {
                'age': 26,
                'wife': {
                    'name': 'Anna',
                    'age': 20
                }
            }
        }, {
            'user': '******',
            'user.name': 'required_with_all:user.age,user.wife'
        })

        self.assertTrue(v.fails())
        self.assertTrue('user.name' in v.failed_rules)
    def test_invalid_urls(self):
        urls = [
            'http://a.b--c.de/', 'http://-error-.invalid/', 'http:///a',
            '//a', 'http://##'
        ]

        for url in urls:
            v = Validator(
                {
                    'url': url
                },
                {
                    'url': 'url'
                }
            )

            self.assertTrue(v.fails())
    def test_ipv6_fails(self):

        ips = [
            '1200:0000:AB00:1234:O000:2552:7777:1313',
            '[2001:db8:0:1]:80',
            'http://[2001:db8:0:1]:80',
            '256.0.0.0',
            '0.0.0.0',
            '9.255.255.255',
            '11.0.0.0',
            '126.255.255.255',
            '129.0.0.0',
            '169.253.255.255',
        ]

        for ip in ips:
            v = Validator({'ip': ip}, {'ip': 'ipv6'})

            self.assertTrue(v.fails())
    def test_rule_list_params_fails(self):
        v = Validator(
            {
                'name': 'johnsdfsdf',
                'email': '*****@*****.**',
                'birth_date': '1985-08-25 15:12:02',
                'height': 190
            }, {
                'name': ['required', 'string', ['min', 3], ['max', 8]],
                'email':
                ['required', 'string', 'email', ['min', 26], ['max', 32]],
                'birth_date': ['required', 'date'],
                'height': ['required', 'integer', ['max', 180]]
            }, {
                'name.max': 'must be maximum 8 chars',
                'email.min': 'must be min 26',
                'height.max': 'must be max 180',
            })

        self.assertTrue(v.fails())
        self.assertTrue('name' in v.failed_rules)
        self.assertTrue('email' in v.failed_rules)
        self.assertTrue('height' in v.failed_rules)