Skip to content

Commit

Permalink
u
Browse files Browse the repository at this point in the history
user field and test user field
  • Loading branch information
rotem123456 committed Jul 6, 2024
1 parent 0d20d82 commit 4b72f03
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
31 changes: 29 additions & 2 deletions app/core/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
from django.db import models # noqa
"""
Database models.
"""

# Create your models here.

from django.db import models
from django.contrib.auth.modles import (
AbstartBaseUser,
BaseUserManger,
PermissionsMixin,
)
class UserManager(BaseUserManger):
"""Manager for users."""

def create_user(self,email, password=None, **extra_field):
"""Create, save and return a new user."""
user = self.model(email=email, **extra_field)
user.set_password(password)
user.save(using=self._db)

return user

class User(AbstartBaseUser,PermissionsMixin):
"""User in the system"""
email = models.EmailField(max_length=255, unique = True)
name= models.CharField(max_length=255)
is_active = models.BooleanField(default=True)
is_staff = models.BooleanField(deafult=False)

USERNAME_FIELD = 'email'
22 changes: 22 additions & 0 deletions app/core/tests/test_modesl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
Tests for models
"""
from django.test import TestCase
from django.contrib.auth import get_user_model


class ModelTest(TestCase):
"""Test models."""

def test_create_user_with_email_succesfull(self):
"""Test creating a user with an email is succesfull"""
email = "test@example.com"
password = 'testpass123'
user = get_user_model().objects.create_user(
email = email,
password = password
)

self.assertEqual(user.email, email)
self.assertTrue(user.check_password(password))

0 comments on commit 4b72f03

Please sign in to comment.