diff --git a/docs/changelog.rst b/docs/changelog.rst index 00ca9c21..3f4252a5 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -7,12 +7,12 @@ Changelog Development =========== - (Fill this out as you fix issues and develop your features). +- EnumField improvements: now `choices` limits the values of an enum to allow Changes in 0.23.1 =========== - Bug fix: ignore LazyReferenceFields when clearing _changed_fields #2484 - Improve connection doc #2481 -- EnumField improvements: now `choices` limits the values of an enum to allow Changes in 0.23.0 ================= diff --git a/tests/fields/test_enum_field.py b/tests/fields/test_enum_field.py index 6dffb905..d2730d33 100644 --- a/tests/fields/test_enum_field.py +++ b/tests/fields/test_enum_field.py @@ -81,7 +81,17 @@ class TestStringEnumField(MongoDBTestCase): def test_partial_choices(self): partial = [Status.DONE] - assert EnumField(Status, choices=partial).choices == partial + enum_field = EnumField(Status, choices=partial) + assert enum_field.choices == partial + + class FancyDoc(Document): + z = enum_field + + FancyDoc(z=Status.DONE).validate() + with pytest.raises( + ValidationError, match=r"Value must be one of .*Status.DONE" + ): + FancyDoc(z=Status.NEW).validate() def test_wrong_choices(self): with pytest.raises(ValueError, match="Invalid choices"):