class Book(models.Model): __tablename__ = 'good_books' id = fields.AutoField() author = fields.ForeignKeyField(Author, 'books', is_nullable=True, on_delete=sql.CASCADE) title = fields.CharField(default='Title') pages = fields.IntegerField(default=100) coauthor = fields.ForeignKeyField(Author, 'cobooks', is_nullable=True, on_delete=sql.NO_ACTION) rating = fields.IntegerField(default=10) name = fields.CharField(default='Book name')
def test_typed_field_error(): field = fields.CharField(name='str_field') with pytest.raises(FieldError): field.__set__(MockModel(), 1)
def test_sized_field_error(): field = fields.CharField(name='sized', max_length=1) with pytest.raises(FieldError): field.__set__(MockModel(), 'wqe')
def test_field_is_nullable_and_has_no_default_raise_error(): field = fields.CharField(name='field', is_nullable=False, default=None) with pytest.raises(FieldError): field.__set__(MockModel(), None)
class Author(models.Model): id = fields.AutoField() name = fields.CharField()