-
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.
- Loading branch information
1 parent
dfc39e7
commit 44d76e1
Showing
2 changed files
with
40 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import unittest | ||
from datetime import datetime | ||
|
||
import six | ||
from django.contrib.auth.tokens import PasswordResetTokenGenerator | ||
|
||
from accounts.tokens import AccountActivationTokenGenerator | ||
|
||
|
||
# Speculate user model class for test abstraction | ||
class User: | ||
def __init__(self, id, is_active): | ||
self.pk = id | ||
self.is_active = is_active | ||
|
||
|
||
class TestAccountActivationTokenGenerator(unittest.TestCase): | ||
def setUp(self): | ||
self.generator = AccountActivationTokenGenerator() | ||
self.timestamp = datetime.now() | ||
|
||
def test_make_hash_value_active_user(self): | ||
user = User(1, True) | ||
hash_val = self.generator._make_hash_value(user, self.timestamp) | ||
expected_val = ( | ||
six.text_type(user.pk) + six.text_type(self.timestamp) + six.text_type(user.is_active) | ||
) | ||
self.assertEqual(hash_val, expected_val) | ||
|
||
def test_make_hash_value_inactive_user(self): | ||
user = User(1, False) | ||
hash_val = self.generator._make_hash_value(user, self.timestamp) | ||
expected_val = ( | ||
six.text_type(user.pk) + six.text_type(self.timestamp) + six.text_type(user.is_active) | ||
) | ||
self.assertEqual(hash_val, expected_val) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
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,3 @@ | ||
# tokens.py | ||
import six | ||
from django.contrib.auth.tokens import PasswordResetTokenGenerator | ||
|
||
|