summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorjvoisin2013-07-14 15:44:20 +0200
committerjvoisin2013-07-14 15:44:20 +0200
commit3d2429a41de44f9769c7f63b587c9f0502fd1a6c (patch)
tree640028bb3e23734419feb5d1b7fb7daa375adcea /test
parentcc1664d0c5752aadfbd47f6532ba62ecf08f6f54 (diff)
Fiabilise secure_remove + associated tests
Diffstat (limited to 'test')
-rw-r--r--test/libtest.py39
1 files changed, 28 insertions, 11 deletions
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 @@
8import unittest 8import unittest
9import test 9import test
10import sys 10import sys
11import tempfile
11sys.path.append('..') 12sys.path.append('..')
12from MAT import mat 13import MAT
13 14
14 15
15class TestRemovelib(test.MATTest): 16class TestRemovelib(test.MATTest):
@@ -19,15 +20,15 @@ class TestRemovelib(test.MATTest):
19 def test_remove(self): 20 def test_remove(self):
20 '''make sure that the lib remove all compromizing meta''' 21 '''make sure that the lib remove all compromizing meta'''
21 for _, dirty in self.file_list: 22 for _, dirty in self.file_list:
22 current_file = mat.create_class_file(dirty, False, add2archive=True, low_pdf_quality=True) 23 current_file = MAT.mat.create_class_file(dirty, False, add2archive=True, low_pdf_quality=True)
23 current_file.remove_all() 24 current_file.remove_all()
24 current_file2 = mat.create_class_file(dirty, False, add2archive=True, low_pdf_quality=True) 25 current_file2 = MAT.mat.create_class_file(dirty, False, add2archive=True, low_pdf_quality=True)
25 self.assertTrue(current_file2.is_clean()) 26 self.assertTrue(current_file2.is_clean())
26 27
27 def test_remove_empty(self): 28 def test_remove_empty(self):
28 '''Test removal with clean files''' 29 '''Test removal with clean files'''
29 for clean, _ in self.file_list: 30 for clean, _ in self.file_list:
30 current_file = mat.create_class_file(clean, False, add2archive=True, low_pdf_quality=True) 31 current_file = MAT.mat.create_class_file(clean, False, add2archive=True, low_pdf_quality=True)
31 current_file.remove_all() 32 current_file.remove_all()
32 self.assertTrue(current_file.is_clean()) 33 self.assertTrue(current_file.is_clean())
33 34
@@ -39,14 +40,14 @@ class TestListlib(test.MATTest):
39 def test_list(self): 40 def test_list(self):
40 '''check if get_meta returns all the expected meta''' 41 '''check if get_meta returns all the expected meta'''
41 for _, dirty in self.file_list: 42 for _, dirty in self.file_list:
42 current_file = mat.create_class_file(dirty, False, add2archive=True, low_pdf_quality=True) 43 current_file = MAT.mat.create_class_file(dirty, False, add2archive=True, low_pdf_quality=True)
43 #FIXME assertisNotNone() : python 2.7 44 #FIXME assertisNotNone() : python 2.7
44 self.assertTrue(current_file.get_meta()) 45 self.assertTrue(current_file.get_meta())
45 46
46 def testlist_list_empty(self): 47 def testlist_list_empty(self):
47 '''check that a listing of a clean file return an empty dict''' 48 '''check that a listing of a clean file return an empty dict'''
48 for clean, _ in self.file_list: 49 for clean, _ in self.file_list:
49 current_file = mat.create_class_file(clean, False, add2archive=True, low_pdf_quality=True) 50 current_file = MAT.mat.create_class_file(clean, False, add2archive=True, low_pdf_quality=True)
50 self.assertEqual(current_file.get_meta(), dict()) 51 self.assertEqual(current_file.get_meta(), dict())
51 52
52 53
@@ -57,13 +58,13 @@ class TestisCleanlib(test.MATTest):
57 def test_dirty(self): 58 def test_dirty(self):
58 '''test is_clean on clean files''' 59 '''test is_clean on clean files'''
59 for _, dirty in self.file_list: 60 for _, dirty in self.file_list:
60 current_file = mat.create_class_file(dirty, False, add2archive=True, low_pdf_quality=True) 61 current_file = MAT.mat.create_class_file(dirty, False, add2archive=True, low_pdf_quality=True)
61 self.assertFalse(current_file.is_clean()) 62 self.assertFalse(current_file.is_clean())
62 63
63 def test_clean(self): 64 def test_clean(self):
64 '''test is_clean on dirty files''' 65 '''test is_clean on dirty files'''
65 for clean, _ in self.file_list: 66 for clean, _ in self.file_list:
66 current_file = mat.create_class_file(clean, False, add2archive=True, low_pdf_quality=True) 67 current_file = MAT.mat.create_class_file(clean, False, add2archive=True, low_pdf_quality=True)
67 self.assertTrue(current_file.is_clean()) 68 self.assertTrue(current_file.is_clean())
68 69
69 70
@@ -73,15 +74,30 @@ class TestFileAttributes(unittest.TestCase):
73 ''' 74 '''
74 def test_not_writtable(self): 75 def test_not_writtable(self):
75 ''' test MAT's behaviour on non-writable file''' 76 ''' test MAT's behaviour on non-writable file'''
76 self.assertFalse(mat.create_class_file('not_writtable', False, add2archive=True, low_pdf_quality=True)) 77 self.assertFalse(MAT.mat.create_class_file('not_writtable', False, add2archive=True, low_pdf_quality=True))
77 78
78 def test_not_exist(self): 79 def test_not_exist(self):
79 ''' test MAT's behaviour on non-existent file''' 80 ''' test MAT's behaviour on non-existent file'''
80 self.assertFalse(mat.create_class_file('ilikecookies', False, add2archive=True, low_pdf_quality=True)) 81 self.assertFalse(MAT.mat.create_class_file('ilikecookies', False, add2archive=True, low_pdf_quality=True))
81 82
82 def test_empty(self): 83 def test_empty(self):
83 ''' test MAT's behaviour on empty file''' 84 ''' test MAT's behaviour on empty file'''
84 self.assertFalse(mat.create_class_file('empty_file', False, add2archive=True, low_pdf_quality=True)) 85 self.assertFalse(MAT.mat.create_class_file('empty_file', False, add2archive=True, low_pdf_quality=True))
86
87class TestSecureRemove(unittest.TestCase):
88 ''' Test the secure_remove function
89 '''
90 def test_remove_existing(self):
91 ''' test the secure removal of an existing file
92 '''
93 _, file_to_remove = tempfile.mkstemp()
94 self.assertTrue(MAT.mat.secure_remove(file_to_remove))
95
96 def test_remove_fail(self):
97 ''' test the secure removal of an non-removable file
98 '''
99 self.assertRaises(MAT.exceptions.UnableToRemoveFile, MAT.mat.secure_remove, '/OMAGAD')
100
85 101
86def get_tests(): 102def get_tests():
87 ''' Return every libtests''' 103 ''' Return every libtests'''
@@ -90,6 +106,7 @@ def get_tests():
90 suite.addTest(unittest.makeSuite(TestListlib)) 106 suite.addTest(unittest.makeSuite(TestListlib))
91 suite.addTest(unittest.makeSuite(TestisCleanlib)) 107 suite.addTest(unittest.makeSuite(TestisCleanlib))
92 suite.addTest(unittest.makeSuite(TestFileAttributes)) 108 suite.addTest(unittest.makeSuite(TestFileAttributes))
109 suite.addTest(unittest.makeSuite(TestSecureRemove))
93 return suite 110 return suite
94 111
95 112