mirror of https://github.com/CIRCL/PyCIRCLean
Add tests for make_dangerous and safe_copy
parent
b77451ae7a
commit
d7280a8535
|
@ -167,7 +167,7 @@ class FileBase(object):
|
||||||
to help prevent double-click of death.
|
to help prevent double-click of death.
|
||||||
"""
|
"""
|
||||||
if not self.is_dangerous:
|
if not self.is_dangerous:
|
||||||
self.set_property('dangerous', True)
|
self.set_property('is_dangerous', True)
|
||||||
self.filename = 'DANGEROUS_{}_DANGEROUS'.format(self.filename)
|
self.filename = 'DANGEROUS_{}_DANGEROUS'.format(self.filename)
|
||||||
if reason_string:
|
if reason_string:
|
||||||
self.add_description(reason_string)
|
self.add_description(reason_string)
|
||||||
|
|
|
@ -16,14 +16,14 @@ fixture = pytest.fixture
|
||||||
class TestFileBase:
|
class TestFileBase:
|
||||||
# Fixtures
|
# Fixtures
|
||||||
|
|
||||||
@fixture(scope='class')
|
|
||||||
def dest_dir_path(self, tmpdir_factory):
|
|
||||||
return tmpdir_factory.mktemp('dest').strpath
|
|
||||||
|
|
||||||
@fixture(scope='class')
|
@fixture(scope='class')
|
||||||
def src_dir_path(self, tmpdir_factory):
|
def src_dir_path(self, tmpdir_factory):
|
||||||
return tmpdir_factory.mktemp('src').strpath
|
return tmpdir_factory.mktemp('src').strpath
|
||||||
|
|
||||||
|
@fixture(scope='class')
|
||||||
|
def dest_dir_path(self, tmpdir_factory):
|
||||||
|
return tmpdir_factory.mktemp('dest').strpath
|
||||||
|
|
||||||
@fixture
|
@fixture
|
||||||
def symlink_file_path(self, tmpdir, tmpfile_path):
|
def symlink_file_path(self, tmpdir, tmpfile_path):
|
||||||
symlink_path = tmpdir.join('symlinked')
|
symlink_path = tmpdir.join('symlinked')
|
||||||
|
@ -179,31 +179,30 @@ class TestFileBase:
|
||||||
text_file.add_description('thing')
|
text_file.add_description('thing')
|
||||||
assert text_file.get_property('description_string') == ['thing']
|
assert text_file.get_property('description_string') == ['thing']
|
||||||
|
|
||||||
def test_add_new_error(self):
|
def test_add_new_error(self, text_file):
|
||||||
"""Adding a new error should add it to the dict of errors."""
|
"""Adding a new error should add it to the dict of errors."""
|
||||||
pass
|
text_file.add_error(Exception, 'thing')
|
||||||
|
assert text_file.get_property('_errors') == {Exception: 'thing'}
|
||||||
|
|
||||||
def test_add_error_exists(self):
|
def test_normal_file_mark_dangerous(self, text_file):
|
||||||
"""Adding an error that already exists shouldn't duplicate it."""
|
"""Marking a file dangerous should identify it as dangerous."""
|
||||||
pass
|
text_file.make_dangerous()
|
||||||
|
assert text_file.is_dangerous is True
|
||||||
|
|
||||||
def test_normal_file_mark_dangerous(self):
|
def test_normal_file_mark_dangerous_filename_change(self, text_file):
|
||||||
"""Marking a normal file dangerous shouldn't make it """
|
"""Marking a file dangerous should mangle the filename."""
|
||||||
pass
|
filename = text_file.filename
|
||||||
|
text_file.make_dangerous()
|
||||||
|
assert text_file.filename == 'DANGEROUS_{}_DANGEROUS'.format(filename)
|
||||||
|
|
||||||
def test_normal_file_mark_dangerous_filename_change(self):
|
def test_normal_file_mark_dangerous_add_description(self, text_file):
|
||||||
pass
|
text_file.make_dangerous('thing')
|
||||||
|
assert text_file.get_property('description_string') == ['thing']
|
||||||
|
|
||||||
def test_normal_file_mark_dangerous_add_description(self):
|
def test_dangerous_file_mark_dangerous(self, text_file):
|
||||||
pass
|
text_file.make_dangerous()
|
||||||
|
text_file.make_dangerous()
|
||||||
def test_dangerous_file_mark_dangerous(self):
|
assert text_file.is_dangerous is True
|
||||||
pass
|
|
||||||
|
|
||||||
# File modifiers
|
|
||||||
|
|
||||||
def test_safe_copy(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def test_force_ext_change(self):
|
def test_force_ext_change(self):
|
||||||
pass
|
pass
|
||||||
|
@ -211,6 +210,18 @@ class TestFileBase:
|
||||||
def test_force_ext_correct(self):
|
def test_force_ext_correct(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def test_safe_copy(self, src_dir_path, dest_dir_path):
|
||||||
|
file_path = os.path.join(src_dir_path, 'test.txt')
|
||||||
|
with open(file_path, 'w+') as file:
|
||||||
|
file.write('')
|
||||||
|
dst_path = os.path.join(dest_dir_path, 'test.txt')
|
||||||
|
with mock.patch('kittengroomer.helpers.magic.from_file',
|
||||||
|
return_value='text/plain'):
|
||||||
|
file = FileBase(file_path, dst_path)
|
||||||
|
with mock.patch('kittengroomer.helpers.shutil.copy') as mock_copy:
|
||||||
|
file.safe_copy()
|
||||||
|
mock_copy.assert_called_once_with(file_path, dst_path)
|
||||||
|
|
||||||
def test_create_metadata_file_new(self):
|
def test_create_metadata_file_new(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -218,6 +229,12 @@ class TestFileBase:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class TestLogging:
|
||||||
|
|
||||||
|
def test_computehash(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class TestKittenGroomerBase:
|
class TestKittenGroomerBase:
|
||||||
|
|
||||||
@fixture(scope='class')
|
@fixture(scope='class')
|
||||||
|
|
Loading…
Reference in New Issue