-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
|