Skip to content

Commit

Permalink
test cov 100
Browse files Browse the repository at this point in the history
  • Loading branch information
Ksauder committed Sep 20, 2024
1 parent 294791c commit 67a2b1c
Showing 1 changed file with 43 additions and 7 deletions.
50 changes: 43 additions & 7 deletions tests/test_orm_metaclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,49 @@ class Category(models.Model):
class Meta:
app_label = "tests"

with pytest.raises(ConfigError, match="Specify either `exclude` or `fields`"):
with pytest.raises(ValidationError, match="Specify either `exclude` or `fields`"):

class CategorySchema(ModelSchema):
class CategorySchema1(ModelSchema):
class Meta:
model = Category

with pytest.raises(ValidationError, match="Specify either `exclude` or `fields`"):

class CategorySchema2(ModelSchema):
class Meta:
model = Category
exclude = ["title"]
fields = ["title"]

with pytest.raises(
ValidationError,
match="Use only `optional_fields`, `fields_optional` is deprecated.",
):

class CategorySchema3(ModelSchema):
class Meta:
model = Category
fields = "__all__"
fields_optional = ["title"]
optional_fields = ["title"]

with pytest.raises(
ConfigError,
match="'title' is defined in class body and in Meta.fields or implicitly in Meta.excluded",
):

class CategorySchema4(ModelSchema):
title: str

class Meta:
model = Category
fields = "__all__"

class CategorySchema5(ModelSchema):
class Config:
model = Category
fields = "__all__"


def test_optional():
class OptModel(models.Model):
Expand Down Expand Up @@ -179,15 +216,14 @@ class Meta:


def test_model_schema_without_config():
# do not raise on creation of class
class NoConfigSchema(ModelSchema):
x: int

with pytest.raises(
ConfigError,
match=r"No model set for class 'NoConfigSchema'",
):
# do not raise on creation of class
class NoConfigSchema(ModelSchema):
x: int

# instead raise in instantiation
NoConfigSchema(x=1)


Expand Down

0 comments on commit 67a2b1c

Please sign in to comment.