Skip to content

Commit

Permalink
fixup! add test
Browse files Browse the repository at this point in the history
  • Loading branch information
blueyed committed Jan 29, 2018
1 parent 9a5964c commit ed6c97f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from decimal import ROUND_DOWN, ROUND_UP, Decimal

import pytest
from django.core.exceptions import ValidationError as DjangoValidationError
from django.http import QueryDict
from django.test import TestCase, override_settings
from django.utils import six
Expand Down Expand Up @@ -2090,16 +2091,19 @@ class ExampleSerializer(serializers.Serializer):


class TestValidationErrorCode:
def test_validationerror_code(self):
from django.core.exceptions import (
ValidationError as DjangoValidationError)
@pytest.mark.parametrize('use_list', (False, True))
def test_validationerror_code(self, use_list):

class ExampleSerializer(serializers.Serializer):
password = serializers.CharField()

def validate_password(self, obj):
raise DjangoValidationError('exc_msg', 'exc_code')
err = DjangoValidationError('exc_msg', code='exc_code')
if use_list:
err = DjangoValidationError([err])
raise err

serializer = ExampleSerializer(data={'password': 123})
serializer.is_valid()
assert serializer.errors == {'password': ['exc_msg']}
assert serializer.errors['password'][0].code == 'exc_code'

0 comments on commit ed6c97f

Please sign in to comment.