Skip to content

Commit

Permalink
Fix test_source_with_attributes for python 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
BergLucas committed Sep 13, 2023
1 parent c1ccc37 commit b10dfc2
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions tests/test_model_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import django
import pytest
from django.contrib.auth.models import User
from django.core.exceptions import ImproperlyConfigured
from django.core.serializers.json import DjangoJSONEncoder
from django.core.validators import (
Expand Down Expand Up @@ -737,6 +736,17 @@ class Meta:
self.assertEqual(repr(TestSerializer()), expected)

def test_source_with_attributes(self):
class User(models.Model):
username = models.CharField(
'username',
max_length=150,
unique=True,
help_text='Required. 150 characters or fewer.',
)
first_name = models.CharField('first name', max_length=150, blank=True)
last_name = models.CharField('last name', max_length=150, blank=True)
email = models.EmailField('email address', blank=True)

class UserProfile(models.Model):
age = models.IntegerField()
birthdate = models.DateField()
Expand All @@ -763,7 +773,7 @@ class Meta:

expected = dedent("""
UserProfileSerializer():
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())>])
username = CharField(help_text='Required. 150 characters or fewer.', max_length=150, source='user.username', validators=[<UniqueValidator(queryset=User.objects.all())>])
email = EmailField(allow_blank=True, label='Email address', max_length=254, required=False, source='user.email')
first_name = CharField(allow_blank=True, max_length=150, required=False, source='user.first_name')
last_name = CharField(allow_blank=True, max_length=150, required=False, source='user.last_name')
Expand Down

0 comments on commit b10dfc2

Please sign in to comment.