def test_default_validator(self): expect_pass = {'attribute': 'foobar'} self.assertTrue( validator.validate(expect_pass, validator.DEFAULT_VALIDATOR)) expect_fail = {'attribute': 0} self.assertFalse( validator.validate(expect_fail, validator.DEFAULT_VALIDATOR))
def test_validate(self): fixture = { 'foo': lambda val: val is True } self.assertTrue( validator.validate({'foo': True}, fixture)) self.assertFalse( validator.validate({'foo': False}, fixture))
def test_default_validator(self): expect_pass = { 'attribute': 'foobar' } self.assertTrue(validator.validate(expect_pass, validator.DEFAULT_VALIDATOR)) expect_fail = { 'attribute': 0 } self.assertFalse(validator.validate(expect_fail, validator.DEFAULT_VALIDATOR))
def test_only_tests_intersect(self): """Test that validator.validate only tests the intersect of keys from args and validator. """ fixture = { 'foo': lambda val: True, 'bar': lambda val: True } self.assertTrue( validator.validate({'foo': True}, fixture)) self.assertTrue( validator.validate({'foo': True, 'bar': True}, fixture)) self.assertTrue( validator.validate({'foo': True, 'bar': True, 'baz': True}, fixture))
def test_only_tests_intersect(self): """Test that validator.validate only tests the intersect of keys from args and validator. """ fixture = {'foo': lambda val: True, 'bar': lambda val: True} self.assertTrue(validator.validate({'foo': True}, fixture)) self.assertTrue(validator.validate({ 'foo': True, 'bar': True }, fixture)) self.assertTrue( validator.validate({ 'foo': True, 'bar': True, 'baz': True }, fixture))
def test_validate(self): fixture = {'foo': lambda val: val is True} self.assertTrue(validator.validate({'foo': True}, fixture)) self.assertFalse(validator.validate({'foo': False}, fixture))
def __call__(self, req): if validator.validate(req.environ['ec2.request'].args, validator.DEFAULT_VALIDATOR): return self.application else: raise webob.exc.HTTPBadRequest()