13
13
14
14
import django
15
15
import pytest
16
- from django .contrib .auth .models import User
17
16
from django .core .exceptions import ImproperlyConfigured
18
17
from django .core .serializers .json import DjangoJSONEncoder
19
18
from django .core .validators import (
@@ -737,6 +736,17 @@ class Meta:
737
736
self .assertEqual (repr (TestSerializer ()), expected )
738
737
739
738
def test_source_with_attributes (self ):
739
+ class User (models .Model ):
740
+ username = models .CharField (
741
+ 'username' ,
742
+ max_length = 150 ,
743
+ unique = True ,
744
+ help_text = 'Required. 150 characters or fewer.' ,
745
+ )
746
+ first_name = models .CharField ('first name' , max_length = 150 , blank = True )
747
+ last_name = models .CharField ('last name' , max_length = 150 , blank = True )
748
+ email = models .EmailField ('email address' , blank = True )
749
+
740
750
class UserProfile (models .Model ):
741
751
age = models .IntegerField ()
742
752
birthdate = models .DateField ()
@@ -763,7 +773,7 @@ class Meta:
763
773
764
774
expected = dedent ("""
765
775
UserProfileSerializer():
766
- 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())>])
776
+ username = CharField(help_text='Required. 150 characters or fewer.', max_length=150, source='user.username', validators=[<UniqueValidator(queryset=User.objects.all())>])
767
777
email = EmailField(allow_blank=True, label='Email address', max_length=254, required=False, source='user.email')
768
778
first_name = CharField(allow_blank=True, max_length=150, required=False, source='user.first_name')
769
779
last_name = CharField(allow_blank=True, max_length=150, required=False, source='user.last_name')
0 commit comments