Skip to content

Commit

Permalink
Feito teste para garantir criação de usuário com email em minúsculo
Browse files Browse the repository at this point in the history
close #15
  • Loading branch information
renzo committed Jul 11, 2024
1 parent fdc4635 commit 60f6bd3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions backend/devpro/base/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ def _create_user(self, email, password, **extra_fields):
"""
if not email:
raise ValueError("The given email must be set")
email = self.normalize_email(email)
email = self.normalize_email(email).lower()
user = self.model(email=email, **extra_fields)
user.password = make_password(password)
user.save(using=self._db)
return user

def create_user(self, email, password=None, **extra_fields):
def create_user(self, email: str, password=None, **extra_fields):
extra_fields.setdefault("is_staff", False)
extra_fields.setdefault("is_superuser", False)
return self._create_user(email, password, **extra_fields)
Expand Down
2 changes: 0 additions & 2 deletions backend/devpro/base/tests.py

This file was deleted.

Empty file.
16 changes: 16 additions & 0 deletions backend/devpro/base/tests/test_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pytest
from django.contrib.auth import get_user_model

from devpro.base.manager import UserManager


def test_user_has_customized_manager_instance():
User = get_user_model()
assert isinstance(User.objects, UserManager)


@pytest.mark.django_db
def test_user_creation_with_lower_case_email():
User = get_user_model()
user = User.objects.create_user(email='RenZo@dev,pro.br')
assert user.email == 'renzo@dev,pro.br'

0 comments on commit 60f6bd3

Please sign in to comment.