-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Ensure that last_login and date_joined defaults are properly set in User Model, and ensure that User Manager does not override the defaults. Thanks to @jschneier for reporting the issue.
- Loading branch information
1 parent
ec3f6fd
commit db3e06a
Showing
4 changed files
with
36 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 |
---|---|---|
|
@@ -4,4 +4,5 @@ AUTHORS | |
|
||
- Andrew Pinkham http://andrewsforge.com | ||
- Jim Illback [email protected] | ||
- Josh Schneier https://github.com/jschneier | ||
- Russell Keith-Magee http://cecinestpasun.com |
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
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,4 +1,6 @@ | ||
"""Test User model manager""" | ||
from datetime import datetime | ||
|
||
from django.test import TestCase | ||
|
||
from improved_user.models import User, UserManager | ||
|
@@ -93,3 +95,24 @@ def test_make_random_password(self): | |
self.assertEqual(len(password), 5) | ||
for char in password: | ||
self.assertIn(char, allowed_chars) | ||
|
||
def test_last_login_is_none(self): | ||
"""Check that last login is unset when created | ||
https://github.com/jambonsw/django-improved-user/issues/25 | ||
""" | ||
user1 = User.objects.create_user('[email protected]', 'password1') | ||
self.assertIsNone(user1.last_login) | ||
|
||
user2 = User.objects.create_superuser('[email protected]', 'password1') | ||
self.assertIsNone(user2.last_login) | ||
|
||
def test_date_joined_default(self): | ||
"""Check date joined set upon creation""" | ||
user1 = User.objects.create_user('[email protected]', 'password1') | ||
self.assertIsNotNone(user1.date_joined) | ||
self.assertIsInstance(user1.date_joined, datetime) | ||
|
||
user2 = User.objects.create_superuser('[email protected]', 'password1') | ||
self.assertIsNotNone(user2.date_joined) | ||
self.assertIsInstance(user2.date_joined, datetime) |
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,4 +1,5 @@ | ||
"""Test Improved User Model""" | ||
from datetime import datetime | ||
from types import MethodType | ||
from unittest import skipUnless | ||
from unittest.mock import patch | ||
|
@@ -78,6 +79,16 @@ def test_last_login_default(self): | |
user2 = User.objects.create(email='[email protected]') | ||
self.assertIsNone(user2.last_login) | ||
|
||
def test_date_joined_default(self): | ||
"""Check date joined set upon creation""" | ||
user1 = User.objects.create(email='[email protected]') | ||
self.assertIsNotNone(user1.date_joined) | ||
self.assertIsInstance(user1.date_joined, datetime) | ||
|
||
user2 = User.objects.create(email='[email protected]') | ||
self.assertIsNotNone(user2.date_joined) | ||
self.assertIsInstance(user2.date_joined, datetime) | ||
|
||
def test_user_clean_normalize_email(self): | ||
"""User email/username is normalized upon creation""" | ||
user = User(email='[email protected]', password='foo') | ||
|