Skip to content

Commit

Permalink
Merge pull request #2514 from bagerard/enum_field_update
Browse files Browse the repository at this point in the history
improvement to recent updates
  • Loading branch information
bagerard committed May 5, 2021
2 parents 34245fe + ecb5dda commit 5209547
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=================
Expand Down
12 changes: 11 additions & 1 deletion tests/fields/test_enum_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,17 @@ def test_cannot_create_model_with_wrong_enum_value(self):

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"):
Expand Down

0 comments on commit 5209547

Please sign in to comment.