Skip to content

Commit

Permalink
Merge pull request #15 from fga-eps-mds/devel
Browse files Browse the repository at this point in the history
Release 3 - Profile
  • Loading branch information
baraky authored Apr 20, 2022
2 parents 3ba8d79 + a1d45e1 commit 5d1a8d0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
18 changes: 18 additions & 0 deletions profile_app/migrations/0006_alter_user_cpf.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
8 changes: 5 additions & 3 deletions profile_app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion profile_app/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
9 changes: 6 additions & 3 deletions tests/urls_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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'
Expand All @@ -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(
Expand Down

0 comments on commit 5d1a8d0

Please sign in to comment.