|
8 | 8 |
|
9 | 9 | from rest_framework.serializers.validators import (
|
10 | 10 | RegexValidator, BaseValidator, RequiredValidator, MinLengthValidator, MaxLengthValidator,
|
11 |
| - MinValueValidator, MaxValueValidator |
| 11 | + MinValueValidator, MaxValueValidator, ChoiceValidator |
12 | 12 | )
|
13 | 13 | from rest_framework.serializers.exceptions import ValidationError
|
14 | 14 |
|
@@ -172,3 +172,17 @@ class RegexValidatorTestCase(ValidatorTestCases):
|
172 | 172 | {'init': {'regex': r'\d+', 'message': 'test'}, 'data': 'test', 'message': 'test'},
|
173 | 173 | {'init': {'regex': r'\d+', 'inverse_match': True}, 'data': 'test'}
|
174 | 174 | )
|
| 175 | + |
| 176 | + |
| 177 | +class ChoiceValidatorTestCase(ValidatorTestCases): |
| 178 | + """ |
| 179 | + Testing ChoiceValidator. |
| 180 | +
|
| 181 | + """ |
| 182 | + validator_class = ChoiceValidator |
| 183 | + cases = ( |
| 184 | + {'init': {'choices': [1, 2, 3]}, 'data': 3}, |
| 185 | + {'init': {'choices': {1: 1, 2: 2, 3: 3}}, 'data': 2}, |
| 186 | + {'init': {'choices': [1, 2, 3]}, 'data': 'asdasd', 'message': 'Value must be one of `[1, 2, 3]`.'}, |
| 187 | + {'init': {'choices': [1, 2, 3], 'message': 'test'}, 'data': 'test', 'message': 'test'}, |
| 188 | + ) |
0 commit comments