Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
johnthagen committed Feb 22, 2021
1 parent e5ffdf8 commit 7164aa1
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/test_serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import uuid

import pytest
from enumfields.drf import EnumField
from enumfields.drf.serializers import EnumSupportSerializerMixin
from rest_framework import serializers

Expand Down Expand Up @@ -42,6 +43,22 @@ def test_serialize(int_names):
assert data['int_enum'] == data['int_enum_not_editable'] == IntegerEnum.B.value


@pytest.mark.parametrize('instance, representation', [
('', ''),
(None, None),
('r', 'r'),
('g', 'g'),
('b', 'b'),
])
def test_enumfield_to_representation(instance, representation):
assert EnumField(Color).to_representation(instance) == representation


def test_invalid_enumfield_to_representation():
with pytest.raises(ValueError, match=r"Invalid value.*"):
assert EnumField(Color).to_representation('INVALID_ENUM_STRING')


@pytest.mark.django_db
@pytest.mark.parametrize('lenient_serializer', (False, True))
@pytest.mark.parametrize('lenient_data', (False, True))
Expand Down

0 comments on commit 7164aa1

Please sign in to comment.