From 3d2429a41de44f9769c7f63b587c9f0502fd1a6c Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sun, 14 Jul 2013 15:44:20 +0200 Subject: Fiabilise secure_remove + associated tests --- test/libtest.py | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) (limited to 'test') diff --git a/test/libtest.py b/test/libtest.py index ffec63a..5b23587 100644 --- a/test/libtest.py +++ b/test/libtest.py @@ -8,8 +8,9 @@ import unittest import test import sys +import tempfile sys.path.append('..') -from MAT import mat +import MAT class TestRemovelib(test.MATTest): @@ -19,15 +20,15 @@ class TestRemovelib(test.MATTest): def test_remove(self): '''make sure that the lib remove all compromizing meta''' for _, dirty in self.file_list: - current_file = mat.create_class_file(dirty, False, add2archive=True, low_pdf_quality=True) + current_file = MAT.mat.create_class_file(dirty, False, add2archive=True, low_pdf_quality=True) current_file.remove_all() - current_file2 = mat.create_class_file(dirty, False, add2archive=True, low_pdf_quality=True) + current_file2 = MAT.mat.create_class_file(dirty, False, add2archive=True, low_pdf_quality=True) self.assertTrue(current_file2.is_clean()) def test_remove_empty(self): '''Test removal with clean files''' for clean, _ in self.file_list: - current_file = mat.create_class_file(clean, False, add2archive=True, low_pdf_quality=True) + current_file = MAT.mat.create_class_file(clean, False, add2archive=True, low_pdf_quality=True) current_file.remove_all() self.assertTrue(current_file.is_clean()) @@ -39,14 +40,14 @@ class TestListlib(test.MATTest): def test_list(self): '''check if get_meta returns all the expected meta''' for _, dirty in self.file_list: - current_file = mat.create_class_file(dirty, False, add2archive=True, low_pdf_quality=True) + current_file = MAT.mat.create_class_file(dirty, False, add2archive=True, low_pdf_quality=True) #FIXME assertisNotNone() : python 2.7 self.assertTrue(current_file.get_meta()) def testlist_list_empty(self): '''check that a listing of a clean file return an empty dict''' for clean, _ in self.file_list: - current_file = mat.create_class_file(clean, False, add2archive=True, low_pdf_quality=True) + current_file = MAT.mat.create_class_file(clean, False, add2archive=True, low_pdf_quality=True) self.assertEqual(current_file.get_meta(), dict()) @@ -57,13 +58,13 @@ class TestisCleanlib(test.MATTest): def test_dirty(self): '''test is_clean on clean files''' for _, dirty in self.file_list: - current_file = mat.create_class_file(dirty, False, add2archive=True, low_pdf_quality=True) + current_file = MAT.mat.create_class_file(dirty, False, add2archive=True, low_pdf_quality=True) self.assertFalse(current_file.is_clean()) def test_clean(self): '''test is_clean on dirty files''' for clean, _ in self.file_list: - current_file = mat.create_class_file(clean, False, add2archive=True, low_pdf_quality=True) + current_file = MAT.mat.create_class_file(clean, False, add2archive=True, low_pdf_quality=True) self.assertTrue(current_file.is_clean()) @@ -73,15 +74,30 @@ class TestFileAttributes(unittest.TestCase): ''' def test_not_writtable(self): ''' test MAT's behaviour on non-writable file''' - self.assertFalse(mat.create_class_file('not_writtable', False, add2archive=True, low_pdf_quality=True)) + self.assertFalse(MAT.mat.create_class_file('not_writtable', False, add2archive=True, low_pdf_quality=True)) def test_not_exist(self): ''' test MAT's behaviour on non-existent file''' - self.assertFalse(mat.create_class_file('ilikecookies', False, add2archive=True, low_pdf_quality=True)) + self.assertFalse(MAT.mat.create_class_file('ilikecookies', False, add2archive=True, low_pdf_quality=True)) def test_empty(self): ''' test MAT's behaviour on empty file''' - self.assertFalse(mat.create_class_file('empty_file', False, add2archive=True, low_pdf_quality=True)) + self.assertFalse(MAT.mat.create_class_file('empty_file', False, add2archive=True, low_pdf_quality=True)) + +class TestSecureRemove(unittest.TestCase): + ''' Test the secure_remove function + ''' + def test_remove_existing(self): + ''' test the secure removal of an existing file + ''' + _, file_to_remove = tempfile.mkstemp() + self.assertTrue(MAT.mat.secure_remove(file_to_remove)) + + def test_remove_fail(self): + ''' test the secure removal of an non-removable file + ''' + self.assertRaises(MAT.exceptions.UnableToRemoveFile, MAT.mat.secure_remove, '/OMAGAD') + def get_tests(): ''' Return every libtests''' @@ -90,6 +106,7 @@ def get_tests(): suite.addTest(unittest.makeSuite(TestListlib)) suite.addTest(unittest.makeSuite(TestisCleanlib)) suite.addTest(unittest.makeSuite(TestFileAttributes)) + suite.addTest(unittest.makeSuite(TestSecureRemove)) return suite -- cgit v1.3