This repository has been archived on 2023-02-07. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
flamenco-worker/tests/test_commands_remove_tree.py
Sybren A. Stüvel 05408dc8c1 Cleanup: reformat with Black
Reformat the entire project with Black.

No functional changes.
2021-07-09 14:26:13 +02:00

94 lines
3.1 KiB
Python

from pathlib import Path
import os
from tests.test_runner import AbstractCommandTest
class RemoveTreeTest(AbstractCommandTest):
def setUp(self):
super().setUp()
from flamenco_worker.commands import RemoveTreeCommand
import tempfile
self.tmpdir = tempfile.TemporaryDirectory()
self.tmppath = Path(self.tmpdir.name)
self.cmd = RemoveTreeCommand(
worker=self.fworker,
task_id="12345",
command_idx=0,
)
def tearDown(self):
super().tearDown()
self.tmpdir.cleanup()
def test_validate_settings(self):
self.assertIn("path", self.cmd.validate({"path": 12}))
self.assertIn("path", self.cmd.validate({"path": ""}))
self.assertIn("path", self.cmd.validate({}))
self.assertFalse(self.cmd.validate({"path": "/some/path"}))
def test_nonexistant_source(self):
path = self.tmppath / "nonexisting"
task = self.cmd.run({"path": str(path)})
ok = self.loop.run_until_complete(task)
self.assertTrue(ok)
self.assertFalse(path.exists())
def test_source_file(self):
path = self.tmppath / "existing"
path.touch()
task = self.cmd.run({"path": str(path)})
ok = self.loop.run_until_complete(task)
self.assertTrue(ok)
self.assertFalse(path.exists())
def test_soure_dir_with_files(self):
path = self.tmppath / "dir"
path.mkdir()
(path / "a.file").touch()
(path / "b.file").touch()
(path / "c.file").touch()
task = self.cmd.run({"path": str(path)})
ok = self.loop.run_until_complete(task)
self.assertTrue(ok)
self.assertFalse(path.exists())
def test_soure_dir_with_files_and_dirs(self):
path = self.tmppath / "dir"
path.mkdir()
(path / "subdir-a" / "subsub-1").mkdir(parents=True)
(path / "subdir-a" / "subsub-2").mkdir()
(path / "subdir-a" / "subsub-3").mkdir()
(path / "subdir-b" / "subsub-1").mkdir(parents=True)
(path / "subdir-c" / "subsub-1").mkdir(parents=True)
(path / "subdir-c" / "subsub-2").mkdir()
(path / "a.file").touch()
(path / "b.file").touch()
(path / "c.file").touch()
(path / "subdir-a" / "subsub-1" / "a.file").touch()
(path / "subdir-a" / "subsub-1" / "b.file").touch()
(path / "subdir-a" / "subsub-2" / "a.file").touch()
(path / "subdir-a" / "subsub-2" / "b.file").touch()
(path / "subdir-a" / "subsub-3" / "a.file").touch()
(path / "subdir-a" / "subsub-3" / "b.file").touch()
(path / "subdir-b" / "subsub-1" / "a.file").touch()
(path / "subdir-b" / "subsub-1" / "b.file").touch()
(path / "subdir-c" / "subsub-1" / "a.file").touch()
(path / "subdir-c" / "subsub-1" / "b.file").touch()
(path / "subdir-c" / "subsub-2" / "a.file").touch()
(path / "subdir-c" / "subsub-2" / "b.file").touch()
task = self.cmd.run({"path": str(path)})
ok = self.loop.run_until_complete(task)
self.assertTrue(ok)
self.assertFalse(path.exists())