tests: check clean_tempfiles method

This commit is contained in:
Frédéric Péters 2020-12-05 22:00:12 +01:00
parent 52feb63060
commit be7a18fe93
1 changed files with 19 additions and 0 deletions

View File

@ -1,5 +1,6 @@
import json
import re
import stat
import sys
import time
import pickle
@ -291,3 +292,21 @@ def test_clean_afterjobs():
pub.clean_afterjobs()
assert AfterJob.count() == 1
assert AfterJob.select()[0].id == 'b'
def test_clean_tempfiles():
pub = create_temporary_pub()
pub.clean_tempfiles()
dirname = os.path.join(pub.app_dir, 'tempfiles')
if not os.path.exists(dirname):
os.mkdir(dirname)
with open(os.path.join(dirname, 'a'), 'w') as fd:
fd.write('a')
with open(os.path.join(dirname, 'b'), 'w') as fd:
os.utime(fd.fileno(), times=(time.time() - 40 * 86400, time.time() - 40 * 86400))
pub.clean_tempfiles()
assert os.listdir(dirname) == ['a']