Coverage for src/backend/InvenTree/generic/states/validators.py: 81%
12 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 17:47 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 17:47 +0000
1"""Validators for generic state management."""
3from django.core.exceptions import ValidationError
4from django.core.validators import BaseValidator
5from django.utils.translation import gettext_lazy as _
8class CustomStatusCodeValidator(BaseValidator):
9 """Custom validator class for checking that a provided status code is valid."""
11 def __init__(self, *args, **kwargs):
12 """Initialize the validator."""
13 self.status_class = kwargs.pop('status_class', None)
14 super().__init__(limit_value=None, **kwargs)
16 def __call__(self, value):
17 """Check that the provided status code is valid."""
18 if status_class := self.status_class: 18 ↛ exitline 18 didn't return from function '__call__' because the condition on line 18 was always true
19 values = status_class.keys(custom=True)
20 if value not in values: 20 ↛ 21line 20 didn't jump to line 21 because the condition on line 20 was never true
21 raise ValidationError(_('Invalid status code'))