diff --git a/profile_app/migrations/0006_alter_user_cpf.py b/profile_app/migrations/0006_alter_user_cpf.py new file mode 100644 index 0000000..608cbab --- /dev/null +++ b/profile_app/migrations/0006_alter_user_cpf.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.6 on 2022-04-18 01:17 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('profile_app', '0005_create_first_user'), + ] + + operations = [ + migrations.AlterField( + model_name='user', + name='cpf', + field=models.CharField(blank=True, max_length=15, unique=True), + ), + ] diff --git a/profile_app/models.py b/profile_app/models.py index 1ff8d46..aeefa89 100644 --- a/profile_app/models.py +++ b/profile_app/models.py @@ -4,8 +4,10 @@ class UserManager(BaseUserManager): - def create_superuser(self, username, user_type, first_name, last_name, - cpf, password, **other_fields): + def create_superuser(self, username, cpf, password, **other_fields): + user_type = "AD" + first_name = "super" + last_name = "user" other_fields.setdefault('is_superuser', True) @@ -39,7 +41,7 @@ class User_Type(models.TextChoices): default=User_Type.VI) first_name = models.CharField(max_length=150, blank=True) last_name = models.CharField(max_length=150, blank=True) - cpf = models.CharField(max_length=15, blank=True) + cpf = models.CharField(max_length=15, blank=True, unique=True) is_superuser = models.BooleanField(default=False) USERNAME_FIELD = 'username' diff --git a/profile_app/serializers.py b/profile_app/serializers.py index 04d96f8..2d1cb1d 100644 --- a/profile_app/serializers.py +++ b/profile_app/serializers.py @@ -22,7 +22,7 @@ class GetUserSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = User - fields = ['first_name', 'last_name'] + fields = ['first_name', 'last_name', 'username', 'user_type', 'cpf', 'id'] class UserSerializer(serializers.ModelSerializer): diff --git a/tests/urls_tests.py b/tests/urls_tests.py index 70de99f..f7aed12 100644 --- a/tests/urls_tests.py +++ b/tests/urls_tests.py @@ -32,8 +32,8 @@ def test_create(self, api_client): "user_type": "VI", "first_name": "test", "last_name": "test", + "password": os.getenv('POSTGRES_HOST'), "cpf": "11111111111", - "password": os.getenv('POSTGRES_HOST') } response = api_client.post( @@ -47,8 +47,10 @@ def test_create_superuser(self, api_client): data={ 'username': 'superuser', 'user_type': "AD", + 'first_name': 'superuser', + 'last_name': 'superuser', 'password': 'superuser', - 'cpf': '00000000000', + 'cpf': "00000000000", 'is_superuser': 'true' }, format='json' @@ -64,7 +66,8 @@ def test_get_user(self, api_client): "user_type": "AD", "first_name": "test", "last_name": "test", - "password": PASSWORD + "password": PASSWORD, + "cpf": "11111111111", } user_response = api_client.post(