コード例 #1
0
    def test_get_temp_token(self):
        temp_token_key = self.serializer.get_temp_token(self.user_profile)
        temp_token = TempToken.objects.get(key=temp_token_key)

        is_expired = expired(temp_token.created)

        self.assertFalse(is_expired)
コード例 #2
0
    def test_get_temp_token(self):
        temp_token_key = self.serializer.get_temp_token(self.user_profile)
        temp_token = TempToken.objects.get(key=temp_token_key)

        is_expired = expired(temp_token.created)

        self.assertFalse(is_expired)
コード例 #3
0
    def get_temp_token(self, object):
        """This should return a valid temp token for this user profile."""
        token, created = TempToken.objects.get_or_create(user=object.user)

        if not created and expired(token.created):
            token.delete()
            token = TempToken.objects.create(user=object.user)

        return token.key
コード例 #4
0
    def get_temp_token(self, object):
        """This should return a valid temp token for this user profile."""
        token, created = TempToken.objects.get_or_create(user=object.user)

        if not created and expired(token.created):
            token.delete()
            token = TempToken.objects.create(user=object.user)

        return token.key
コード例 #5
0
    def get_temp_token(self, object):
        """This should return a valid temp token for this user profile."""
        token, created = TempToken.objects.get_or_create(user=object.user)

        try:
            if not created and expired(token.created):
                with transaction.atomic():
                    TempToken.objects.get(user=object.user).delete()
                    token = TempToken.objects.create(user=object.user)
        except IntegrityError:
            pass

        return token.key
コード例 #6
0
    def get_temp_token(self, object):
        """This should return a valid temp token for this user profile."""
        token, created = TempToken.objects.get_or_create(user=object.user)
        check_expired = getattr(settings, 'CHECK_EXPIRED_TEMP_TOKEN', True)

        try:
            if check_expired and not created and expired(token.created):
                with transaction.atomic():
                    TempToken.objects.get(user=object.user).delete()
                    token = TempToken.objects.create(user=object.user)
        except IntegrityError:
            pass

        return token.key
コード例 #7
0
    def test_get_temp_token_recreates_if_expired(self):
        temp_token, created = TempToken.objects.get_or_create(
            user=self.user_profile.user)

        day = timedelta(seconds=settings.DEFAULT_TEMP_TOKEN_EXPIRY_TIME)
        today = now()
        yesterday = today - day
        temp_token.created = yesterday
        temp_token.save()

        temp_token_key = self.serializer.get_temp_token(self.user_profile)
        temp_token = TempToken.objects.get(key=temp_token_key)

        is_expired = expired(temp_token.created)

        self.assertFalse(is_expired)
コード例 #8
0
    def test_get_temp_token_recreates_if_expired(self):
        temp_token, created = TempToken.objects.get_or_create(
            user=self.user_profile.user)

        day = timedelta(seconds=settings.DEFAULT_TEMP_TOKEN_EXPIRY_TIME)
        today = now()
        yesterday = today - day
        temp_token.created = yesterday
        temp_token.save()

        temp_token_key = self.serializer.get_temp_token(self.user_profile)
        temp_token = TempToken.objects.get(key=temp_token_key)

        is_expired = expired(temp_token.created)

        self.assertFalse(is_expired)
コード例 #9
0
    def get_temp_token(self, object):  # pylint: disable=R0201,W0622
        """
        This should return a valid temp token for this user profile.
        """
        token, created = TempToken.objects.get_or_create(user=object.user)
        check_expired = getattr(settings, 'CHECK_EXPIRED_TEMP_TOKEN', True)

        try:
            if check_expired and not created and expired(token.created):
                with transaction.atomic():
                    TempToken.objects.get(user=object.user).delete()
                    token = TempToken.objects.create(user=object.user)
        except IntegrityError:
            pass

        return token.key