Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_embedded_model(model):
entity = model()
assert entity.secondary is None
entity.name = 'chuck'
entity.secondary = Secondary()
entity.secondary.data = 42
with pytest.raises(errors.ValidationError):
entity.secondary = 'something different'
entity.secondary = None
def _check_types(self):
if self.types is None:
raise ValidationError(
'Field "{type}" is not usable, try '
'different field type.'.format(type=type(self).__name__))
def _get_topic(obj):
try:
return getattr(obj, 'topic', None)
except errors.ValidationError:
return None
def _check_against_required(self, value):
if value is None and self.required:
raise ValidationError('Field is required!')