diff options
Diffstat (limited to 'test/clitest.py')
| -rw-r--r-- | test/clitest.py | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/test/clitest.py b/test/clitest.py index f603f97..0667d6d 100644 --- a/test/clitest.py +++ b/test/clitest.py | |||
| @@ -8,66 +8,76 @@ import subprocess | |||
| 8 | import sys | 8 | import sys |
| 9 | 9 | ||
| 10 | sys.path.append('..') | 10 | sys.path.append('..') |
| 11 | import cli | 11 | #import cli |
| 12 | from lib import mat | 12 | from lib import mat |
| 13 | import test | 13 | import test |
| 14 | 14 | ||
| 15 | class Test_Remove_cli(test.MATTest): | 15 | class TestRemovecli(test.MATTest): |
| 16 | ''' | ||
| 17 | test if cli.py correctly remove metadatas | ||
| 18 | ''' | ||
| 16 | def test_remove(self): | 19 | def test_remove(self): |
| 17 | '''make sure that the cli remove all compromizing meta''' | 20 | '''make sure that the cli remove all compromizing meta''' |
| 18 | for clean, dirty in self.file_list: | 21 | for _, dirty in self.file_list: |
| 19 | subprocess.call(['../cli.py', dirty]) | 22 | subprocess.call(['../cli.py', dirty]) |
| 20 | current_file = mat.create_class_file(dirty, False, True) | 23 | current_file = mat.create_class_file(dirty, False, True) |
| 21 | self.assertTrue(current_file.is_clean()) | 24 | self.assertTrue(current_file.is_clean()) |
| 22 | 25 | ||
| 23 | def test_remove_empty(self): | 26 | def test_remove_empty(self): |
| 24 | '''Test removal with clean files''' | 27 | '''Test removal with clean files''' |
| 25 | for clean, dirty in self.file_list: | 28 | for clean, _ in self.file_list: |
| 26 | subprocess.call(['../cli.py', clean]) | 29 | subprocess.call(['../cli.py', clean]) |
| 27 | current_file = mat.create_class_file(clean, False, True) | 30 | current_file = mat.create_class_file(clean, False, True) |
| 28 | self.assertTrue(current_file.is_clean()) | 31 | self.assertTrue(current_file.is_clean()) |
| 29 | 32 | ||
| 30 | 33 | ||
| 31 | class Test_List_cli(test.MATTest): | 34 | class TestListcli(test.MATTest): |
| 35 | ''' | ||
| 36 | test if cli.py correctly display metadatas | ||
| 37 | ''' | ||
| 32 | def test_list_clean(self): | 38 | def test_list_clean(self): |
| 33 | '''check if get_meta returns meta''' | 39 | '''check if get_meta returns meta''' |
| 34 | for clean, dirty in self.file_list: | 40 | for clean, _ in self.file_list: |
| 35 | proc = subprocess.Popen(['../cli.py', '-d', clean], | 41 | proc = subprocess.Popen(['../cli.py', '-d', clean], |
| 36 | stdout=subprocess.PIPE) | 42 | stdout=subprocess.PIPE) |
| 37 | stdout, stderr = proc.communicate() | 43 | stdout, _ = proc.communicate() |
| 38 | self.assertEqual(stdout.strip('\n'), "[+] File %s :\nNo harmful meta found" % clean) | 44 | self.assertEqual(stdout.strip('\n'), "[+] File %s :\nNo harmful \ |
| 45 | meta found" % clean) | ||
| 39 | 46 | ||
| 40 | def test_list_dirty(self): | 47 | def test_list_dirty(self): |
| 41 | '''check if get_meta returns all the expected meta''' | 48 | '''check if get_meta returns all the expected meta''' |
| 42 | for clean, dirty in self.file_list: | 49 | for _, dirty in self.file_list: |
| 43 | proc = subprocess.Popen(['../cli.py', '-d', dirty], | 50 | proc = subprocess.Popen(['../cli.py', '-d', dirty], |
| 44 | stdout=subprocess.PIPE) | 51 | stdout=subprocess.PIPE) |
| 45 | stdout, stderr = proc.communicate() | 52 | stdout, _ = proc.communicate() |
| 46 | self.assertNotEqual(stdout, "[+] File %s" % dirty) | 53 | self.assertNotEqual(stdout, "[+] File %s" % dirty) |
| 47 | 54 | ||
| 48 | 55 | ||
| 49 | class Test_isClean_cli(test.MATTest): | 56 | class TestisCleancli(test.MATTest): |
| 57 | ''' | ||
| 58 | check if cli.py correctly check if a file is clean or not | ||
| 59 | ''' | ||
| 50 | #FIXME : use an external file with string as const ? | 60 | #FIXME : use an external file with string as const ? |
| 51 | def test_clean(self): | 61 | def test_clean(self): |
| 52 | '''test is_clean on clean files''' | 62 | '''test is_clean on clean files''' |
| 53 | for clean, dirty in self.file_list: | 63 | for clean, _ in self.file_list: |
| 54 | proc = subprocess.Popen(['../cli.py', '-c', clean], | 64 | proc = subprocess.Popen(['../cli.py', '-c', clean], |
| 55 | stdout=subprocess.PIPE) | 65 | stdout=subprocess.PIPE) |
| 56 | stdout, stderr = proc.communicate() | 66 | stdout, _ = proc.communicate() |
| 57 | self.assertEqual(stdout.strip('\n'), '[+] %s is clean' % clean) | 67 | self.assertEqual(stdout.strip('\n'), '[+] %s is clean' % clean) |
| 58 | 68 | ||
| 59 | def test_dirty(self): | 69 | def test_dirty(self): |
| 60 | '''test is_clean on dirty files''' | 70 | '''test is_clean on dirty files''' |
| 61 | for clean, dirty in self.file_list: | 71 | for _, dirty in self.file_list: |
| 62 | proc = subprocess.Popen(['../cli.py', '-c', dirty], | 72 | proc = subprocess.Popen(['../cli.py', '-c', dirty], |
| 63 | stdout=subprocess.PIPE) | 73 | stdout=subprocess.PIPE) |
| 64 | stdout, stderr = proc.communicate() | 74 | stdout, _ = proc.communicate() |
| 65 | self.assertEqual(stdout.strip('\n'), '[+] %s is not clean' % dirty) | 75 | self.assertEqual(stdout.strip('\n'), '[+] %s is not clean' % dirty) |
| 66 | 76 | ||
| 67 | 77 | ||
| 68 | if __name__ == '__main__': | 78 | if __name__ == '__main__': |
| 69 | suite = unittest.TestSuite() | 79 | suite = unittest.TestSuite() |
| 70 | suite.addTest(unittest.makeSuite(Test_Remove_cli)) | 80 | suite.addTest(unittest.makeSuite(TestRemovecli)) |
| 71 | suite.addTest(unittest.makeSuite(Test_List_cli)) | 81 | suite.addTest(unittest.makeSuite(TestListcli)) |
| 72 | suite.addTest(unittest.makeSuite(Test_isClean_cli)) | 82 | suite.addTest(unittest.makeSuite(TestisCleancli)) |
| 73 | unittest.TextTestRunner(verbosity=2).run(suite) | 83 | unittest.TextTestRunner(test.VERBOSITY).run(suite) |
