Skip to content

Commit

Permalink
chore(schematics) Improves ChoicesEnumType to receive kwargs
Browse files Browse the repository at this point in the history
  • Loading branch information
maikyguanaes authored and fgmacedo committed Sep 2, 2019
1 parent 6342b6e commit f191c08
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions choicesenum/schematics/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@


class ChoicesEnumType(BaseType):
def __init__(self, type_):
def __init__(self, type_, **kwargs):
if not issubclass(type_, ChoicesEnum):
raise ValidationError(self.Messages.INVALID_TYPE)
super(ChoicesEnumType, self).__init__(type_)
super(ChoicesEnumType, self).__init__(type_, kwargs)
self.type = type_

def to_native(self, value, context=None):
Expand Down
5 changes: 5 additions & 0 deletions tests/test_schematics_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ def test_choices_enum_type(http_statuses):
assert state.to_primitive(200) == http_statuses.OK.value


def test_choices_enum_type_with_extra_params(http_statuses):
state = ChoicesEnumType(http_statuses, required=True)
assert state.to_native(200) is http_statuses.OK


def test_choices_enum_type_should_throw_exception():
with pytest.raises(ValidationError) as e:
ChoicesEnumType(object)
Expand Down

0 comments on commit f191c08

Please sign in to comment.