From 36c963ef60babe18c5bbd0feb624f2d5615a23df Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sat, 1 Feb 2014 04:10:09 +0000 Subject: Fix https://labs.riseup.net/code/issues/6416 This commit fix the "Does not inform the user when files where lost while cleaning an archive" (for the CLI) bug, and adds a test for it. --- test/clitest.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/clitest.py b/test/clitest.py index 312822f..ad895f5 100644 --- a/test/clitest.py +++ b/test/clitest.py @@ -5,9 +5,11 @@ Unit test for the CLI interface ''' +import os import unittest import subprocess import sys +import tarfile sys.path.append('..') from MAT import mat @@ -21,14 +23,14 @@ class TestRemovecli(test.MATTest): def test_remove(self): '''make sure that the cli remove all compromizing meta''' for _, dirty in self.file_list: - subprocess.call(['../mat', dirty]) + subprocess.call(['../mat', '--add2archive', dirty]) current_file = mat.create_class_file(dirty, False, add2archive=True, low_pdf_quality=True) self.assertTrue(current_file.is_clean()) def test_remove_empty(self): - '''Test removal with clean files''' + '''Test removal with clean files\n''' for clean, _ in self.file_list: - subprocess.call(['../mat', clean]) + subprocess.call(['../mat', '--add2archive', clean]) current_file = mat.create_class_file(clean, False, add2archive=True, low_pdf_quality=True) self.assertTrue(current_file.is_clean()) @@ -97,11 +99,24 @@ class TestFileAttributes(unittest.TestCase): def test_empty(self): ''' test MAT's behaviour on empty file''' - proc = subprocess.Popen(['../mat', 'empty_file'], - stdout=subprocess.PIPE) + proc = subprocess.Popen(['../mat', 'empty_file'], stdout=subprocess.PIPE) stdout, _ = proc.communicate() self.assertEqual(str(stdout).strip('\n'), 'Unable to process %s' % 'ilikecookies') +class TestUnsupported(test.MATTest): + def test_abort_unsupported(self): + ''' test if the cli aborts on unsupported files + ''' + tarpath = os.path.join(self.tmpdir, "test.tar.bz2") + tar = tarfile.open(tarpath, "w") + for f in ('../mat.desktop', '../README.security', '../setup.py'): + tar.add(f, f[3:]) # trim '../' + tar.close() + proc = subprocess.Popen(['../mat', tarpath], stdout=subprocess.PIPE) + stdout, _ = proc.communicate() + self.assertTrue('It contains unsupported filetypes:'\ + '\n- mat.desktop\n- README.security\n- setup.py\n' + in str(stdout)) def get_tests(): ''' Return every clitests''' @@ -109,4 +124,5 @@ def get_tests(): suite.addTest(unittest.makeSuite(TestRemovecli)) suite.addTest(unittest.makeSuite(TestListcli)) suite.addTest(unittest.makeSuite(TestisCleancli)) + suite.addTest(unittest.makeSuite(TestUnsupported)) return suite -- cgit v1.3