def should_raise_validation_error(self): assert_raises_with_message( ValidationError, "Cannot push values onto non-array field of <type 'int'>", validate_update_modifier, {'$pushAll': {'field': [1]}}, {'field': int})
def should_raise_validation_error(self): assert_raises_with_message( ValidationError, "Cannot rename field of type [<type 'int'>] to field of type [<type 'float'>]", validate_update_modifier, {'$rename': {'old_field': 'new_field'}}, {'old_field': [int], 'new_field': [float]})
def should_raise_validation_error(self): assert_raises_with_message( ValidationError, "Cannot push value 1.1 onto array of <type 'int'>", validate_update_modifier, {'$pushAll': {'field': [1, 1.1]}}, {'field': [int]})
def when_validating_document_with_string_mapped_to_float_should_fail_validation(): doc = DocumentWithEmbeddedDictOfStringToInt({ 'field': {'foo': 1, u'bar': 2.3}}) assert_raises_with_message( ValidationError, "Position 'field.bar' was declared to be <type 'int'>, but encountered value 2.2999999999999998", doc.validate)
def should_raise_validation_error(self): assert_raises_with_message( ValidationError, "Cannot use modifier $pushAll with non-array argument 1", validate_update_modifier, {'$pushAll': {'field': 1}}, {'field': [int]})
def should_raise_validation_error(self): assert_raises_with_message( ValidationError, "Cannot increment non-numeric field of declared as <type 'datetime.datetime'>", validate_update_modifier, {'$inc': {'field': 1}}, {'field': datetime.datetime})
def should_raise_ValidationError(self): assert_raises_with_message( ValidationError, "Cannot push value {'a': 'Not a number', 'b': 'foo'} onto array of" " {'a': <type 'int'>, 'b': <type 'basestring'>}:" " Position 'a' was declared to be <type 'int'>, but encountered value 'Not a number'", validate_update_modifier, {'$push': {'list_of_docs': {'a': 'Not a number', 'b': 'foo'}}}, {'list_of_docs': [{'a': int, 'b': basestring}]}, )
def should_raise_validation_error(self): assert_raises_with_message( ValidationError, "Encountered unknown update modifier '$unknown'", validate_update_modifier, {'$unknown': {'field': 1}}, {'field': int})
def should_raise_validation_error(self): assert_raises_with_message( ValidationError, "Cannot $addToSet value 1 onto array of <type 'float'>", validate_update_modifier, {'$addToSet': {'field': 1}}, {'field': [float]})
def should_raise_validation_error(self): assert_raises_with_message( ValidationError, "Cannot push value 1 onto array field of type float", validate_update_modifier, {'$push': {'field': 1}}, {'field': [float]})
def should_raise_validation_error(self): assert_raises_with_message( ValidationError, "Position 'field' was declared to be <type 'str'>, but encountered value 1", validate_update_modifier, {'$set': {'field': 1}}, {'field': str})
def should_not_crash(self): assert_raises_with_message( ValidationError, 'Position <Dingus path> was declared to be <Dingus expected_type>, but encountered value <Dingus value>', validate_single_field, self.path, self.value, self.expected_type)
def when_validating_with_list_of_int_should_fail(): assert_raises_with_message( ValidationError, "Position 'field' was declared to be <OR <type 'int'>, <type 'basestring'>>, but encountered value [1]", DocumentWithMultiplePotentialTypes({'field': [1]}).validate)
def when_validating_document_with_extra_fields_should_raise_error(): doc = DocumentWithListOfStrings({'unknown': 1}) assert_raises_with_message( ValidationError, "Encountered field(s) not present in structure: 'unknown'", doc.validate)
def when_validating_document_with_list_of_numbers(): assert_raises_with_message( ValidationError, "Position 'field.0' was declared to be <type 'basestring'>, but encountered value 1", DocumentWithListOfStrings({'field': [1]}).validate)
def when_validating_with_2_should_fail(): assert_raises_with_message( ValidationError, "Position 'field' was declared to be <IS 1, 'foo'>, but encountered value 2", DocumentWithMultiplePotentialValues({'field': 2}).validate)