Skip to content

Commit b4ce3e5

Browse files
committed
Change the test "test_source_with_attributes" to target django 4.2-5.2
1 parent 05b2e3b commit b4ce3e5

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

tests/test_model_serializer.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ class Meta:
729729

730730
def test_source_with_attributes(self):
731731
class UserProfile(models.Model):
732-
age = models.IntegerField()
732+
age = models.IntegerField(validators=[MinValueValidator(1), MaxValueValidator(100)])
733733
birthdate = models.DateField()
734734
user = models.ForeignKey(User, on_delete=models.CASCADE)
735735

@@ -752,17 +752,13 @@ class Meta:
752752
}
753753
}
754754

755-
# In Django 3.0, the maximum length of first_name is 30, whereas it is 150
756-
# in later versions, so we can't hard-code the value in the expected variable.
757-
max_length = User.first_name.field.max_length
758-
759-
expected = dedent(f"""
755+
expected = dedent("""
760756
UserProfileSerializer():
761757
username = CharField(help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, source='user.username', validators=[<django.contrib.auth.validators.UnicodeUsernameValidator object>, <UniqueValidator(queryset=User.objects.all())>])
762758
email = EmailField(allow_blank=True, label='Email address', max_length=254, required=False, source='user.email')
763-
first_name = CharField(allow_blank=True, max_length={max_length}, required=False, source='user.first_name')
759+
first_name = CharField(allow_blank=True, max_length=150, required=False, source='user.first_name')
764760
last_name = CharField(allow_blank=True, max_length=150, required=False, source='user.last_name')
765-
age = IntegerField()
761+
age = IntegerField(max_value=100, min_value=1)
766762
birthdate = DateField()
767763
""")
768764
self.assertEqual(repr(UserProfileSerializer()), expected)

0 commit comments

Comments
 (0)