diff --git a/src/tupan/tupan/tests/tests.py b/src/tupan/tupan/tests/tests.py deleted file mode 100644 index 60557b3..0000000 --- a/src/tupan/tupan/tests/tests.py +++ /dev/null @@ -1,8 +0,0 @@ -import pytest -from django.urls import reverse - -@pytest.mark.django_db -def test_homepage(client): - url = reverse('admin') - response = client.get(url) - assert response.status_code == 200 diff --git a/src/tupan/usuarios/tests.py b/src/tupan/usuarios/tests.py index 7f249bc..9620999 100644 --- a/src/tupan/usuarios/tests.py +++ b/src/tupan/usuarios/tests.py @@ -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") @@ -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 @@ -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 \ No newline at end of file + 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" \ No newline at end of file diff --git a/src/tupan/usuarios/views.py b/src/tupan/usuarios/views.py index 8e71a3f..c0e1d48 100644 --- a/src/tupan/usuarios/views.py +++ b/src/tupan/usuarios/views.py @@ -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) \ No newline at end of file