Merge pull request #2514 from bagerard/enum_field_update

improvement to recent updates
This commit is contained in:
Bastien Gérard 2021-05-05 09:21:45 +02:00 committed by GitHub
commit 5209547a89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -7,12 +7,12 @@ Changelog
Development Development
=========== ===========
- (Fill this out as you fix issues and develop your features). - (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 Changes in 0.23.1
=========== ===========
- Bug fix: ignore LazyReferenceFields when clearing _changed_fields #2484 - Bug fix: ignore LazyReferenceFields when clearing _changed_fields #2484
- Improve connection doc #2481 - Improve connection doc #2481
- EnumField improvements: now `choices` limits the values of an enum to allow
Changes in 0.23.0 Changes in 0.23.0
================= =================

View File

@ -81,7 +81,17 @@ class TestStringEnumField(MongoDBTestCase):
def test_partial_choices(self): def test_partial_choices(self):
partial = [Status.DONE] 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): def test_wrong_choices(self):
with pytest.raises(ValueError, match="Invalid choices"): with pytest.raises(ValueError, match="Invalid choices"):