test_cleanup.py 833 Bytes
Newer Older
Sascha Herzinger's avatar
Sascha Herzinger committed
1
2
3
4
5
"""This module provides tests for the janitor"""

import os
from pathlib import Path

6
from fractalis.cleanup import janitor
Sascha Herzinger's avatar
Sascha Herzinger committed
7
8
9
10
11
12
13
14
15
16
from fractalis import app, redis


# noinspection PyMissingOrEmptyDocstring,PyMissingTypeHints
class TestManage:

    def test_janitor_removes_untracked_files(self):
        tmp_dir = app.config['FRACTALIS_TMP_DIR']
        os.makedirs(tmp_dir, exist_ok=True)
        Path(os.path.join(tmp_dir, 'abc')).touch()
17
        janitor()
Sascha Herzinger's avatar
Sascha Herzinger committed
18
19
20
21
22
23
24
        assert not os.path.exists(os.path.join(tmp_dir, 'abc'))

    def test_janitor_does_not_remove_tracked_files(self):
        tmp_dir = app.config['FRACTALIS_TMP_DIR']
        os.makedirs(tmp_dir, exist_ok=True)
        Path(os.path.join(tmp_dir, 'abc')).touch()
        redis.set('data:abc', '')
25
        janitor()
Sascha Herzinger's avatar
Sascha Herzinger committed
26
        assert os.path.exists(os.path.join(tmp_dir, 'abc'))