<commit_before>"""accounts app unittests for tokens

"""
import base64
from time import sleep

from django.test import TestCase, Client
from django.contrib.auth import get_user_model

from logintokens.tokens import LoginTokenGenerator


USER = get_user_model()


class TokenGeneratorTest(TestCase):
    """Tests for login token model.

    """
    def setUp(self):
        self.client = Client()
        self.username = '<EMAIL>'
        self.generator = LoginTokenGenerator()

    def test_unique_tokens_generated(self):
        """Tokens generated one second apart should differ.

        """
        token1 = self.generator.make_token(self.username)
        sleep(1)
        token2 = self.generator.make_token(self.username)
        self.assertNotEqual(token1, token2)

    def test_username_recovered_from_token(self):
        """A consumed token should yield the original username.

        """
        USER.objects.create_user(self.username)
        token = self.generator.make_token(self.username)
        username = self.generator.consume_token(token)
        self.assertEqual(username, self.username)

    def test_new_user_token(self):
        """A token which doesn't yet have a user should yield the username.

        """<commit_msg>Rename test for clarity<commit_after>"""accounts app unittests for tokens

"""
import base64
from time import sleep

from django.test import TestCase, Client
from django.contrib.auth import get_user_model

from logintokens.tokens import LoginTokenGenerator


USER = get_user_model()


class TokenGeneratorTest(TestCase):
    """Tests for login token model.

    """
    def setUp(self):
        self.client = Client()
        self.username = '<EMAIL>'
        self.generator = LoginTokenGenerator()

    def test_unique_tokens_generated(self):
        """Tokens generated one second apart should differ.

        """
        token1 = self.generator.make_token(self.username)
        sleep(1)
        token2 = self.generator.make_token(self.username)
        self.assertNotEqual(token1, token2)

    def test_existing_user_token(self):
        """A consumed token should yield the original username.

        """
        USER.objects.create_user(self.username)
        token = self.generator.make_token(self.username)
        username = self.generator.consume_token(token)
        self.assertEqual(username, self.username)

    def test_new_user_token(self):
        """A token which doesn't yet have a user should yield the username.

        """
{'fraction_non_alphanumeric': 0.09149277688603531, 'fraction_numerical': 0.0056179775280898875, 'mean_word_length': 3.1003289473684212, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '906093', 'n_tokens_mistral': 696, 'n_tokens_neox': 673, 'n_words': 179}