55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
import datetime
|
|
|
|
from django.core.management import call_command
|
|
|
|
from django.contrib.auth.models import User
|
|
from fargo.fargo.models import UserDocument, Document
|
|
from fargo.oauth2.models import OAuth2TempFile, OAuth2Client
|
|
from django.core.files.base import ContentFile
|
|
|
|
|
|
def test_cleanup(freezer, john_doe):
|
|
start = freezer()
|
|
|
|
client = OAuth2Client.objects.create(client_name='c', redirect_uris='')
|
|
|
|
foo = Document.objects.create(content=ContentFile(b'foo', name='foo.txt'))
|
|
bar = Document.objects.create(content=ContentFile(b'bar', name='bar.txt'))
|
|
UserDocument.objects.create(user=john_doe,
|
|
document=foo,
|
|
filename='foo.txt',
|
|
title='',
|
|
description='')
|
|
OAuth2TempFile.objects.create(document=bar, client=client, filename='bar.txt')
|
|
|
|
call_command('fargo-cleanup')
|
|
|
|
assert UserDocument.objects.all().count()
|
|
assert OAuth2TempFile.objects.all().count()
|
|
assert Document.objects.all().count() == 2
|
|
|
|
User.objects.all().delete()
|
|
|
|
assert not UserDocument.objects.all().count()
|
|
assert Document.objects.all().count() == 2
|
|
|
|
call_command('fargo-cleanup')
|
|
|
|
assert Document.objects.all().count() == 2
|
|
|
|
freezer.move_to(start + datetime.timedelta(seconds=120))
|
|
call_command('fargo-cleanup')
|
|
|
|
assert Document.objects.all().count() == 1
|
|
|
|
freezer.move_to(start + datetime.timedelta(days=3))
|
|
|
|
call_command('fargo-cleanup')
|
|
|
|
assert not OAuth2TempFile.objects.count()
|
|
assert Document.objects.count()
|
|
|
|
call_command('fargo-cleanup')
|
|
|
|
assert not Document.objects.count()
|