authentic/tests/test_cleanup.py

31 lines
1.2 KiB
Python

# authentic2 - versatile identity manager
# Copyright (C) 2010-2019 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
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