Exemplo n.º 1
0
 def test_required(self):
     req_string_validator = validators.StringValidator()
     not_req_string_validator = validators.StringValidator(required=False)
     dict_validator = validators.DictValidator({
         'req':
         req_string_validator,
         'opt':
         not_req_string_validator,
     })
     valid_dict = {'req': 'abc'}
     valid_dict2 = {'req': 'abc', 'opt': 'def'}
     invalid_dict = {'opt': 'def'}
     self.assertTrue(dict_validator(valid_dict))
     self.assertTrue(dict_validator(valid_dict2))
     self.assertRaises(ValidationError, dict_validator, invalid_dict)
Exemplo n.º 2
0
 def create_node(self):
     node_validator = valid.DictValidator({
         'name':
         valid.StringValidator(),
         'size_id':
         valid.StringValidator(),
         'image_id':
         valid.StringValidator(),
         'location_id':
         valid.StringValidator(required=False)
     })
     driver = self._get_driver_instance()
     try:
         node_data = json.loads(self.request.data)
     except ValueError, e:
         raise MalformedJSONError(msg=e.message)
Exemplo n.º 3
0
 def test_dict(self):
     dict_validator = validators.DictValidator(
         {'arg1': validators.StringValidator()})
     valid_dict = {'arg1': 'str'}
     invalid_dict = {'arg1': 123}
     invalid_dict2 = {'abc': 'str'}
     self.assertTrue(dict_validator(valid_dict))
     self.assertRaises(ValidationError, dict_validator, invalid_dict)
     self.assertRaises(ValidationError, dict_validator, invalid_dict2)
Exemplo n.º 4
0
 def test_name(self):
     int_validator = validators.IntegerValidator(name='test')
     invalid_data = 'abc'
     self.assertRaisesRegexp(ValidationError, 'test.*', int_validator,
                             invalid_data)
     dict_validator = validators.DictValidator(
         {'test_name': validators.ConstValidator('333')})
     self.assertRaisesRegexp(ValidationError, 'test_name .*',
                             dict_validator, {})
     str_validator = validators.StringValidator()
     self.assertRaisesRegexp(ValidationError,
                             '%s .*' % (str_validator.default_name),
                             str_validator, {})
Exemplo n.º 5
0
 def test_string(self):
     string_validator = validators.StringValidator()
     valid_string = 'abc'
     invalid_type = 123
     self.assertTrue(string_validator(valid_string))
     self.assertRaises(ValidationError, string_validator, invalid_type)