From 1a50ea4f9d99899098e1d0c8f5b13df2b7731afe Mon Sep 17 00:00:00 2001 From: Ghosts6 Date: Sat, 19 Oct 2024 20:04:02 +0100 Subject: [PATCH] Fix formatting and resolve pre-commit errors --- rest_framework/fields.py | 2 +- tests/test_fields.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 1b6945f9f..0717acaab 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -917,7 +917,7 @@ class CustomLengthValidator: def __call__(self, value): if len(value) < self.min_length: raise ValueError(f"This field must be at least {self.min_length} characters long.") - + if self.max_length is not None and len(value) > self.max_length: raise ValueError(f"This field must be no more than {self.max_length} characters long.") diff --git a/tests/test_fields.py b/tests/test_fields.py index 15925a719..089772b8a 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -1071,7 +1071,7 @@ class TestAlphabeticField: invalid_inputs = { 'John123': ['This field must contain only alphabetic characters and spaces.'], 'Alice!': ['This field must contain only alphabetic characters and spaces.'], - '': ['This field must contain only alphabetic characters and spaces.'], + '': ['This field must contain only alphabetic characters and spaces.'], } non_string_inputs = [ 123, # Integer @@ -1085,7 +1085,7 @@ class TestAlphabeticField: def test_valid_inputs(self): validator = AlphabeticFieldValidator() for value in self.valid_inputs.keys(): - validator(value) + validator(value) def test_invalid_inputs(self): validator = AlphabeticFieldValidator() @@ -1111,7 +1111,7 @@ class TestAlphanumericField: invalid_inputs = { 'John!': ['This field must contain only alphanumeric characters (letters and numbers).'], 'Alice 007': ['This field must contain only alphanumeric characters (letters and numbers).'], - '': ['This field must contain only alphanumeric characters (letters and numbers).'], + '': ['This field must contain only alphanumeric characters (letters and numbers).'], } non_string_inputs = [ 123, # Integer @@ -1125,7 +1125,7 @@ class TestAlphanumericField: def test_valid_inputs(self): validator = AlphanumericFieldValidator() for value in self.valid_inputs.keys(): - validator(value) + validator(value) def test_invalid_inputs(self): validator = AlphanumericFieldValidator() @@ -1153,12 +1153,12 @@ class TestCustomLengthField: 'ab': ['This field must be at least 3 characters long.'], # Too short 'abcdefghijk': ['This field must be no more than 10 characters long.'], # Too long } - field = str + field = str def test_valid_inputs(self): validator = CustomLengthValidator(min_length=3, max_length=10) for value in self.valid_inputs.keys(): - validator(value) + validator(value) def test_invalid_inputs(self): validator = CustomLengthValidator(min_length=3, max_length=10)