Skip to content

Commit

Permalink
backup of code
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-gray-tangent committed Jul 18, 2024
1 parent dfc39e7 commit 44d76e1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
40 changes: 40 additions & 0 deletions app/accounts/tests/test_token.py
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()
1 change: 0 additions & 1 deletion app/accounts/tokens.py
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

Expand Down

0 comments on commit 44d76e1

Please sign in to comment.