Skip to content

Commit

Permalink
func: Adiciona rota de update de Usuario
Browse files Browse the repository at this point in the history
  • Loading branch information
WellingtonLFaria committed Sep 27, 2024
1 parent 54c104d commit 2d498f8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
8 changes: 0 additions & 8 deletions src/tupan/tupan/tests/tests.py

This file was deleted.

24 changes: 17 additions & 7 deletions src/tupan/usuarios/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ class TestUsuario:
@pytest.mark.django_db
def test_criacao_usuarios(self):
user1 = Usuario.objects.create_user(email='user@gmail.com', password='senha1')
user2 = Usuario.objects.create_user(email='well@gmail.com', password='senha2')
user2 = Usuario.objects.create_user(email='user2@gmail.com', password='senha2')

assert Usuario.objects.count() == 2
assert user1.email == 'user@gmail.com'
assert user2.email == 'well@gmail.com'
assert user2.email == 'user2@gmail.com'

assert user1.check_password("senha1")
assert user2.check_password("senha2")
Expand All @@ -21,7 +21,7 @@ def test_criacao_usuarios(self):
@pytest.mark.django_db
def test_listagem_usuarios(self):
user1 = Usuario.objects.create_user(email='user@gmail.com', password='senha1')
user2 = Usuario.objects.create_user(email='well@gmail.com', password='senha2')
user2 = Usuario.objects.create_user(email='user2@gmail.com', password='senha2')

usuarios = Usuario.objects.all()
assert len(usuarios) == 2
Expand All @@ -30,7 +30,17 @@ def test_listagem_usuarios(self):

@pytest.mark.django_db
def test_inativar_usuario(self):
user1 = Usuario.objects.create_user(email="wellingtonll.faria@gmail.com", password="123123")
user1.ativo = False
user1.save()
assert user1.ativo == False
user = Usuario.objects.create_user(email="user@gmail.com", password="123123")
user.ativo = False
user.save()
assert user.ativo == False

@pytest.mark.django_db
def test_atualizar_usuario(self):
user = Usuario.objects.create_user(email="user@gmail.com", password="userpass")
user.email = "test@gmail.com"
user.password = "passwd"
user.save()

assert user.email == "test@gmail.com"
assert user.password == "passwd"
10 changes: 10 additions & 0 deletions src/tupan/usuarios/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,13 @@ def post(self, request, format=None):
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

def update(self, request, format=None):
serializer = UsuarioSerializer(data=request.data)
if serializer.is_valid():
user = Usuario.get(id=serializer.data.id)
user.email = serializer.data.email
user.password = serializer.data.password
user.save()
return Response(user, status=status.HTTP_200_OK)
return Response("", status=status.HTTP_400_BAD_REQUEST)

0 comments on commit 2d498f8

Please sign in to comment.