MCPcopy
hub / github.com/django/django / test_validate_case_when

Method test_validate_case_when

tests/constraints/tests.py:1067–1082  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1065 )
1066
1067 def test_validate_case_when(self):
1068 UniqueConstraintProduct.objects.create(name="p1")
1069 constraint = models.UniqueConstraint(
1070 Case(When(color__isnull=True, then=F("name"))),
1071 name="name_without_color_uniq",
1072 )
1073 msg = "Constraint “name_without_color_uniq” is violated."
1074 with self.assertRaisesMessage(ValidationError, msg):
1075 constraint.validate(
1076 UniqueConstraintProduct,
1077 UniqueConstraintProduct(name="p1"),
1078 )
1079 constraint.validate(
1080 UniqueConstraintProduct,
1081 UniqueConstraintProduct(name="p1", color="green"),
1082 )
1083
1084 def test_validate_ordered_expression(self):
1085 constraint = models.UniqueConstraint(

Callers

nothing calls this directly

Calls 7

validateMethod · 0.95
CaseClass · 0.90
WhenClass · 0.90
FClass · 0.90
assertRaisesMessageMethod · 0.80
createMethod · 0.45

Tested by

no test coverage detected