add test of the DeletedUserManager.cleanup() method
This commit is contained in:
parent
e3d190d9a2
commit
accc74d7c4
|
@ -35,9 +35,9 @@ class DeletedUserManager(models.Manager):
|
|||
user.save()
|
||||
self.get_or_create(user=user)
|
||||
|
||||
def cleanup(self, threshold=600):
|
||||
def cleanup(self, threshold=600, timestamp=None):
|
||||
'''Delete all deleted users for more than 10 minutes.'''
|
||||
not_after = now() - timedelta(seconds=threshold)
|
||||
not_after = (timestamp or now()) - timedelta(seconds=threshold)
|
||||
for deleted_user in self.filter(creation__lte=not_after):
|
||||
user = deleted_user.user
|
||||
deleted_user.delete()
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
import datetime
|
||||
|
||||
from authentic2.models import DeletedUser
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.utils.timezone import now
|
||||
|
||||
|
||||
def test_deleted_user_cleanup(db):
|
||||
User = get_user_model()
|
||||
u = User.objects.create(username='john.doe')
|
||||
assert User.objects.count() == 1
|
||||
DeletedUser.objects.delete_user(u)
|
||||
DeletedUser.objects.cleanup(timestamp=now() + datetime.timedelta(seconds=700))
|
||||
assert User.objects.count() == 0
|
Loading…
Reference in New Issue