From 44d76e1f6157263a90c7265204d892f82bf7e08b Mon Sep 17 00:00:00 2001 From: Daniel Gray Date: Thu, 18 Jul 2024 16:17:27 +0200 Subject: [PATCH] backup of code --- app/accounts/tests/test_token.py | 40 ++++++++++++++++++++++++++++++++ app/accounts/tokens.py | 1 - 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 app/accounts/tests/test_token.py diff --git a/app/accounts/tests/test_token.py b/app/accounts/tests/test_token.py new file mode 100644 index 00000000..30165e06 --- /dev/null +++ b/app/accounts/tests/test_token.py @@ -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() diff --git a/app/accounts/tokens.py b/app/accounts/tokens.py index 88c8a2dc..05503120 100644 --- a/app/accounts/tokens.py +++ b/app/accounts/tokens.py @@ -1,4 +1,3 @@ -# tokens.py import six from django.contrib.auth.tokens import PasswordResetTokenGenerator