示例#1
0
    def test_timeout(self):
        """
        Ensure we can use the token after n days, but no greater.
        """

        # Uses a mocked version of EmailActivationTokenGenerator
        # so we can change the value of 'today'
        class Mocked(EmailActivationTokenGenerator):
            def __init__(self, today):
                self._today_val = today

            def _today(self):
                return self._today_val

        user = self.create_user()
        token_generator = EmailActivationTokenGenerator()
        token = token_generator.make_token(user)

        p1 = Mocked(date.today() +
                    timedelta(settings.USERS_EMAIL_CONFIRMATION_TIMEOUT_DAYS))
        self.assertTrue(p1.check_token(user, token))

        p2 = Mocked(date.today() +
                    timedelta(settings.USERS_EMAIL_CONFIRMATION_TIMEOUT_DAYS +
                              1))
        self.assertFalse(p2.check_token(user, token))
示例#2
0
    def test_make_token(self):
        """
        Ensure that we can make a token and that it is valid
        """
        user = self.create_user()

        token_generator = EmailActivationTokenGenerator()
        token = token_generator.make_token(user)
        self.assertTrue(token_generator.check_token(user, token))
示例#3
0
    def test_make_token(self):
        """
        Ensure that we can make a token and that it is valid
        """
        user = self.create_user()

        token_generator = EmailActivationTokenGenerator()
        token = token_generator.make_token(user)
        self.assertTrue(token_generator.check_token(user, token))
示例#4
0
    def test_bad_token(self):
        """
        Ensure bad activation keys are rejected
        """
        user = self.create_user()

        token_generator = EmailActivationTokenGenerator()
        bad_activation_keys = ('emailactivationtokengenerator',
                               'emailactivation-tokengenerator',
                               '3rd-bademailactivationkey')
        for key in bad_activation_keys:
            self.assertFalse(token_generator.check_token(user, key))
示例#5
0
    def test_bad_token(self):
        """
        Ensure bad activation keys are rejected
        """
        user = self.create_user()

        token_generator = EmailActivationTokenGenerator()
        bad_activation_keys = (
            'emailactivationtokengenerator',
            'emailactivation-tokengenerator',
            '3rd-bademailactivationkey'
        )
        for key in bad_activation_keys:
            self.assertFalse(token_generator.check_token(user, key))
示例#6
0
    def test_timeout(self):
        """
        Ensure we can use the token after n days, but no greater.
        """
        # Uses a mocked version of EmailActivationTokenGenerator
        # so we can change the value of 'today'
        class Mocked(EmailActivationTokenGenerator):
            def __init__(self, today):
                self._today_val = today

            def _today(self):
                return self._today_val

        user = self.create_user()
        token_generator = EmailActivationTokenGenerator()
        token = token_generator.make_token(user)

        p1 = Mocked(date.today() + timedelta(settings.USERS_EMAIL_CONFIRMATION_TIMEOUT_DAYS))
        self.assertTrue(p1.check_token(user, token))

        p2 = Mocked(date.today() + timedelta(settings.USERS_EMAIL_CONFIRMATION_TIMEOUT_DAYS + 1))
        self.assertFalse(p2.check_token(user, token))