Пример #1
0
 def test_if_list_element_is_not_int_return_list_with_int_type_error_and_the_index_one(
         self):
     expected_error = ELEMENT_ERROR_TEMPLATE % (1,
                                                TYPE_ERROR_MSG % INT_TYPE)
     result = create_list_validator(
         validate_element=create_int_validator())([1, 'abc'])
     self.assertIn(expected_error, result)
     self.assertEqual(len(result), 1)
Пример #2
0
 def test_if_dict_element_is_not_int_return_list_with_int_type_error_and_key_equals_to_a(
         self):
     expected_error = ELEMENT_ERROR_TEMPLATE % ('a',
                                                TYPE_ERROR_MSG % INT_TYPE)
     self.assertIn(
         expected_error,
         create_dict_validator(element_validators=dict(
             a=create_int_validator()))(dict(a='abc')))
Пример #3
0
 def test_if_not_nullable_and_transform_is_not_null_and_obj_is_null_return_nullable_error(
         self):
     self.assertEqual(NULLABLE_ERROR_MSG,
                      create_int_validator(nullable=False)(None))
Пример #4
0
 def test_if_is_nullable_and_obj_is_null_return_valid(self):
     self.assertEqual(VALID, create_int_validator(nullable=True)(None))
Пример #5
0
 def test_if_int_is_greater_than_max_return_max_int_error(self):
     max_value = 2
     self.assertEqual(MAX_ERROR_MSG % (INT_TYPE, str(max_value)),
                      create_int_validator(max_=max_value)(4))
Пример #6
0
 def test_if_int_is_between_min_max_return_valid(self):
     self.assertEqual(VALID, create_int_validator(min_=2, max_=4)(3))
Пример #7
0
 def test_if_dict_elements_are_not_valid_return_list_with_errors(self):
     self.assertIsInstance(
         create_dict_validator(element_validators=dict(
             a=create_int_validator()))(dict(a='abc')), list)
Пример #8
0
 def test_if_dict_elements_are_valid_return_valid(self):
     self.assertEqual(
         VALID,
         create_dict_validator(element_validators=dict(
             a=create_int_validator()))(dict(a=1)))
Пример #9
0
 def test_if_int_is_smaller_than_min_return_min_int_error(self):
     min_value = 2
     self.assertEqual(MIN_ERROR_MSG % (INT_TYPE, str(min_value)),
                      create_int_validator(min_=min_value)(1))
Пример #10
0
 def test_if_list_elements_are_not_valid_return_list_with_errors(self):
     self.assertIsInstance(
         create_list_validator(validate_element=create_int_validator())(
             ['abc']), list)
Пример #11
0
 def test_if_list_elements_are_valid_return_valid(self):
     self.assertEqual(
         VALID,
         create_list_validator(validate_element=create_int_validator())(
             [1, 2, 3]))
Пример #12
0
 def test_if_obj_is_not_int_return_int_type_error(self):
     self.assertEqual(TYPE_ERROR_MSG % INT_TYPE,
                      create_int_validator()(str()))
Пример #13
0
 def test_if_obj_is_int_return_valid(self):
     self.assertEqual(VALID, create_int_validator()(int()))