diff options
Diffstat (limited to 'clitest.py')
| -rwxr-xr-x[-rw-r--r--] | clitest.py | 80 |
1 files changed, 58 insertions, 22 deletions
diff --git a/clitest.py b/clitest.py index 00955ae..f4adbf5 100644..100755 --- a/clitest.py +++ b/clitest.py | |||
| @@ -1,54 +1,90 @@ | |||
| 1 | import cli | 1 | #!/usr/bin/python |
| 2 | import unittest | 2 | ''' |
| 3 | import test | 3 | Unit test for the CLI interface |
| 4 | ''' | ||
| 4 | 5 | ||
| 5 | import shlex | 6 | import unittest |
| 6 | import subprocess | 7 | import subprocess |
| 7 | 8 | ||
| 9 | import cli | ||
| 10 | import mat | ||
| 11 | import test | ||
| 12 | |||
| 8 | class Test_Remove_cli(test.MATTest): | 13 | class Test_Remove_cli(test.MATTest): |
| 9 | def test_remove(self): | 14 | def test_remove(self): |
| 10 | '''make sure that the cli remove all compromizing meta''' | 15 | '''make sure that the cli remove all compromizing meta''' |
| 11 | for clean, dirty in self.file_list: | 16 | for clean, dirty in self.file_list: |
| 12 | subprocess.call("cli.py %s" dirty) | 17 | subprocess.call(['./cli.py', dirty]) |
| 13 | self.assertTrue(mat.file(dirty).is_clean()) | 18 | current_file = mat.create_class_file(dirty) |
| 19 | self.assertTrue(current_file.is_clean()) | ||
| 14 | 20 | ||
| 15 | def test_remove_empty(self): | 21 | def test_remove_empty(self): |
| 16 | '''Test removal with clean files''' | 22 | '''Test removal with clean files''' |
| 17 | for clean, dirty in self.file_list: | 23 | for clean, dirty in self.file_list: |
| 18 | subprocess.call("cli.py %s" clean) | 24 | subprocess.call(['./cli.py', clean]) |
| 19 | self.assertTrue(mat.file(dirty).is_clean()) | 25 | current_file = mat.create_class_file(clean) |
| 26 | self.assertTrue(current_file.is_clean()) | ||
| 20 | 27 | ||
| 21 | 28 | ||
| 22 | class Test_List_cli(test.MATTest): | 29 | class Test_List_cli(test.MATTest): |
| 23 | def test_list(self): | 30 | def test_list_clean(self): |
| 31 | '''check if get_meta returns meta''' | ||
| 32 | for clean, dirty in self.file_list: | ||
| 33 | proc = subprocess.Popen(['./cli.py', '-d', clean], | ||
| 34 | stdout=subprocess.PIPE) | ||
| 35 | stdout, stderr = proc.communicate() | ||
| 36 | self.assertEqual(stdout, "[+] File %s" % clean) | ||
| 37 | |||
| 38 | def test_list_dirty(self): | ||
| 24 | '''check if get_meta returns all the expected meta''' | 39 | '''check if get_meta returns all the expected meta''' |
| 25 | for clean, dirty in self.file_list: | 40 | for clean, dirty in self.file_list: |
| 26 | meta_list = dict("fixme":"please",) #FIXME | 41 | proc = subprocess.Popen(['./cli.py', '-d', dirty], |
| 27 | self.assertDictEqual(mat.file(dirty).get_meta(), meta_list) | 42 | stdout=subprocess.PIPE) |
| 43 | stdout, stderr = proc.communicate() | ||
| 44 | self.assertNotEqual(stdout, "[+] File %s" % dirty) | ||
| 45 | |||
| 46 | class Test_List_Harmful_cli(test.MATTest): | ||
| 47 | def test_list_clean(self): | ||
| 48 | '''check if get_meta returns no meta at all''' | ||
| 49 | for clean, dirty in self.file_list: | ||
| 50 | proc = subprocess.Popen(['./cli.py', '--harmful', clean], | ||
| 51 | stdout=subprocess.PIPE) | ||
| 52 | stdout, stderr = proc.communicate() | ||
| 53 | self.assertNotEqual(stdout.strip('\n'), '[+] File %s :' % clean) | ||
| 28 | 54 | ||
| 29 | def testlist_list_empty(self): | 55 | def test_list_dirty(self): |
| 30 | '''check that a listing of a clean file return an empty dict''' | 56 | '''check if get_meta returns harmful meta''' |
| 31 | for clean, dirty in self.file_list: | 57 | for clean, dirty in self.file_list: |
| 32 | self.assertEqual(mat.file(clean).get_meta(), None) | 58 | proc = subprocess.Popen(['./cli.py', '--harmful', dirty], |
| 59 | stdout=subprocess.PIPE) | ||
| 60 | stdout, stderr = proc.communicate() | ||
| 61 | self.assertNotEqual(stdout.strip('\n'), '[+] File %s :' % dirty) | ||
| 62 | |||
| 33 | 63 | ||
| 34 | 64 | ||
| 35 | class Test_isClean_cli(test.MATTest): | 65 | class Test_isClean_cli(test.MATTest): |
| 66 | #FIXME : use an external file with string as const ? | ||
| 36 | def test_clean(self): | 67 | def test_clean(self): |
| 37 | '''test is_clean on clean files''' | 68 | '''test is_clean on clean files''' |
| 38 | for clean, dirty in self.file_list: | 69 | for clean, dirty in self.file_list: |
| 39 | print "e" | 70 | proc = subprocess.Popen(['./cli.py', '-c', clean], |
| 40 | self.assertTrue(mat.file(clean).is_clean()) | 71 | stdout=subprocess.PIPE) |
| 72 | stdout, stderr = proc.communicate() | ||
| 73 | self.assertEqual(stdout.strip('\n'), '[+] %s is clean' % clean) | ||
| 41 | 74 | ||
| 42 | def test_clean(self): | 75 | def test_dirty(self): |
| 43 | '''test is_clean on dirty files''' | 76 | '''test is_clean on dirty files''' |
| 44 | for clean, dirty in self.file_list: | 77 | for clean, dirty in self.file_list: |
| 45 | self.assertFalse(mat.file(dirty).is_clean()) | 78 | proc = subprocess.Popen(['./cli.py', '-c', dirty], |
| 79 | stdout=subprocess.PIPE) | ||
| 80 | stdout, stderr = proc.communicate() | ||
| 81 | self.assertEqual(stdout.strip('\n'), '[+] %s is not clean' % dirty) | ||
| 46 | 82 | ||
| 47 | 83 | ||
| 48 | if __name__ == '__main__': | 84 | if __name__ == '__main__': |
| 49 | suite = unittest.TestSuite() | 85 | suite = unittest.TestSuite() |
| 50 | suite.addTest(unittest.makeSuite(Test_Remove)) | 86 | suite.addTest(unittest.makeSuite(Test_Remove_cli)) |
| 51 | suite.addTest(unittest.makeSuite(Test_List)) | 87 | suite.addTest(unittest.makeSuite(Test_List_cli)) |
| 52 | suite.addTest(unittest.makeSuite(Test_isClean)) | 88 | suite.addTest(unittest.makeSuite(Test_isClean_cli)) |
| 89 | suite.addTest(unittest.makeSuite(Test_List_Harmful_cli)) | ||
| 53 | unittest.TextTestRunner(verbosity=2).run(suite) | 90 | unittest.TextTestRunner(verbosity=2).run(suite) |
| 54 | |||
