Skip to content

Commit 67a2b1c

Browse files
committed
test cov 100
1 parent 294791c commit 67a2b1c

File tree

1 file changed

+43
-7
lines changed

1 file changed

+43
-7
lines changed

tests/test_orm_metaclass.py

+43-7
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,49 @@ class Category(models.Model):
9393
class Meta:
9494
app_label = "tests"
9595

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

98-
class CategorySchema(ModelSchema):
98+
class CategorySchema1(ModelSchema):
9999
class Meta:
100100
model = Category
101101

102+
with pytest.raises(ValidationError, match="Specify either `exclude` or `fields`"):
103+
104+
class CategorySchema2(ModelSchema):
105+
class Meta:
106+
model = Category
107+
exclude = ["title"]
108+
fields = ["title"]
109+
110+
with pytest.raises(
111+
ValidationError,
112+
match="Use only `optional_fields`, `fields_optional` is deprecated.",
113+
):
114+
115+
class CategorySchema3(ModelSchema):
116+
class Meta:
117+
model = Category
118+
fields = "__all__"
119+
fields_optional = ["title"]
120+
optional_fields = ["title"]
121+
122+
with pytest.raises(
123+
ConfigError,
124+
match="'title' is defined in class body and in Meta.fields or implicitly in Meta.excluded",
125+
):
126+
127+
class CategorySchema4(ModelSchema):
128+
title: str
129+
130+
class Meta:
131+
model = Category
132+
fields = "__all__"
133+
134+
class CategorySchema5(ModelSchema):
135+
class Config:
136+
model = Category
137+
fields = "__all__"
138+
102139

103140
def test_optional():
104141
class OptModel(models.Model):
@@ -179,15 +216,14 @@ class Meta:
179216

180217

181218
def test_model_schema_without_config():
219+
# do not raise on creation of class
220+
class NoConfigSchema(ModelSchema):
221+
x: int
222+
182223
with pytest.raises(
183224
ConfigError,
184225
match=r"No model set for class 'NoConfigSchema'",
185226
):
186-
# do not raise on creation of class
187-
class NoConfigSchema(ModelSchema):
188-
x: int
189-
190-
# instead raise in instantiation
191227
NoConfigSchema(x=1)
192228

193229

0 commit comments

Comments
 (0)